2

This is the original image.

enter image description here

I changed it into 1) grayscale and apply 2) threshold.

As seen in the original image, there are some shadow that still exist after apply two method above.

But most of the image are perfect after 2 method.

enter image description here

I need to extract the text, so I need to get rid of the noise. I almost finish the work but the problem is some cases have a black border and I wanted to replace that into white color.

And I insist that I want just only border to turn into white

I think of create some white rectangle and fill the border with those rectangle but I don't know how to do it.

How can I achieve that using Matlab? Any other method would be appreciate too!

Krit
  • 610
  • 1
  • 7
  • 18
  • I have tried to understand morphological operation, but it seems to be complex for me. For instead, I just want to create white rectangle box and fill the black border. – Krit Jan 25 '13 at 08:34

1 Answers1

1

If you can be sure only the borders will be black, why not simply crop the image until all isolated shapes are recognizable characters? Something along the lines of

done = false;
ii = 1;
while (~done)

    % fill the outer border
    img(:,ii)       = 255;    img(ii,:)       = 255;
    img(:,end-ii+1) = 255;    img(end-ii+1,:) = 255;

    % (run your algorithms here. It positive match, done = true)

end

That could be computationally intensive, since you have to do pattern recognition on each iteration, but you indicated it only occurs in "some cases".

Otherwise, I suspect some morphological operation can also be used, probably erosion or thinning or similar. But that has the drawback of altering the characters you want to match. But, if all images you have to process look like the one you show, I hardly suspect that'll give you any problems.

Some ways to detecting straight lines are mentioned in this question. I'd say you could detect all lines, and remove those (with a small tolerance around it) that are perfectly horizontal/vertical and on one of the edges.

Community
  • 1
  • 1
Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • Do you have any suggest on how to create white rectangle and fill the black border instead? I think it is more simple method but I don't know if it gonna work or not. – Krit Jan 25 '13 at 08:30
  • I don't understand the code at all, but it seems to worked. But how to increase the line size? – Krit Jan 25 '13 at 10:30
  • @KritHoonsuwan: you mean the thickness of each line you remove? – Rody Oldenhuis Jan 25 '13 at 10:40
  • @KritHoonsuwan: the colon operator (`:`) means addressing all entries in a column or row. If you set the first row in the image equal to 255, you're setting it equal to white. There I am assuming the image is a `uint8` grayscale bitmap, meaning, each pixel is gray, with 0 being black and 255 being white. So, what I did in words: set all rows in column 1 equal to white, set all columns in row 1 equal to white, set all rows in the last column equal to white, and set all columns in the last row equal to white. – Rody Oldenhuis Jan 25 '13 at 10:43
  • I got it worked(increase the thickness of the line), it is something like this. ii = 6; greyImage(:,1:ii) = 255; greyImage(1:ii,:) = 255; greyImage(:,end-ii+1:end) = 255; greyImage(end-ii+1:end,:) = 255; – Krit Jan 25 '13 at 10:47