0

I need a Matlab function that prepares an image for digit and letter recognition.

What I need now is to convert the original RGB image to a binary image that every pixel in it is white except the pixels corresponding to letters and digits, as well as all digit and letter must appear chromatic/saturated, i.e. appear full of color. enter image description here

Here is the code I have been tested. As you can see some pixels of a letter or digit are white.

I = imread('img6.png');   % read the image into the matrix
Ig = rgb2gray(I);

Icon = imadjust(Ig);

subplot(2,2,1)
imshow(Ig)
subplot(2,2,2)
imshow(Icon)
subplot(2,2,3)
imhist(I)
subplot(2,2,4)
imhist(Icon)

1- How we can convert the original image to a high contrast image?

2- How the shadows around letters and digits can be removed?

sci9
  • 700
  • 1
  • 7
  • 21

1 Answers1

1

To sharpen the image, you can use the imfilter method. This takes in an image and a kernel (in this case, a sharpening kernel) and applies the kernel to the image. For example:

kernel = [0 -1 0;
-1 5 -1;
0 -1 0]
sharpened_image = imfilter(image, kernel)

enter image description here

sci9
  • 700
  • 1
  • 7
  • 21
  • Thank you for your answer, but imfilter does not produce better output than imadjust. Please see the edited post. – sci9 Aug 11 '20 at 17:59
  • 1
    The function `imfilter` lets you put in a custom kernel, which could be helpful but you should be fine with just `imadjust`. For your project, your processed image just needs a threshold filter (some gray color) to differentiate the shapes of the letters. You may want to consider some sort of blob fitting algorithm, but you don't need to sharpen it any further. – Andrew Mascillaro Aug 11 '20 at 18:07
  • Thank you for comment. I'll try to do your suggestions – sci9 Aug 11 '20 at 20:13