Reputation: 13
I have an image containing text and I want to cut each letter from the image. How would I achieve this using MATLAB?
Upvotes: 0
Views: 1564
Reputation: 21563
Simplest would be to test for the color:
Find out which color the letters have.
Suppose this is your image, containing a letter T written in color 5:
myImage = round(4*rand(6));
myImage(1:2,:) = 5; %Drawing the top bar of the T
myImage(:,3:4) = 5; %Drawing the leg of the t
myColor = 5;
Now to only keep the letter(/letters):
myImage(myImage~=myColor) = NaN
Now you can plot it using
surf(myImage)
It is not too hard to extend this to a color range (or to a set of RGB colors, depending on what kind of format your image is)
Upvotes: 2
Reputation: 661
If you have the toolbox you can quickly identify each separate letter in your image.
Starting with a gray scale image you have to find a segmentation threshold with
level = graythresh(Img);
Then convert the image to binary with
Img = im2bw(Img,level);
With
Cc = bwconncomp(Img);
you get a structure that contains the linear indices of each identified component in its field
Cc.PixelIdxList
See the documentation for those functions to adjust the segmentation to your needs.
You have to implement the connected component algorithm yourself.
From the Matlab documentation:
>The basic steps in finding the connected components are:
>
>1. Search for the next unlabeled pixel, p.
>2. Use a flood-fill algorithm to label all the pixels in the connected component containing p.
>3. Repeat steps 1 and 2 until all the pixels are labeled.
Upvotes: 2