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

8 Ansichten (letzte 30 Tage)
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 Kommentare
Meghashree G
Meghashree G am 17 Dez. 2015
sure sir,i will try..Thank you
Meghashree G
Meghashree G am 18 Dez. 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

harjeet singh
harjeet singh am 18 Dez. 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 Kommentare
Poornima Gokhale
Poornima Gokhale am 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
harjeet singh am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

harjeet singh
harjeet singh am 17 Dez. 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 Kommentare
Sumita Das
Sumita Das am 15 Dez. 2016
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 am 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by