Search code examples
matlabfilteringnoise

how to remove noise from a special area in Matlab


I have a an image of size 180x220 containing some noise in the region for example (145:180,1:65).

My question is how to remove the noise in this region without affecting the other parts of the image using Matlab.

Thank you very much.

Edit: I want to remove the noise in the regions (1:146,1:25) and (1:15,25,174) from the following image:

enter image description here


Solution

  • In general, this would go something like

    % filter image in-place
    img(145:180, 1:65) = medfilt2(img(145:180, 1:65));
    

    Note that most filters require some context of the region of interest to do a proper interpolation/averaging/etc., so you might want to take this approach:

    % Note: increase ROI by 10 on each side
    offset = 10;
    img_tmp = img(145-offset : 180+offset, 1 : 65+offset); 
    
    % apply filter
    img_tmp = medfilt2(img_tmp, [additional parameters]);
    
    % put filtered image back in its proper place
    img(145:180, 1:65) = img_tmp(offset:end-offset+1, 1:end-offset+1);