how to obtain the space between two words in a given sentence?
4 views (last 30 days)
Show older comments
Meghashree G
on 17 Dec 2015
Commented: sparsh garg
on 28 Aug 2021
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 Comments
Accepted Answer
harjeet singh
on 18 Dec 2015
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 Comments
Poornima Gokhale
on 26 Jan 2016
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
on 26 Jan 2016
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
More Answers (1)
harjeet singh
on 17 Dec 2015
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 Comments
Sumita Das
on 15 Dec 2016
How do I use the values in the figure? for eg : if I want to take average of all the values?
sparsh garg
on 28 Aug 2021
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.
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!