J = imnoise(I,'salt &pepper',0.8) //insert the slat and pepper noise into the image I, parameter=0.8
prototype of imnoise is
g=imnoise(f,type,parameters)
K(:,:,1)= medfilt2(J(:,:,1))
//because the jpg image is a colored one, so it had three channels: R G and B, these channels will be saved into a length*height*3 martix
for example J(:,:,1) saved the red pixels, J(:,:,2) is for the green and J(:,:,3) is for the blue
now we use medfilt2(x) as a median filter to deal with the noise-inserted image J with its R channel, and the resault will be send into K(:,:,1) (image K's R channel)
K(:,:,2)= medfilt2(J(:,:,2)) //dealing with the G channel
K(:,:,3)= medfilt2(J(:,:,3)) //dealing with the B channel
imshow(J),//show the noise-inserted image J
figure,//to new a drawing board
imshow(K)//show the filtered image K
流程不外乎是
读取图像文件;
扫描噪点;
去除噪点;
保存图像文件。
Java2D *** 作好像使用BufferedImage读取图像文件最方便,有一阵没弄这了,忘了。应该可以读取JPG,PNG,GIF图像。
识别噪点应该有专门的算法,我没研究过,百度一下应该能找到专门算法,然后写段代码就可以。我个人以为是独立一个像素与周围一定范围内的像素差异过大,就认为是噪点。可以有亮度,色相上的差别。BufferedImage可以读取每个像素的RGB,从而能识别色相的差别;还有个矩阵,用来由RGB计算亮度的,也就可以计算亮度差别了,这个网上都能找到。
输出也使用BufferedImage就可以。
关键是每个像素都要和周围像素比较,还要计算亮度,最少是三重循环了,如何提高效率是个大问题了。这个代码写好了也算一个高手了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)