「java图像处理api」java画图像
本篇文章给大家谈谈java图像处理api,以及java画图像对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、《Java数字图像处理编程技巧与应用实践》epub下载在线阅读全文,求百度网盘云资源
- 2、java 图像处理,基本概念的理解
- 3、用java编写一个图像处理,光线补偿 、
- 4、关于java图像处理
- 5、java的API中有哪些常用的包?
- 6、《JAVA数字图像处理》pdf下载在线阅读全文,求百度网盘云资源
《Java数字图像处理编程技巧与应用实践》epub下载在线阅读全文,求百度网盘云资源
《Java数字图像处理编程技巧与应用实践》(贾志刚)电子书网盘下载免费在线阅读
链接:
提取码: cy78
书名:Java数字图像处理编程技巧与应用实践
作者: 贾志刚
出版社: 机械工业出版社
副标题: 编程技巧与应用实践
出版年: 2016-1
内容简介
本书首先通过一个简单JAVA图像处理程序勾勒出用JAVA来实现图像处理的基本步骤,介绍JAVA在操作图像方面的几个重要的API类如ImageIO,BufferedImageOP等,并对图像文件的保存与读写做较为深入细致的讲解。从第二章开始介绍图像的像素操作同时还会用实例讲解如何通过这些简单的像素操作实现图像的色彩特效。接下来会学习图像的直方图,演示如何直方图均衡化的实际应用,会基于直方图实现一种图像搜索算法,接下来学习图像处理中最重要与常见的如何调整图像的亮度,对比度与饱和度实现图像的基本调整。然后逐步深入介绍图像的模糊与锐化,首先学习图像卷积模糊算法,然后介绍快速模糊算法盒子模糊,细节保留的高斯模糊与双边模糊,以及各种不同方向的对图像实现模糊的技术,从而实现不同的处理效果。
作者简介
费志刚,CSDN博客专家,51CTO视频学院认证讲师,拥有10年以上的Java语言编程经验,在图像特征提取匹配、识别等方面有较深入的研究,多年从事Java Swing图形与图像方面的应用开发,拥有丰富的图像处理项目实践经验。
java 图像处理,基本概念的理解
SampleModel 取样模型
Databuffer 数据缓冲区
Raster 光栅
Sample 样本
band 带
SampleModel是java awt中的一个抽象类,它定义了一个接口,用于提取一幅图像中的像素(pixel)的样本(Sample)。
一幅图像包含了许多数据,而所有的数据是以像素为基本单位来表达的(像素的集合),其中每个像素又由若干样本来构成。
样本(Sample),是指对一幅图像取样得到的属于某个带的单体数据,
而带(band),是一副图像中的特定类型的样本的全体。
例如,1个像素可包含3个样本、分别代表红、绿、蓝这三个基色。于是就说以三基色来定义的一幅图像包含了3个带:第一个带含来自图像中的所有像素的红色样本,第二个带含所有的绿色样本,第三个带含所有的蓝色样本。
内存存放方式:像素可用不同方式来进行存储。如,把一个带的所有像素按顺序进行存放的方式、和把单个像素所含的样本组(例如三基色的三个样本)的各个样本逐组顺序存放的方式,等等。
SampleModel的子类用来指定样本的表达类型(如,是非负的8比特类型byte还是整数类型的16比特short,等),以及样本在内存的存放格式。Java 2D(tm)提供的图像处理内置API不可能支持所有的样品类型,但通常都会支持16比特无符号整数类型(0 -65535)或更低的类型,其中,有些API支持的数据类型会有很多。
1组像素可表示为1个光栅(Raster。例如一个扫描行)。光栅含1个DataBuffer和1个SampleModel。使用SampleModel可以对DataBuffer中的样本进行存取,有些还可能提供机器级别的信息,帮助编程者直接操作DataBuffer中的样品和像素。
SampleModel处理图像通常是后退法。高效的编程是,把SampleModel 转换(cast)到适当的子类,从中提取出直接操作DataBuffer中的像素所需的信息。 请参考
用java编写一个图像处理,光线补偿 、
写了很多篇关于图像处理的文章,没有一篇介绍Java 2D的图像处理API,文章讨论和提及的
API都是基于JDK6的,首先来看Java中如何组织一个图像对象BufferedImage的,如图:
一个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 }
关于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的API中有哪些常用的包?
Application Programming Interface 应用程序编程接口,Java的api就多的数不清了,平时编程用的都是API。
《JAVA数字图像处理》pdf下载在线阅读全文,求百度网盘云资源
《JAVA数字图像处理》百度网盘pdf最新全集下载:
链接:
?pwd=f8sq 提取码: f8sq
简介:在开始本书内容之前,笔者假设你已经有了面向对象语言编程的基本概念,了解Java语言的基本语法与特征,原因在于本书的所有源代码都是基于Java语言实现的,而且是基于Java开发环境运行与演示所有图像处理算法的。本书第1章到第3章是为了帮助读者了解与掌握Java图形与GUI编程的基本知识与概念而写的。本章主要介绍Java GUI编程中基本的图形知识,针对GU1编程,Java语言提供了两套几乎并行的API,分别是Swing与AWT。早期的Java GUJ编程中主要使用AWT的相关组件,但是AWT的功能并不是十分强大,而且严重依赖本地接口。于是在Java 1.3及后续版本中引入了Swing工具实现GUl编程,Swing中的组件大多数都是基于纯Java语言实现的,而不是通过本地组件实现的,所以它们是轻量级的GUI组件,同时Swing对图形与图像的支持操作也有很大的提高与增强。如何区分AWT组件与Swing组件?一个简单而且相当直观的方法是看Class的名称,Swing的组件大多数带有大写的前缀字母J。
关于java图像处理api和java画图像的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。