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

37 views (last 30 days)
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
Meghashree G
Meghashree G on 18 Dec 2015
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

Sign in to comment.

Accepted Answer

harjeet singh
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
harjeet singh
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

Sign in to comment.

More Answers (1)

harjeet singh
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
sparsh garg
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!