From: Vihang Patil on
Hello,
I am trying to achieve segmentation of an image, to futher do OCR on it. I am able to remove the background of the image and able to get the 3 letters that I am interested in the image. Now, I want to further segment this letters individualy so that I can do OCR and achieve the letters in text format. But since there is very little gap in between the letters and also since there is very little variation in the grascale, I am unable to do so.
Could anyone help me on this one.
The code for segmenting the 3 letters in the image is as follows;

I = imread('1.bmp');
gray = rgb2gray(I);
figure,imshow(I);
J = imcrop(gray); %create a small ROI around the letters either FRL or RRL
figure,imshow(J);
J2 = ipexbatchDetectCells(J);
J3 = imsubtract(J2,J);
bw = im2bw(J3,graythresh(J3));
bw_fill = imfill(bw,'holes');
% figure,imshow(bw_fill);
SE = strel('rectangle',[3 3]);
bw_fill1 = imdilate(bw_fill,SE);
bw_fill1 = imfill(bw_fill1,'holes');
L = bwlabel(bw_fill1);
stats = regionprops(L,'area');
area = [stats.Area];
if length(area) > 1
bw_fill1 = bwareaopen(bw_fill1 ,(max(area) - 5));
end
figure,imshow(bw_fill1);
K = J;
K(~bw_fill1) = 0;
figure,imshow(K);

The sample files are located here http://drop.io/vihdrop
Thanks
Vihang
From: ImageAnalyst on
On Jul 3, 6:41 am, "Vihang Patil" <vihang_pa...(a)yahoo.com> wrote:
> [snip] since there is very little gap in between the letters and also since there is very little variation in the grascale, I am unable to do so.
[snip]
> Vihang
--------------------------------------------------------------------------
It looks like you have good control over the lighting and camera. As
most people know it's better to start with a good image rather than a
bad one that you try to "fix up" later with image processing.
Therefore to improve the problem issues you listed, I recommend that
you get a camera with a higher resolution and zoom in some more so
that your pair of letter strings occupy more pixels. It looks like
you're designing a machine vision system of your own rather than using
one of the numerous commercial systems for which this situation is
cheaply and easily handled. The system consists of two parts: the
image acquisition and the image analysis. You're working on the image
analysis part now but I urge you not to just assume that the work
you've done on the image capture part is perfected and finalized.
Improve the image capture part and your image analysis part will be
easier.

If you're stuck with the images because the vendor did only the image
capture part, then ask them to finish the job and do it right to
deliver a complete turnkey system (any decent vendor will be able to
do that). If you're stuck with the images because this is not a real
machine vision project but just some student exercise, then let us
know that too because there are some things that can be done if you
can't do it right (by improving the image capture).
-ImageAnalyst
From: Vihang Patil on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <759cc292-fab0-4385-b254-360363d8dd14(a)i31g2000yqm.googlegroups.com>...
If you're stuck with the images because this is not a real
> machine vision project but just some student exercise, then let us
> know that too because there are some things that can be done if you
> can't do it right (by improving the image capture).
> -ImageAnalyst

Thanks ImageAnalyst for the suggestion, but as of now, I am stuck with these images only. Yes, its a machine vision application, but I will have to manage with these images only.
Any suggestion on the image processing part?
Vihang
From: ImageAnalyst on
Vihang Patil:
I don't have your function
J2 = ipexbatchDetectCells(J);
Can you also post the intermediate images that you've obtained via
your code?
From: Vihang Patil on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <cd82e80e-2c98-405c-9f8d-44ea2c55832a(a)d16g2000yqb.googlegroups.com>...
> Vihang Patil:
> I don't have your function
> J2 = ipexbatchDetectCells(J);
> Can you also post the intermediate images that you've obtained via
> your code?

Dear ImageAnalyst
ipexbatchDetectCells is an built in function of the Image Processing Toolbox in R2006b. Nevertheless, I am posting it here

function segmentedCells = ipexbatchDetectCells(I)
%ipexbatchDetectCells Algorithm to detect cells in image.
% segmentedCells = ipexbatchDetectCells(I) detects cells in the cell
% image I and returns the result in segmentedCells.
%
% Supports batch processing demo, ipexbatch.m,
% ("Batch Processing of Image Files Using Distributed Computing").

% Copyright 2005 The MathWorks, Inc.
% $Revision: 1.1.6.1 $ $Date: 2005/06/20 03:09:37 $

% Use |edge| and the Sobel operator to calculate the threshold
% value. Tune the threshold value and use |edge| again to obtain a
% binary mask that contains the segmented cell.
[junk threshold] = edge(I, 'sobel');
fudgeFactor = .5;
BW = edge(I,'sobel', threshold * fudgeFactor);

se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWdilate = imdilate(BW, [se90 se0]);
BWnobord = imclearborder(BWdilate, 4);
BWopen = bwareaopen(BWnobord,200);
BWclose = bwmorph(BWopen,'close');
BWfill = imfill(BWclose, 'holes');
BWoutline = bwperim(BWfill);
segmentedCells = I;
segmentedCells(BWoutline) = 255;


Vihang
 |  Next  |  Last
Pages: 1 2
Prev: regexprep tokens
Next: svmtrain problem