Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem in detecting outline of image

Subject: Problem in detecting outline of image

From: Li Fang Fan Li

Date: 5 Nov, 2010 16:36:05

Message: 1 of 4

Hi,

There is this image of some seperate characters which I need to detect outlines. The problem is that the character "B" is blur, while the character "1" is kind of missing its bottom. Therefore, if I try threshold with level of 0 (to get almost the full "1"), I will also enhance the blur side of "B", whereas, if I try threshold with level of 0.1 (to get rid of blur in "B"), I will lost the bottom of "1".

Here is my code:

image0 = imread ('image.bmp');

% Display the original image
figure_index = figure_index+1;
figure(figure_index);
imshow(image0);
title('The original image');

% Display the histogram of the original image
figure_index = figure_index+1;
figure(figure_index);
imhist(image0);
title('Histogram of the original image');

% Threshold the image
image0 = im2bw(image0, 0.1);
figure_index = figure_index+1;
figure(figure_index);
imshow(image0);
title('The binary image after thresholding');

% Dilate the image
NHOOD = [1; 1];
image0 = imdilate(image0, NHOOD);
figure_index = figure_index+1;
figure(figure_index);
imshow(image0);
title('The dilated image');

% Using the function "edge"
  image1 = single(image0);
  image_edge = edge(image1, 'roberts', 'thinning');
% image_edge = edge(image0, 'sobel');
% image_edge = edge(image0, 'prewitt');
% image_edge = edge(image0, 'canny');
figure_index = figure_index+1;
figure(figure_index);
imshow(image_edge);
title('The character outlines using "edge"');

% Using the function "bwmorph"
image2 = bwmorph(image0, 'remove');
figure_index = figure_index+1;
figure(figure_index);
imshow(image2);
title('The character outlines using "bwmorph"');

Here is the results:
http://img574.imageshack.us/img574/4126/capturew.jpg

Subject: Problem in detecting outline of image

From: ImageAnalyst

Date: 5 Nov, 2010 16:50:31

Message: 2 of 4

So what's the question? What's the big picture here? What are you
trying to do? If you're trying to do OCR you're going to have to make
your algorithm robust enough to handle imperfectly shaped characters.
None of those pictures you gave are necessarily "wrong." And there is
not necessarily any single "correct" answer. Each image you gave was
correct given the input and the assumptions that it uses.

Some ways to get more boundaries/outlines are to:
(1) use bwboundaries,
(2) maybe do some kind of noise reduction prior to thresholding,
(there are tons of noise reduction methods)
(3) use a morphological closing operation, or
(4) use Topology-Preserving Alternating Sequential Filters (http://
www.esiee.fr/~coupriem/Pdf/cb04.pdf) to smooth the boundaries.
(5) use alpha shapes

Subject: Problem in detecting outline of image

From: Sean

Date: 5 Nov, 2010 17:02:04

Message: 3 of 4

"Li Fang Fan Li" <le4phuong@yahoo.com> wrote in message <ib1bpl$rad$1@fred.mathworks.com>...
> Hi,
>
> There is this image of some seperate characters which I need to detect outlines.
> Here is the results:
> http://img574.imageshack.us/img574/4126/capturew.jpg

You could try using the second output to my shrinkWrap function, available here:
http://www.mathworks.com/matlabcentral/fileexchange/29175-shrinkwrap

Since you didn't post just the original image I wasn't able to try it for you. However, congrats on at least giving us something for an image on the first post!

Subject: Problem in detecting outline of image

From: Li Fang Fan Li

Date: 6 Nov, 2010 17:46:03

Message: 4 of 4

Finally, I did some "cheating":

I cut "B" from the image, thresholded it with level of 0.1, while the rest I used level of 0, and then added the 2 results together.

Thank you.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us