日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

图像处理之基础---卷积去噪

發布時間:2023/12/19 综合教程 18 生活家
生活随笔 收集整理的這篇文章主要介紹了 图像处理之基础---卷积去噪 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

討論如何使用卷積作為數學工具來處理圖像,實現圖像的濾波,其方法包含以下幾種,均值

濾波,中值濾波,最大最小值濾波,關于什么是卷積以及理解卷積在圖像處理中作用參見這

里–http://blog.csdn.net/jia20003/article/details/7038938

均值濾波:

均值濾波,是圖像處理中最常用的手段,從頻率域觀點來看均值濾波是一種低通濾波器,高

頻信號將會去掉,因此可以幫助消除圖像尖銳噪聲,實現圖像平滑,模糊等功能。理想的均

值濾波是用每個像素和它周圍像素計算出來的平均值替換圖像中每個像素。采樣Kernel數

據通常是3X3的矩陣,如下表示:

從左到右從上到下計算圖像中的每個像素,最終得到處理后的圖像。均值濾波可以加上兩個

參數,即迭代次數,Kernel數據大小。一個相同的Kernel,但是多次迭代就會效果越來越好。

同樣,迭代次數相同,Kernel矩陣越大,均值濾波的效果就越明顯。

中值濾波

中值濾波也是消除圖像噪聲最常見的手段之一,特別是消除椒鹽噪聲,中值濾波的效果要比

均值濾波更好。中值濾波是跟均值濾波唯一不同是,不是用均值來替換中心每個像素,而是

將周圍像素和中心像素排序以后,取中值,一個3X3大小的中值濾波如下:

最大最小值濾波

最大最小值濾波是一種比較保守的圖像處理手段,與中值濾波類似,首先要排序周圍像素和

中心像素值,然后將中心像素值與最小和最大像素值比較,如果比最小值小,則替換中心像

素為最小值,如果中心像素比最大值大,則替換中心像素為最大值。一個Kernel矩陣為3X3的最大最小值濾波如下:

原圖如下:

分別實現中值和均值濾波以后效果如下:

代碼就不解釋了,原理已經解釋得很清楚了,全部算法源代碼都是基于Java

特別說明一點的是,均值濾波對于高斯噪聲的效果比較好,中值濾波對于椒鹽噪聲的效果比較好

想必大家從上面效果比較中也可以看到一點端倪。因為我選擇的噪聲圖片是椒鹽噪聲的,哈哈

自己讀吧,不解釋了,有問題的可以問,源代碼如下:

[java]view plaincopy

packagecom.process.blur.study;

importjava.awt.image.BufferedImage;
importjava.util.ArrayList;
importjava.util.Arrays;


publicclassSmoothFilterextendsAbstractBufferedImageOp{
publicfinalstaticintMEAN_FILTER_TYPE=1;
publicfinalstaticintMEADIAN_FILTER_TYPE=2;
publicfinalstaticintMIN_MAX_FILTER_TYPE=4;

privateintrepeats=3;//default1
privateintkernel_size=3;//default3
privateinttype=1;//defaultmeantype

publicintgetRepeat(){
returnrepeats;
}

publicvoidsetRepeat(intrepeat){
this.repeats=repeat;
}

publicintgetKernelSize(){
returnkernel_size;
}

publicvoidsetKernelSize(intkernelSize){
this.kernel_size=kernelSize;
}

publicintgetType(){
returntype;
}

publicvoidsetType(inttype){
this.type=type;
}

@Override
publicBufferedImagefilter(BufferedImagesrc,BufferedImagedest){
intwidth=src.getWidth();
intheight=src.getHeight();

if(dest==null)
dest=createCompatibleDestImage(src,null);

int[]inPixels=newint[width*height];
int[]outPixels=newint[width*height];
getRGB(src,0,0,width,height,inPixels);

//pickuponefilterfromhere!!!
if(this.type==MEAN_FILTER_TYPE)
{
for(inti=0;i<repeats;i++){
performMeanFilter(width,height,inPixels,outPixels);
System.arraycopy(outPixels,0,inPixels,0,inPixels.length);
}
}
elseif(this.type==MEADIAN_FILTER_TYPE)
{
performMedianFilter(width,height,inPixels,outPixels);
}
elseif(this.type==MIN_MAX_FILTER_TYPE)
{
performMinMaxFilter(width,height,inPixels,outPixels);
}

//returnresult
setRGB(dest,0,0,width,height,outPixels);
returndest;
}

/**
*<p>performconvolutionfilter</p>
*
*@paramwidth
*@paramheight
*@paraminPixels
*@paramoutPixels
*/
publicvoidperformMeanFilter(intwidth,intheight,int[]inPixels,int[]outPixels){

introws2=kernel_size/2;
intcols2=kernel_size/2;
intindex=0;
intindex2=0;
floattotal=kernel_size*kernel_size;
for(inty=0;y<height;y++){
for(intx=0;x<width;x++){
floatr=0,g=0,b=0,a=0;
for(introw=-rows2;row<=rows2;row++){
introwoffset=y+row;
if(rowoffset<0||rowoffset>=height){
rowoffset=y;
}
//System.out.println("rowoffset=="+rowoffset);
for(intcol=-cols2;col<=cols2;col++){
intcoloffset=col+x;
if(coloffset<0||coloffset>=width){
coloffset=x;
}
index2=rowoffset*width+coloffset;
intrgb=inPixels[index2];
a+=((rgb>>24)&0xff);
r+=((rgb>>16)&0xff);
g+=((rgb>>8)&0xff);
b+=(rgb&0xff);
}
}
intia=0xff;
intir=clamp((int)(r/total));
intig=clamp((int)(g/total));
intib=clamp((int)(b/total));
outPixels[index++]=(ia<<24)|(ir<<16)|(ig<<8)|ib;
}
}
}
/**
*<p>performmedianfilter</p>
*
*@paramwidth
*@paramheight
*@paramsrc
*@paraminPixels
*@paramoutPixels
*/
publicvoidperformMedianFilter(intwidth,intheight,int[]inPixels,int[]outPixels){

introws2=kernel_size/2;
intcols2=kernel_size/2;
intindex=0;
intindex2=0;
floattotal=kernel_size*kernel_size;
int[]matrix=newint[(int)total];
for(inty=0;y<height;y++){
for(intx=0;x<width;x++){
intcount=0;
for(introw=-rows2;row<=rows2;row++){
introwoffset=y+row;
if(rowoffset<0||rowoffset>=height){
rowoffset=y;
}

for(intcol=-cols2;col<=cols2;col++){
intcoloffset=col+x;
if(coloffset<0||coloffset>=width){
coloffset=x;
}
index2=rowoffset*width+coloffset;
intrgb=inPixels[index2];
matrix[count]=rgb;
count++;
}
}
Arrays.sort(matrix);

intia=0xff;
intir=((matrix[count/2]>>16)&0xff);
intig=((matrix[count/2]>>8)&0xff);
intib=(matrix[count/2]&0xff);
outPixels[index++]=(ia<<24)|(ir<<16)|(ig<<8)|ib;
}
}
}

/**
*<p>performmin/maxpixelfilter</p>
*
*@paramwidth
*@paramheight
*@paramsrc
*@paraminPixels
*@paramoutPixels
*/
publicvoidperformMinMaxFilter(intwidth,intheight,int[]inPixels,int[]outPixels){
introws2=kernel_size/2;
intcols2=kernel_size/2;
intindex=0;
intindex2=0;
floattotal=kernel_size*kernel_size;
int[]matrix=newint[(int)total];
for(inty=0;y<height;y++){
for(intx=0;x<width;x++){
intcount=0;
for(introw=-rows2;row<=rows2;row++){
introwoffset=y+row;
if(rowoffset<0||rowoffset>=height){
rowoffset=y;
}

for(intcol=-cols2;col<=cols2;col++){
intcoloffset=col+x;
if(coloffset<0||coloffset>=width){
coloffset=x;
}
index2=rowoffset*width+coloffset;
intrgb=inPixels[index2];
matrix[count]=rgb;
count++;
}
}
intia=0xff;
intoldPixel=matrix[count/2];
inttargetRGB=findNewPixel(matrix,oldPixel);
intir=((targetRGB>>16)&0xff);
intig=((targetRGB>>8)&0xff);
intib=(targetRGB&0xff);
outPixels[index++]=(ia<<24)|(ir<<16)|(ig<<8)|ib;
}
}
}

privateintfindNewPixel(int[]matrix,intoldPixel){
ArrayList<Integer>list=newArrayList<Integer>();
for(inti=0;i<matrix.length;i++){
if(matrix[i]==oldPixel)
continue;
list.add(matrix[i]);
}
int[]filterData=newint[list.size()];
intindex=0;
for(Integerrgb:list){
filterData[index++]=rgb;
}
Arrays.sort(filterData);

if(filterData.length==0)
returnoldPixel;
return(oldPixel>filterData[0])?filterData[0]:(oldPixel<filterData[filterData.length-1])?filterData[filterData.length-1]:oldPixel;
}

publicstaticintclamp(intc){
if(c<0)
return0;
if(c>255)
return255;
returnc;
}

}

轉載是請注明出自本博客,如果需要完全代碼的留下Email

http://blog.csdn.net/jia20003/article/details/7294460

總結

以上是生活随笔為你收集整理的图像处理之基础---卷积去噪的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。