I have uploaded images:
Please tell how to remove the extra white regions, other than the text. I need only the text. Please help.

 채택된 답변

Image Analyst
Image Analyst 2012년 4월 20일

0 개 추천

For what's it's worth, here is 10 minutes worth of a very simplistic attempt to isolate letters. It obviously misses some of the letters for the reasons I mentioned in my comments above. That could possibly be fixed to get some of the missing ones, at the expense of altering the shapes of the ones it got correctly on the first pass, or maybe you can avoid even that with an even more sophisticated algorithm.
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 demo image.
folder = 'C:\Users\Kash\Documents\Temporary';
baseFileName = 'jlGZw.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Convert to gray scale image and threshold to get binary image.
binaryImage = rgb2gray(grayImage) > 100;
% Display the image.
subplot(2, 3, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Invert it.
binaryImage2 = ~binaryImage;
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage2, []);
title('Inverted Binary Image', 'FontSize', fontSize);
% Border kill.
binaryImage3 = imclearborder(binaryImage2);
% Get rid of blobs smaller than 15.
binaryImage3 = bwareaopen(binaryImage3, 15);
% Display the image.
subplot(2, 3, 4);
imshow(binaryImage3, []);
title('Binary Image', 'FontSize', fontSize);
% Crop to bounding box.
verticalProfile = any(binaryImage3, 2);
horizontalProfile = any(binaryImage3, 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
binaryImage4 = imcrop(binaryImage3, [x1, y1, x2-x1+1, y2-y1+1]);
% Display the image.
subplot(2, 3, 5);
imshow(binaryImage4, []);
title('Binary Image', 'FontSize', fontSize);
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(binaryImage4, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'all');
allAreas = [blobMeasurements.Area]
title('Labeled Letters', 'FontSize', fontSize);

댓글 수: 4

kash
kash 2012년 4월 20일
편집: Image Analyst 2016년 12월 25일
Thanks but some letters are missing and i did not get bounding box for each line for those text,i need two bounding boxes for each line(because it has two lines of text), please help
Image Analyst
Image Analyst 2012년 4월 20일
Yes, like I said. I can't continue/complete this for you - this is where you take over.
Hetal Jariwala
Hetal Jariwala 2016년 8월 26일
Thanks for the information. works like charm
shafaq nisar
shafaq nisar 2016년 12월 25일
it is helpful

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Walter Roberson
Walter Roberson 2012년 4월 18일

0 개 추천

Everything in your images appears to be text. English in one patch, something Arabic-like in another patch, and some alphabet I do not recognize in a third patch.
Everything is text is some alphabet.

댓글 수: 7

kash
kash 2012년 4월 18일
http://imgur.com/77Dxh
thi sis original image ,for text detection using connected component i got that output
else please tell hoe to get text from
http://i.imgur.com/jlGZw.jpg
kash
kash 2012년 4월 18일
Walter i did not get any required answer from that link
Walter Roberson
Walter Roberson 2012년 4월 19일
All three areas in your picture are text, so none of them can be removed.
Wasps read the brick walls of my house every year and find the "enter here" signs easily. I don't know the alphabet the wasps are using, but then I don't know the Arabic-like alphabet in your pictures either.
kash
kash 2012년 4월 19일
ok walter plz tell how to draw bounding box for each word in that image
Walter Roberson
Walter Roberson 2012년 4월 19일
No, I do not know how to find word boundaries for the Arabic-like string, or for wasp-ish, or for Dalek.
kash
kash 2012년 4월 20일
Walter i need for only hindi and english words

댓글을 달려면 로그인하십시오.

Geoff
Geoff 2012년 4월 19일

0 개 추천

As Walter says, everything is text. Are you planning to use character recognition on this?
In your case, I'm going to assume you want to do the filtering only on the supplied images.
I would try something like this:
1. Detect blobs of connected pixels.
2. Go through your blob list and discard any that don't meet some required criteria (width, height, width/height ratio, number of pixels).
3. You are left with a list of all blobs that meet your 'goodness' criteria, and you construct an image using the pixels of those blobs.
An easy way to detect blobs is by the Union-Find algorithm: http://en.wikipedia.org/wiki/Disjoint-set_data_structure
There might be a nicer description somewhere else with pretty diagrams... Use Google.
You move through your image and do a Union on the current pixel with:
* the pixel immediately right (x+1, y)
* the pixel immediately down (x, y+1)
* the pixel immediately down and right (x+1,y+1)
* the pixel immediately down and left (x-1, y+1)
I haven't done this for years, and my brain doesn't feel like digging it up right now. But that's somewhere to start.

댓글 수: 6

kash
kash 2012년 4월 19일
Geoff can u tell how to draw bounding box for each line in that image
Geoff
Geoff 2012년 4월 19일
What line? Which image? You gave us two images. You mean the real messy one? You mean the lines above and below "Hydraulics Laboratory"?
Image Analyst
Image Analyst 2012년 4월 20일
Yeah, it's possible (for this image) that color segmentation might produce a better binary image than whatever kash did. But I foresee a great deal of trouble with the mix of languages, like you said. But I'm pretty sure all the OCR apps in the File Exchange are fairly unsophisticated, and not robust, or dependent on characters that match very specific templates, or have other limitations. Robust OCR is not an easy task. I did write some simple code to get the letters based on the (admittedly poor) binary image he supplied here, and it's in my Answer in this thread.
kash
kash 2012년 4월 20일
GEof a bounding box for a word "Hydraulics Laboratory" and for a line which in in hindi,so i will get two bounding boxes for two lines
Geoff
Geoff 2012년 4월 20일
Just to be clear here, are you intending to use this method on other images? Any useful method that you can apply to this image may well not work at all on other images. If you just want to do this image, is there a reason you need to "detect" the lines of text? Cos I know what I'd do... Click, click, click, click, click, click, click, click. Eight user-selected co-ordinates = two bounding polygons. Anyway, this thread seems to have gone beyond 'help with MatLab', and into 'please write my algorithm'-territory.
kash
kash 2012년 4월 20일
Geof whats the solution for this

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2012년 4월 19일

0 개 추천

Well I didn't see any white text whatsoever. Only some black text interior to some white surround. (You could make it white though with inverting, border-clearing, hole-filling, and some other tricks though.) So my output image would be all zero. I think this task, doing OCR on text with very strange fonts, graphics, noise and all kinds of other garbage in the image is beyond kash's abilities or even mine. There are whole OCR companies with dozens of people who have worked on this for decades and even their accuracy would be low for these kinds of images.

댓글 수: 4

Walter Roberson
Walter Roberson 2012년 4월 20일
I think kash's original image would be the easiest one to work with, http://imgur.com/77Dxh .
Isolate the blue box, convert blue to black, do the ocr on the white.
Geoff
Geoff 2012년 4월 20일
Oh! I never saw that image. I concur... Do the hard stuff BEFORE filtering out all the useful data from your image.
kash
kash 2012년 4월 20일
S walter you are correcr cut i dont need ocr,i only need bounding box for each line of text
Image Analyst
Image Analyst 2012년 4월 20일
One way to do it is in my code that has the comment "% Crop to bounding box."

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

질문:

2012년 4월 18일

편집:

2016년 12월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by