MATLAB: Problems with segments in an image

imageImage Processing Toolboximage segmentation

I'm working on a project that involves character recognition. If I load an image that has for example the letters A, B, C, D, my program finds the regions and does some operations on it to get rid of vertical and horizontal white lines and also re-sizes the image to a pre-defined size. This works fine. However, if I load an image up that has one letter for example A, the bwlabel segments the image into 4 regions because that's the minimum number of regions it can have. I need to be able to code some logic that will help with this.
Here is the procedure that I have developed thus far (it has problems). num is the number of regions in the image from bwlabel. Ibw is the logical matrix for the image. Iprops is a structured array of properties for each region. Each row is a region.
grid_size = [10, 10];
[r c] = size(Iprops);
if num == 4 && num == r %single character recognition
segments = imresize(Ibw, grid_size, 'bicubic');
segments = segments(:)';
end
The problem with this code lies in the use of num == r. An image of one letter will return the same number of properties as an image of 4 letters. I need to modify my logic to account for this.
Edit: Now that I think of it, if I can determine if any regions overlap I could include that in my logic statement. The questions arise though, how can I check if any regions overlap?

Best Answer

There is no reason why the A would be split up into 4 regions. I'd have to see your code. Do you do something like
blackLetters = grayImage < 128;
[labeledImage, numberOfBlobs] = bwlabel(blackLetters)
???