Problems with segments in an image

4 visualizzazioni (ultimi 30 giorni)
Harold
Harold il 21 Apr 2013
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?
  3 Commenti
Harold
Harold il 22 Apr 2013
Modificato: Harold il 22 Apr 2013
I tried the region overlap idea but realized that will not work out because the matrices of each region are a different size.
Harold
Harold il 22 Apr 2013
I've re-uploaded both to a different hosting site.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 22 Apr 2013
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)
???
  1 Commento
Harold
Harold il 22 Apr 2013
Modificato: Harold il 22 Apr 2013
Not exactly. Here is what I have. Image file is http://i37.tinypic.com/29err4w.jpg
clc
clear all
filename = 'A.bmp';
I = imread(filename);
imshow(I)
%convert image from rgb to gray scale
Igray = rgb2gray(I);
%convert grayscale image to binary image
Ibw = im2bw(Igray,graythresh(Igray));
%Find edges in grayscale image
Iedge = edge(uint8(Ibw));
%Image Dilation (thickens the edges)
se = strel('square',2);
Iedge = imdilate(Iedge, se);
%Image Filling - gets rid of any background pixels inside the segments
Ifill= imfill(Iedge,'holes');
[Ilabel num] = bwlabel(Ifill);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 num]);
%Draw bounding box around segmentations
for cnt = 1:num
rectangle('position',Ibox(:,cnt),'edgecolor','r');
point = Iprops(cnt,1).Centroid;
text(point(1),point(2),num2str(cnt),'HorizontalAlignment','center','BackgroundColor',[.7 .9 .7]);
end
Edit: I think I just found out what I was doing wrong. Instead of bwlabel(Ifill), it should be bwlabel(Ibw).

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by