From: ImageAnalyst on
I didn't have that function because that's not a built-in part of the
Image processing Toolbox - that is part of some demo and apparently
the 2010a set of demos doesn't include that demo anymore.

It's not so easy to do in a few lines. You need to do some smoothing
of the background so that you can find pixels lighter and darker than
the background. In the code below I did a median filter followed by a
variance filter to find edges. It's still not ideal. You should
investigate other noise reduction filters and window sizes, such as a
bilateral filter, or non-local means, or something like those.

Or perhaps you can find better algorithms here:
http://iris.usc.edu/Vision-Notes/bibliography/contentschar.html#OCR,%20Document%20Analysis%20and%20Character%20Recognition%20Systems


clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Read in a user's image.
folder = 'C:\Documents and Settings\userName\My Documents\Temporary
stuff';
baseFileName = '1.bmp';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% The user posted a color image, so convert it to monochrome;
grayImage = rgb2gray(grayImage);
end
uiwait(msgbox('Draw a box. Double click the center to finish'));
J = single(imcrop(grayImage)); %create a small ROI around the letters
either FRL or RRL
J = medfilt2(J);
subplot(2, 3, 2);
imshow(J, []);

% Perform a variance filter.
% Output image is the variance of the input image in a 3 by 3 sliding
window.
VarianceFilterFunction = @(x) var(x(:));
varianceImage = nlfilter(J, [5 5], VarianceFilterFunction);
% An alternate way of doing the variance filter is on the next line:
% varianceImage = reshape(std(im2col(originalImage,[3 3],'sliding')),
size(originalImage)-2);
subplot(2, 3, 3);
imshow(varianceImage, [])
title('Variance Image', 'FontSize', fontSize);

% Compute the square root of the variance image to get the standard
deviation.
standardDeviationImage = sqrt(varianceImage);
subplot(2, 3, 4);
imshow(standardDeviationImage, [])
title('Standard Deviation Image', 'FontSize', fontSize);

thresholdedImage = standardDeviationImage > 14;
thresholdedImage = imclearborder(thresholdedImage);
thresholdedImage = imfill(thresholdedImage, 'holes');
subplot(2, 3, 5);
imshow(thresholdedImage, [])
title('Thresholded Image', 'FontSize', fontSize);

From: Vihang Patil on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <c12cc95c-2505-47b2-a3b0-65f7b1f9174d(a)k39g2000yqd.googlegroups.com>...

Thanks ImageAnalyst for your code.
It has helped me a lot. I am trying to further enhace the output by using morphological tools.
Thanks
Vihang
First  |  Prev  | 
Pages: 1 2
Prev: regexprep tokens
Next: svmtrain problem