3

The other day I asked about something similiar and finally i solved that part, but i am stuck again.

I would like to create a noise filter, to remove noise from an image, avoiding edges and boundaries. My imput is an image file, and the filter is a smoothing linear FIR.

BUT i want the result to be written to the output mixed with the original content, following the next equation:

result(x,y) = original(x,y)*mask(x,y) + filter_output(x,y)*(1-mask(x,y))

Where: original(x,y) would be the imput, the image with noise (this for example, with gaussian noise). mask(x,y) is a matrix of coefficients based on the edges of the image (alredy done) and filter_ouput(x,y), should be the image after the linear FIR.

My problem is: I tried with so many filters and types of noise (gaussian, salt&pepper...), and i don't get a good result. The result(x,y) i get is the same than the image with noise! With any change. So strange.

Which filter would be the correct? I don't know if my error is in the filter, or in the code. But something is being implemented wrong. Here is the code.

filter = ones(5,5) / 25;
a2 = imfilter(a,filter); % a is the image with noise, a2 is the filtered image (output)

%The equation. G is the mask.

result=uint8(a).*uint8(G) + uint8(a2).*uint8(1-G);
imshow(result);

PS: Original image without noise

Any idea? Thank you so much!

lennon310
  • 12,503
  • 11
  • 43
  • 61
Dedrawde
  • 107
  • 1
  • 10
  • what is the range of values of your mask `G`? what is the output of `[min(G), max(G)]`? what is the data type of `G`? is it `double` or `uint8`? – Shai Dec 29 '13 at 15:30
  • The range of G is [0, 1], 512x512, double. – Dedrawde Dec 29 '13 at 18:19

1 Answers1

1

a2 is smooth after applying the averaging filter on a. I'm trying to understand what you are expecting to show in the result image. Actually your G , obtained after sobel operator, is also a uint8 image ranging from 0 to 255. So I guess your

result=uint8(a).*uint8(G) + uint8(a2).*uint8(1-G);

should be result=a.*uint8(G1) + a2.*uint8(1-G1); where G1 =im2bw(G,thresh) with your preset thresh value.

EDIT

Response to your suggestion: how about using

result=a2+(255-G);
lennon310
  • 12,503
  • 11
  • 43
  • 61
  • Hello. I would expect to get an image without noise on the flat areas only, avoiding edges and boundaries. I did what you said, and i have the same trouble. As a result, I obtain a noisy image in the flat areas. I'll keep trying. – Dedrawde Dec 29 '13 at 18:40
  • I don't know if i explain myself, sorry. Using only the filter (a->a2), i get a smooth image, without noise, but with the blurred edges. Using this equation, the goal is to get the image without noise, but keeping the original edges, i.e. without blurring. – Dedrawde Dec 29 '13 at 18:47
  • how about using result=a2+(255-G);? – lennon310 Dec 29 '13 at 19:26
  • No @lennon310, I understand what are you trying to do, but I get a black background. Thank you anyway! :) I'll keep searching the mistake. – Dedrawde Dec 29 '13 at 20:39