How to recognize scale marker text in the image?

Hello All, I wish to identify scale marker text in the image. And would like your suggestions and ideas for Algorithm. In Image given below its 100uM and thats what I would like to recognize.

5 Comments

Have you written that text or is it written before.
If you have to CVS toolbox ( link )
@ANKUR KUMAR No I have not added the marker.
@jonas Yes, I have tried that but could not get a excellent results. rather Zero results.. Have you tried it?
Well, did you try my code below? If not, why not? If it's not what you want, then explain better exactly what "identify" means to you.

Sign in to comment.

 Accepted Answer

% file: AutoMarkerScale
% Author: AMAR P
% Version: V1_0
%Objective: Localize the Marker Scale on a Image, Perform OCR and Return
%the Value.
%==========================================================================
%==========================================================================
% Read Image
[MainImg, MainImgMap] = imread(OriginalImg);
%Convert to Binary
BinImg = im2bw(MainImg, graythresh(MainImg));
BinImg = imcomplement(BinImg);
[yMax, xMax] = size(BinImg);
%ROI here is Region of Interest select using imrect()
BotRImg = imcrop(BinImg,ROI);
[ROIy_max,ROIx_max] = size(BotRImg);
% To Remove any Noise
BotRImg = imclearborder(BotRImg);
% Run OCR on Image
ocrResult = ocr(BotRImg,'CharacterSet','0123456789numc',...
'TextLayout','Line',...
'Language','English');
MarkerValue = ocrResult.Text;
fprintf('Marker Value is = %s', MarkerValue);

More Answers (1)

It's a constant and uniform gray level, so just detect that. For example if it's gray level is 175, do
scaleMask = grayImage == 175;
scaleMask = bwareafilt(scaleMask, 1); % Take largest blob.
scaleMask = imfill(scaleMask, 'holes'); % Fill holes to get rectangular block.
Not sure what you want to do after that.

8 Comments

This will work.. Actually goal here is, While batch processing multiple images, no need to add scale every time. Program should be able to read/detect it from given image..
To batch process fiels, see the two code samples in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
Again, I have no idea what detect or identify means to you. Do you mean read the number inside the uniform area and then get a spatial calibration factor from that? Do you mean just find pixels that are in the bounding box of the scale bar background? I have no idea.
Do you mean read the number inside the uniform area and then get a spatial calibration factor from that?
Yeah Exactly..
What I have done?
Crop the ROI in Image. and performed OCR() on Cropimage.
OK, use imclearborder() to get rid of the white surround. Then call bwareafilt() to get rid of the underline.
Then to do OCR you need the Computer Vision System Toolbox. Do you have that?
Hey Hi.. seems we are on a same track.. except I wish to measure the properties of scale below so used
regionprops(Img,'BBox','Extent')
to get [x y w h] of that rectangle. Further I try to run OCR() on a Img but result was NULL. so I had to run OCR() with ROI co-ords. And thats when I was able to receive the result.
Glad it's working for you. Do you want to post the final code so that people won't post here for years to come "Can you please upload your code?" as they always do.
Sure.. I will finalize couple things and will post the result.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 3 Oct 2018

Commented:

on 10 Oct 2018

Community Treasure Hunt

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

Start Hunting!