noise removing for image processing
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi. I still in learning process. I want to remove noise in the image. I found this code where the noise successfully removed but the problem is I don't understand the code. I want to know how it work from row to row. Here the code that I had found.
I=imread('boy_noisy.gif'); %read the image
I=double(mat2gray(I)); %convert to double and change it to gray
I=imresize(I,[256 256]); %why should we re-size it?
[rows,cols]=size(I);
I=I-mean(I(:)); % I don't know the purpose for this code
f=fftshift(fft2(I));%use fourier transform
fabs=abs(f); % I don't know the purpose for this code
roi=3;thresh=400; I don't know the purpose for this function and why use roi?
le=ordfilt2(fabs,roi^2,ones(roi)); % use ordinal filter but I still don't understand this part
figure,imshow(le) %display
%I don't know all this part
r=(fabs==le)&(fabs>thresh);
[r,c]=find(r);
for i=1:length(result)
if (result (i)-128)^2+(c(i)-128)^2>400
f(result (i)-2:result(i)+2,c(i)-2:c(i)+2)=0;
Inew=ifft2(fftshift(f)); %inverse fourier transform
imagesc(real(Inew)),colormap(gray); % turn back the colour
댓글 수: 1
William
2015년 1월 3일
highlight code sections using the "{} code" button - makes it much easier to read and more likely to get answered
채택된 답변
Image Analyst
2015년 1월 3일
I don't know why they're resizing. Perhaps for some reason they think the image must be a power of 2 before taking the FFT, like in the old days.
le=ordfilt2(fabs,roi^2,ones(roi));
is the same as dilation, imdilate(). Essentially it makes le the local max of fabs. Then they check it to see if a pixel is the local max, and if it's frequency is greater than 400 then they erase that frequency. In other words, if it's a local spike, erase it.
Overall, it looks like this will removed high frequency noise that is periodic. Periodic noise shows up as spikes in the Fourier domain and this code looks for spikes in higher frequencies and removes them if they're there and then transforms back to the spatial domain where the high frequency ripples in the image should be reduced.
댓글 수: 3
Image Analyst
2015년 1월 4일
The subtracted the mean because if you don't, there will be a huge spike at DC (zero frequency) because the energy at 0 frequency is related to the mean gray level of the entire image. If you subtract that then the values bounce around zero and there will be no huge DC spike. This might make their algorithm ignore that spike automatically but because they manually force it to look only at frequencies greater than 400 it should not make any difference. Try getting rid of that line and see how it changes the final image.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!