
正文
java图像处理插件代码 java图像处理opencv
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Image j里的plugins clahe在哪里
ImageJ软件File - Open打开HE染色图片;Plugins - CLAHE增强局部对比度。
CLAHE (Enhance Local Contrast)插件可增强图像的局部对比度从而增加图片清晰度,例如原始电镜图片经过CLAHE增强后更加清晰。
ImageJ软件功能
1.ImageJ支持用户自定义插件和宏。ImageJ自带编辑器, 并且导入了java的编译器,实现了简单的IDE功能, 用户可直接基于ImageJ进行图像处理。
2.ImageJ通过Java插件被设计为开放体系结构的,可以获取定制的分析、处理插件,这些插件都能够使用ImageJ内置的编辑器和编译器。用户自定义插件可以解决几乎所有图像处理和分析方面的问题。
3.ImageJ的源代码免费提供。
4.主面由菜单栏,工具栏和状态栏组成。
5.菜单栏包括:文件,编辑,图形,处理,分析,插件,窗口,帮助。
6.文件主要有:文件打开,关闭,保存等功能,比较特殊的一个功能是恢复功能。可以直接回到上次保存过的状态。
相关问答
Q1: 代码不长,java 图像处理 关天setRGB(x,y,rgb)
不会啊java图像处理插件代码,我试了一下图像是变化的java图像处理插件代码,不过下边这段代码没太懂,为什么i和j要递增2呢?递增1的话感觉效果更有趣一些:)
for(i=0;iwidth-1;i+=2)
for(j=0;jheight-1;j+=2)
{ pix=temp.getRGB(i,j);
if(pix!=im.getRGB(i,j))//每个相素进行比较如果不等
{im.setRGB(i,j,pix);//则更新为现在的像素值。
}
}
Q2: 用java编写一个图像处理,光线补偿 、
写了很多篇关于图像处理java图像处理插件代码的文章,没有一篇介绍Java 2Djava图像处理插件代码的图像处理API,文章讨论和提及的
API都是基于JDK6的,首先来看Java中如何组织一个图像对象BufferedImage的,如图java图像处理插件代码:
一个BufferedImage的像素数据储存在Raster中,ColorModel里面储存颜色空间,类型等
信息,当前Java只支持一下三种图像格式- JPG,PNG,GIF,如何向让Java支持其它格式,首
先要 完成Java中的图像读写接口,然后打成jar,加上启动参数- Xbootclasspath/p
newimageformatIO.jar即可。
Java中如何读写一个图像文件,使用ImageIO对象即可。读图像文件的代码如下:
File file = new File("D:\\test\\blue_flower.jpg");
BufferedImage image = ImageIO.read(file);
写图像文件的代码如下:
File outputfile = new File("saved.png");
ImageIO.write(bufferedImage, "png",outputfile);
从BufferedImage对象中读取像素数据的代码如下:
1 int type= image.getType();2 if ( type ==BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )3 return (int [])image.getRaster().getDataElements(x, y, width, height, pixels );4 else5 return image.getRGB( x, y, width, height, pixels, 0, width );
首先获取图像类型,如果不是32位的INT型数据,直接读写RGB值即可,否则需要从Raster
对象中读取。
往BufferedImage对象中写入像素数据同样遵守上面的规则。代码如下:
1 int type= image.getType();2 if ( type ==BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )3 image.getRaster().setDataElements(x, y, width, height, pixels );4 else5 image.setRGB(x, y, width, height, pixels, 0, width );
读取图像可能因为图像文件比较大,需要一定时间的等待才可以,Java Advance Image
Processor API提供了MediaTracker对象来跟踪图像的加载,同步其它操作,使用方法如下:
MediaTracker tracker = new MediaTracker(this); //初始化对象 om/roucheng/tracker.addImage(image_01, 1); // 加入要跟踪的BufferedImage对象image_001tracker.waitForID(1, 10000) // 等待10秒,让iamge_01图像加载
从一个32位int型数据cARGB中读取图像RGB颜色值的代码如下:
1 int alpha = (cARGB 24) 0xff; //透明度通道 g/2 int red = (cARGB 16) 0xff;3 int green = (cARGB 8) 0xff;4 int blue = cARGB 0xff;
将RGB颜色值写入成一个INT型数据cRGB的代码如下:
cRGB = (alpha 24) | (red 16) | (green 8) | blue;
创建一个BufferedImage对象的代码如下:
BufferedImage image = newBufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
一个完整的源代码Demo如下:
1 package com.gloomyfish.swing; 2 3 import java.awt.BorderLayout; 4 import java.awt.Dimension; 5 import java.awt.Graphics; 6 import java.awt.Graphics2D; 7 import java.awt.RenderingHints; 8 import java.awt.image.BufferedImage; 9 import java.io.File; 10 import java.io.IOException; 11 12 import javax.imageio.ImageIO; 13 import javax.swing.JComponent; 14 import javax.swing.JFrame; 15 16 public class PlasmaDemo extends JComponent {
17 18 /** 19 *
20 */ 21 private static final long serialVersionUID = -2236160343614397287L;
22 private BufferedImage image = null;
23 private int size = 256; 24 25 public PlasmaDemo() {
26 super();
27 this.setOpaque(false);
28 }
29 30 protected void paintComponent(Graphics g) {
31 Graphics2D g2 = (Graphics2D)g;
32 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
33 g2.drawImage(getImage(), 5, 5, image.getWidth(), image.getHeight(), null);
34 }
35 36 private BufferedImage getImage() {
37 if(image == null) {
38 image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
39 int[] rgbData = new int[size*size];
40 generateNoiseImage(rgbData);
41 setRGB(image, 0, 0, size, size, rgbData); 42 File outFile = new File("plasma.jpg"); 43 try { 44 ImageIO.write(image, "jpg", outFile); 45 } catch (IOException e) { 46 e.printStackTrace(); 47 } 48 }
49 return image;
50 }
51 52 public void generateNoiseImage(int[] rgbData) {
53 int index = 0;
54 int a = 255;
55 int r = 0;
56 int g = 0;
57 int b = 0;
58 59 for(int row=0; rowsize; row++) {
60 for(int col=0; colsize; col++) {
61 // set random color value for each pixel 62 r = (int)(128.0 + (128.0 * Math.sin((row + col) / 8.0)));
63 g = (int)(128.0 + (128.0 * Math.sin((row + col) / 8.0)));
64 b = (int)(128.0 + (128.0 * Math.sin((row + col) / 8.0)));
65 66 rgbData[index] = ((clamp(a) 0xff) 24) |
67 ((clamp(r) 0xff) 16) |
68 ((clamp(g) 0xff) 8) |
69 ((clamp(b) 0xff));
70 index++;
71 }
72 }
73 74 }
75 76 private int clamp(int rgb) {
77 if(rgb 255)
78 return 255;
79 if(rgb 0)
80 return 0;
81 return rgb;
82 }
83 84 public void setRGB( BufferedImage image, int x, int y, int width, int height, int[] pixels ) {
85 int type = image.getType();
86 if ( type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )
87 image.getRaster().setDataElements( x, y, width, height, pixels );
88 else 89 image.setRGB( x, y, width, height, pixels, 0, width );
90 }
91 92 public static void main(String[] args) {
93 JFrame frame = new JFrame("Noise Art Panel");
94 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
95 frame.getContentPane().setLayout(new BorderLayout()); m/roucheng/ 98 frame.getContentPane().add(new PlasmaDemo(), BorderLayout.CENTER);
99 frame.setPreferredSize(new Dimension(400 + 25,450));
100 frame.pack();
101 frame.setVisible(true);
102 }
103 }
Q3: 求Java图像放大后不失真的代码!!!!网上没找到~!
其实,这个算法老复杂了。
最近像素插值算法是最简单的一种插值算法,当图片放大时,缺少的像素通过直接使用与之最接近的原有的像素的颜色生成,也就是说照搬旁边的像素。它是三种内插值方式中质量最差的一种,用该方法修改后的图像边缘有锯齿,但速度较快。
双线性插值算法是沿水平和垂直方向对周围像素取样,然后建立像素颜色总数的平均颜色值。这种算法极大地消除了锯齿现象,在计算速度与质量两个方面都居于三种方法中间地位。
双立方插值算法是在水平、垂直和对角线方向对像素取样,然后使用总颜色的加权平均值建立新像素,它是三者中运算速度最慢,但效果最佳的一种。
Q4: java实现图片上传至服务器并显示,如何做?希望要具体的代码实现
很简单。
可以手写IO读写(有点麻烦)。
怕麻烦的话使用FileUpload组件 在servlet里doPost嵌入一下代码
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
//设置保存上传文件的目录
String uploadDir =getServletContext().getRealPath("/up");
System.out.println(uploadDir);
if (uploadDir == null)
{
out.println("无法访问存储目录!");
return;
}
//根据路径创建一个文件
File fUploadDir = new File(uploadDir);
if(!fUploadDir.exists()){
if(!fUploadDir.mkdir())//如果UP目录不存在 创建一个 不能创建输出...
{
out.println("无法创建存储目录!");
return;
}
}
if (!DiskFileUpload.isMultipartContent(request))
{
out.println("只能处理multipart/form-data类型的数据!");
return ;
}
DiskFileUpload fu = new DiskFileUpload();
//最多上传200M数据
fu.setSizeMax(1024 * 1024 * 200);
//超过1M的字段数据采用临时文件缓存
fu.setSizeThreshold(1024 * 1024);
//采用默认的临时文件存储位置
//fu.setRepositoryPath(...);
//设置上传的普通字段的名称和文件字段的文件名所采用的字符集编码
fu.setHeaderEncoding("gb2312");
//得到所有表单字段对象的集合
List fileItems = null;
try
{
fileItems = fu.parseRequest(request);//解析request对象中上传的文件
}
catch (FileUploadException e)
{
out.println("解析数据时出现如下问题:");
e.printStackTrace(out);
return;
}
//处理每个表单字段
Iterator i = fileItems.iterator();
while (i.hasNext())
{
FileItem fi = (FileItem) i.next();
if (fi.isFormField()){
String content = fi.getString("GB2312");
String fieldName = fi.getFieldName();
request.setAttribute(fieldName,content);
}else{
try
{
String pathSrc = fi.getName();
if(pathSrc.trim().equals("")){
continue;
}
int start = pathSrc.lastIndexOf('\\');
String fileName = pathSrc.substring(start + 1);
File pathDest = new File(uploadDir, fileName);
fi.write(pathDest);
String fieldName = fi.getFieldName();
request.setAttribute(fieldName, fileName);
}catch (Exception e){
out.println("存储文件时出现如下问题:");
e.printStackTrace(out);
return;
}
finally //总是立即删除保存表单字段内容的临时文件
{
fi.delete();
}
}
}
注意 JSP页面的form要加enctype="multipart/form-data" 属性, 提交的时候要向服务器说明一下 此页面包含文件。
如果 还是麻烦,干脆使用Struts 的上传组件 他对FileUpload又做了封装,使用起来更傻瓜化,很容易掌握。
-----------------------------
以上回答,如有不明白可以联系我。
Q5: java图像处理问题
Java图像处理技巧四则
下面代码中用到的sourceImage是一个已经存在的Image对象
图像剪切
对于一个已经存在的Image对象,要得到它的一个局部图像,可以使用下面的步骤:
//import java.awt.*;
//import java.awt.image.*;
Image croppedImage;
ImageFilter cropFilter;
CropFilter =new CropImageFilter(25,30,75,75); //四个参数分别为图像起点坐标和宽高,即CropImageFilter(int x,int y,int width,int height),详细情况请参考API
CroppedImage= Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(sourceImage.getSource(),cropFilter));
如果是在Component的子类中使用,可以将上面的Toolkit.getDefaultToolkit().去掉。FilteredImageSource是一个ImageProducer对象。
图像缩放
对于一个已经存在的Image对象,得到它的一个缩放的Image对象可以使用Image的getScaledInstance方法:
Image scaledImage=sourceImage. getScaledInstance(100,100, Image.SCALE_DEFAULT); //得到一个100X100的图像
Image doubledImage=sourceImage. getScaledInstance(sourceImage.getWidth(this)*2,sourceImage.getHeight(this)*2, Image.SCALE_DEFAULT); //得到一个放大两倍的图像,这个程序一般在一个swing的组件中使用,而类Jcomponent实现了图像观察者接口ImageObserver,所有可以使用this。
//其它情况请参考API
灰度变换
下面的程序使用三种方法对一个彩色图像进行灰度变换,变换的效果都不一样。一般而言,灰度变换的算法是将象素的三个颜色分量使用R*0.3+G*0.59+ B*0.11得到灰度值,然后将之赋值给红绿蓝,这样颜色取得的效果就是灰度的。另一种就是取红绿蓝三色中的最大值作为灰度值。java核心包也有一种算法,但是没有看源代码,不知道具体算法是什么样的,效果和上述不同。
/* GrayFilter.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class GrayFilter extends RGBImageFilter {
int modelStyle;
public GrayFilter() {
modelStyle=GrayModel.CS_MAX;
canFilterIndexColorModel=true;
}
public GrayFilter(int style) {
modelStyle=style;
canFilterIndexColorModel=true;
}
public void setColorModel(ColorModel cm) {
if (modelStyle==GrayModel
else if (modelStyle==GrayModel
}
public int filterRGB(int x,int y,int pixel) {
return pixel;
}
}
/* GrayModel.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class GrayModel extends ColorModel {
public static final int CS_MAX=0;
public static final int CS_FLOAT=1;
ColorModel sourceModel;
int modelStyle;
public GrayModel(ColorModel sourceModel) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
modelStyle=0;
}
public GrayModel(ColorModel sourceModel,int style) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
modelStyle=style;
}
public void setGrayStyle(int style) {
modelStyle=style;
}
protected int getGrayLevel(int pixel) {
if (modelStyle==CS_MAX) {
return Math.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));
}
else if (modelStyle==CS_FLOAT){
return (int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);
}
else {
return 0;
}
}
public int getAlpha(int pixel) {
return sourceModel.getAlpha(pixel);
}
public int getRed(int pixel) {
return getGrayLevel(pixel);
}
public int getGreen(int pixel) {
return getGrayLevel(pixel);
}
public int getBlue(int pixel) {
return getGrayLevel(pixel);
}
public int getRGB(int pixel) {
int gray=getGrayLevel(pixel);
return (getAlpha(pixel)24)+(gray16)+(gray8)+gray;
}
}
如果你有自己的算法或者想取得特殊的效果,你可以修改类GrayModel的方法getGrayLevel()。
色彩变换
根据上面的原理,我们也可以实现色彩变换,这样的效果就很多了。下面是一个反转变换的例子:
/* ReverseColorModel.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class ReverseColorModel extends ColorModel {
ColorModel sourceModel;
public ReverseColorModel(ColorModel sourceModel) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
}
public int getAlpha(int pixel) {
return sourceModel.getAlpha(pixel);
}
public int getRed(int pixel) {
return ~sourceModel.getRed(pixel);
}
public int getGreen(int pixel) {
return ~sourceModel.getGreen(pixel);
}
public int getBlue(int pixel) {
return ~sourceModel.getBlue(pixel);
}
public int getRGB(int pixel) {
return (getAlpha(pixel)24)+(getRed(pixel)16)+(getGreen(pixel)8)+getBlue(pixel);
}
}
/* ReverseColorModel.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class ReverseFilter extends RGBImageFilter {
public ReverseFilter() {
canFilterIndexColorModel=true;
}
public void setColorModel(ColorModel cm) {
substituteColorModel(cm,new ReverseColorModel(cm));
}
public int filterRGB(int x,int y,int pixel) {
return pixel;
}
}
要想取得自己的效果,需要修改ReverseColorModel.java中的三个方法,getRed、getGreen、getBlue。
下面是上面的效果的一个总的演示程序。
/*GrayImage.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.color.*;
public class GrayImage extends JFrame{
Image source,gray,gray3,clip,bigimg;
BufferedImage bimg,gray2;
GrayFilter filter,filter2;
ImageIcon ii;
ImageFilter cropFilter;
int iw,ih;
public GrayImage() {
ii=new ImageIcon(\"images/11.gif\");
source=ii.getImage();
iw=source.getWidth(this);
ih=source.getHeight(this);
filter=new GrayFilter();
filter2=new GrayFilter(GrayModel.CS_FLOAT);
gray=createImage(new FilteredImageSource(source.getSource(),filter));
gray3=createImage(new FilteredImageSource(source.getSource(),filter2));
cropFilter=new CropImageFilter(5,5,iw-5,ih-5);
clip=createImage(new FilteredImageSource(source.getSource(),cropFilter));
bigimg=source.getScaledInstance(iw*2,ih*2,Image.SCALE_DEFAULT);
MediaTracker mt=new MediaTracker(this);
mt.addImage(gray,0);
try {
mt.waitForAll();
} catch (Exception e) {
}
关于java图像处理插件代码和java图像处理opencv的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







