Search code examples
imagematlabimage-processingnoise-reduction

Remove noise from characters in an image


I processed my input image and the result is below. I just need the characters. I tried but can't remove the noise surrounding the characters.

mu.jpg


Solution

  • A simple erosion with a small structuring element, like a 3 x 3 square may work where you would eliminate the small white noise profile and thus make the characters darker. You can also take advantage of the fact that the areas that are black that are not characters are connected to the boundaries of the image. You can remove these from the image by removing areas connected to the boundaries.

    Therefore, perform an erosion first using imerode, then you will need to remove the boundaries using imclearborder but this requires that the pixels touching the border are white. Therefore, use the inverse of the output from imerode into the function, then inverse it again.

    Something like this will work and I'll read your image from Stack Overflow directly:

    % Read the image and threshold in case
    im = imread('https://i.sstatic.net/Hl6Y9.jpg');
    im = im > 200;
    
    % Erode
    out = imerode(im, strel('square', 3));
    
    % Remove the border and find inverse
    out = ~imclearborder(~out);
    

    We get this image now:

    enter image description here

    There are some isolated black holes near the B that you may not want. You can do some additional post-processing by using bwareaopen to remove islands that are below a certain area. I chose this to be 50 pixels from experimentation. You'll have to do this on the inverse of the output from imclearborder:

    % Read the image and threshold in case
    im = imread('https://i.sstatic.net/Hl6Y9.jpg');
    im = im > 200;
    
    % Erode
    out = imerode(im, strel('square', 3));
    
    % Remove the border
    bor = imclearborder(~out);
    
    % Remove small areas and inverse
    out = ~bwareaopen(bor, 50);
    

    We now get this:

    enter image description here