How to find the size of the handwritten word in an image?
이전 댓글 표시
When a word is given I want to find the size of it (not the width) i.e., if a word like 'hello' is given its approximate size should be found out considering all the upperzone letters like 'l' and middle zone letters like 'e'.I have tried the bounding box but it is not efficient because it will give the maximum possible height, but i want the average height. Please help me with the code.

답변 (2개)
Image Analyst
2015년 12월 19일
To get the average height, you'll have to scan across the image column by column using find to find the first black pixel and the last black pixel
for col = 1 : size(grayImage, 2)
topRow(col) = find(grayImage < someThreshold, 1, 'first');
bottomRow(col) = find(grayImage < someThreshold, 1, 'last');
height(col) = bottomRow(col) - topRow(col);
end
meanHeight = mean(height);
댓글 수: 5
Poornima Gokhale
2015년 12월 20일
Image Analyst
2015년 12월 20일
Use the thresholding application in my File Exchange to decide: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Poornima Gokhale
2015년 12월 21일
Image Analyst
2015년 12월 21일
The app will work with either floating point images or integer images. The max threshold on the right is the highest gray level in the image I believe, or it may be the greatest value possible for integer images (I don't remember).
Integer images are typically what you read from standard format image files. You might get a floating point image if you did something like did a conversion from RGB to LAB or HSV color space, or if you summed a bunch of images and cast them to double before summing so that you would not get clipping. You should just use whatever image you have that you want to threshold.
I don't know the threshold values (low and high) that you should use. Often times it's a judgment call and that's why I built this interactive program. Sometimes you don't have a nice bimodal histogram that you can find the valley of. Sometimes it's an ugly histogram with no obvious place to threshold it at. That's why sometimes you need a human to do the thresholding at a place that is reasonably good. You might have some false blobs, but then perhaps you can go and get rid of those some other way, such as by size or shape filtering.
Poornima Gokhale
2015년 12월 21일
harjeet singh
2015년 12월 21일
편집: harjeet singh
2015년 12월 21일
may be this code will help you

clear all
close all
warning off
clc
img1=imread('word.png');
[m n x]=size(img1);
figure(1)
imshow(img1)
drawnow
img2=img1(:,:,1)<80;
img2=bwareaopen(img2,50);
figure(2)
imshow(img2)
[lab,num]=bwlabel(img2);
figure(1)
imshow(img1)
hold on
for i=1:num
[r,c]=find(lab==i);
plot([mean(c) mean(c)],[min(r) max(r)],'r');
text(mean(c)+5,m,num2str(max(r)-min(r)));
hold on
end
댓글 수: 7
Meghashree G
2015년 12월 22일
sir,should we take the average of those numbers which is on the image(i.e 20,44 etc?)if so,how to take the values displayed on the image and compute the average ?
Image Analyst
2015년 12월 22일
Of course. Didn't you see my answer above. I do exactly that -- get the mean over every column.
harjeet singh
2015년 12월 22일
use this for averaging
clear all
close all
warning off
clc
img1=imread('word.png');
[m n x]=size(img1);
figure(1)
imshow(img1)
drawnow
img2=img1(:,:,1)<80;
img2=bwareaopen(img2,50);
figure(2)
imshow(img2)
[lab,num]=bwlabel(img2);
figure(1)
imshow(img1)
hold on
a=0;
for i=1:num
[r,c]=find(lab==i);
plot([mean(c) mean(c)],[min(r) max(r)],'r');
text(mean(c)+5,m,num2str(max(r)-min(r)));
a=a + (max(r)-min(r));
hold on
end
a=a/num;
display(strcat('average:',num2str(a)));
Meghashree G
2015년 12월 23일
average:37.2857 is the answer.is it the pixel count?no,if i'm correct.then what is the unit for the average sir?
Meghashree G
2015년 12월 23일
@image analyst.Yes sir i did see your answer :) we got the average pixel count too :)
harjeet singh
2015년 12월 23일
yes meghashree its the pixel count
Meghashree G
2015년 12월 23일
oh ok sir .thanks a lot :) @image analyst ,sir thank you for you also :)
카테고리
도움말 센터 및 File Exchange에서 Blocked Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!