導航:首頁 > 編程語言 > java簡單圖像處理

java簡單圖像處理

發布時間:2023-07-09 21:46:25

㈠ 用java編寫一個圖像處理,光線補償 、

寫了很多篇關於圖像處理的文章,沒有一篇介紹Java 2D的圖像處理API,文章討論和提及的

API都是基於JDK6的,首先來看Java中如何組織一個圖像對象BufferedImage的,如圖:

㈡ JAVA也可以用於圖像的設計嗎

是的,Java可以用於圖像的設計。Java提供了許多圖形庫和工具,可以用於創建和處理圖像。以下是一些常用的Java圖形庫和工具:搭衡
1. Java 2D API:Java 2D API提供了一組用於創建和處理2D圖形的類和介面,包括繪圖、圖像處理、顏色管理和字體等方面的功能。
2. JavaFX:JavaFX是一個用於創建富客戶端應用程序的凱困框架,包括圖形、媒體、界面和動畫等方面的功能。JavaFX提供了一組用於創建和處理圖像的類和介面,可以用於創建各種類型的圖像和動畫效果。
3. AWT:Abstract Window Toolkit(AWT)是Java的原始圖形庫,提供了一組用於創建和處理圖形用戶界面(GUI)的類和介面。AWT包括一些基本的繪圖和事件處理功能,但是相對於Java 2D API和JavaFX,其功能較為有限。
4. Java圖像處理庫(Java Image Processing Library,JIPL):JIPL是一個開源的Java圖像處理庫,提供了一組用於處理和編輯圖像的類和方法,包括圖像過濾器盯枝念、雜訊消除、邊緣檢測、圖像變換和顏色空間轉換等方面的功能。
總之,Java可以用於圖像的設計,開發人員可以根據具體需求選擇適合的圖形庫和工具。

㈢ 關於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是一個ImageProcer對象。
圖像縮放
對於一個已經存在的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:[email protected]*/
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:[email protected]*/
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)+(gray<<16)+(gray<<8)+gray;
}
}

如果你有自己的演算法或者想取得特殊的效果,你可以修改類GrayModel的方法getGrayLevel()。
色彩變換
根據上面的原理,我們也可以實現色彩變換,這樣的效果就很多了。下面是一個反轉變換的例子:

/* ReverseColorModel.java*/
/*@author:cherami */
/*email:[email protected]*/
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:[email protected]*/
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:[email protected]*/
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 圖像處理類的方法有哪些

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簡單圖像處理相關的資料

熱點內容
網路評選一般有哪些 瀏覽:476
2021三支一扶報名數據在哪裡看 瀏覽:914
網路未備案怎麼打得開 瀏覽:987
計算機程序用什麼編程語言 瀏覽:324
linux入門常用命令 瀏覽:497
江寧區哪裡有數控編程培訓 瀏覽:778
java寫一個shape形狀類 瀏覽:744
win7如何設置word背景顏色 瀏覽:484
如何創造電腦編程語言 瀏覽:56
昂達平板電腦圖形密碼忘記怎麼辦 瀏覽:92
組織文件內容是什麼 瀏覽:183
0基礎如何學習智能編程 瀏覽:366
java程序員全攻略下載 瀏覽:715
網路逆向教程 瀏覽:135
iso文件如何重裝系統 瀏覽:750
ghost鏡像文件路徑如何恢復 瀏覽:832
搭建網站需要多少錢啊 瀏覽:599
編程貓怎麼設置背景亮度 瀏覽:177
qq文件破損 瀏覽:414
javapoi配置 瀏覽:608

友情鏈接