how to obtain the space between two words in a given sentence?

4 次查看(过去 30 天)
Hello, I want to obtain the space between the two words in the given image(i.e,the space between 'A' and 'MOVE','MOVE' and 'to' so on..)i want the space in terms of mm(millimeters). Please help me.Thank you
  9 个评论
Meghashree G
Meghashree G 2015-12-18
sir this is what i have done!!you can see my attached file(space.m) But still not getting,have a look and please do help me. Thank you

请先登录,再进行评论。

采纳的回答

harjeet singh
harjeet singh 2015-12-18
i used your code and modified that to detect space between pixels as shown in pic attached
%//////////// your code ////////////////////////////////////
clc;
clear all
close all
format long g;
format compact;
fontSize = 20;
fullFileName = fullfile(pwd, 'capture.png');
grayImage = imread(fullFileName);
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
figure(1)
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
binaryImage = grayImage > 128;
figure(2)
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
%////////////// include this //////////////////////////////////////////
[m,n]=size(binaryImage);
[lab,num]=bwlabel(~binaryImage);
for i=1:num-1
img_1=lab==i;
img_2=lab==i+1;
[r,c]=find(lab==i);
[r1,c1]=find(lab==i+1);
if(min(c1)-max(c) > fontSize)
line([min(c1) max(c)],[round(m/2) round(m/2)],'LineWidth',3);
text((min(c1)+max(c))/2,10,num2str(min(c1)-max(c)));
end
end
hold off
  8 个评论
Poornima Gokhale
Poornima Gokhale 2016-1-26
Hello sir, I used the above code with some modifications to find the space between the words. But I am getting negative values a distance.Please help me.
harjeet singh
harjeet singh 2016-1-26
try use code in this way
clc;
clear all
close all
format long g;
format compact;
fontSize = 20;
fullFileName = fullfile(pwd, 'segmented_line.png');
grayImage = imread(fullFileName);
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
figure(1)
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
binaryImage = grayImage; %> 128;
figure(2)
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
%////////////// include this //////////////////////////////////////////
[m,n]=size(binaryImage);
se=strel('disk',8);
binaryImage1=imdilate(~binaryImage,se);
binaryImage1=bwareaopen(binaryImage1,500);
[lab,num]=bwlabel(binaryImage1);
figure(3)
imshow(binaryImage)
hold on
for i=1:num-1
img_1=lab==i;
img_2=lab==i+1;
[r,c]=find(lab==i);
[r1,c1]=find(lab==i+1);
if(min(c1)-max(c) > fontSize && max(c1)-min(c1)>10)
line([min(c1) max(c)],[round(m/2) round(m/2)],'LineWidth',3);
text((min(c1)+max(c))/2,10,num2str(min(c1)-max(c)));
end
end
hold off

请先登录,再进行评论。

更多回答(1 个)

harjeet singh
harjeet singh 2015-12-17
dear meghashree try this code
clear all
close all
clc
image=imread('capture.png');
figure(1)
imshow(image)
drawnow
img_1=image(:,:,1)<150;
figure(2)
imshow(img_1)
drawnow
se=strel('disk',5);
img_2=imdilate(img_1,se);
figure(3)
imshow(img_2)
drawnow
[lab,num]=bwlabel(img_2);
for i=1:num
[r,c]=find(lab==i);
img_3=image(min(r):max(r),min(c):max(c),:);
figure(4)
subplot(3,3,i)
imshow(img_3);
drawnow
end
  13 个评论
Sumita Das
Sumita Das 2016-12-15
How do I use the values in the figure? for eg : if I want to take average of all the values?
sparsh garg
sparsh garg 2021-8-28
Hey harjeet thanks for the code,in this we are able to figure out the spacing between two words.However for examples like this,I am also interested in looking at the spacing between the characters in a word.If anyone can give me pointers on how to go about this,it would be really useful.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by