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!
a2is smooth after applying the averaging filter ona. I'm trying to understand what you are expecting to show in the result image. Actually yourG, obtained after sobel operator, is also auint8image ranging from 0 to 255. So I guess yourshould be
result=a.*uint8(G1) + a2.*uint8(1-G1);whereG1 =im2bw(G,thresh)with your presetthreshvalue.EDIT
Response to your suggestion: how about using