improving pre-processing (noise removal) orange seven segment display for OCR reading About this project: Older images have the date they where taken placed on the image, in the bottom left hand corner. The goal is to extract this date and put it in the EXIF data of the scanned photo.

I am new to the challenge of working with images. I have a code playground and git repo I am working with and posting my results, and have made some progress. But I have hit a wall with dealing with the noise near the extracted text. I am reaching out for any assistance and direction to solve this noise problem.

What I have done thus far:
https://gitlab.com/51m0nt3r4aar/OCR_Img_Date_From_Scanned_Jpeg/blob/master/ImageManipPLayground.pdf

What I need help with: the Morph-Close did not remove the largest bits of noise, as seen in the last image, yet doing more morphs has not been successful. I am looking for any guidance to help solve this problem.

Thanks!
The shapes you are interested in are very regular while the noise you are trying to deal with will be less regular. Ideally, you will only have two shapes at the end of your processing: wide rectangles for the horizontal parts of the display and tall rectangles for the vertical parts. You can leverage this fact in how you shape your structuring element when you use opening to remove noise.

This code is for Matlab (or Octave, its free cousin), but should easy to implement in Python. Note that I screen grabbed the image from your GitLab file and resized it - so these dimensions likely won't match yours exactly. I also inverted the image so the foreground is white. Also, the images below were resized to 400% before posting.

pkg load image
img = imread("download.png");
img = img * 255;
imshow(img)




First, use a wide structuring element for opening so only wide rectangles are kept.

SE_h = strel('rectangle',[1,8]);
h_lines = imerode(img, SE_h);
h_lines_reconstructed = imdilate(h_lines, SE_h);
imshow(h_lines_reconstructed)




The repeat for tall rectangles:

SE_v = strel('rectangle',[8,1]);
v_lines = imerode(img, SE_v);
v_lines_reconstructed = imdilate(v_lines, SE_v);
imshow(v_lines_reconstructed)




Recombine and display:

combined = or(v_lines_reconstructed, h_lines_reconstructed);
imshow(combined);