How to make label on the image and find the distance?

1 view (last 30 days)
Hello,
I have one image and i want to put label on it for finding the distace.
anyone suggest or give code to make label on that region which shown in fig. and also want to plot line between two black line in that box.
alos i attched my file to look at my code.

Accepted Answer

Image Analyst
Image Analyst on 9 Aug 2020
I don't know how a label would help you "for finding the distace". But anyway, to put a text label on the image use the text() function. To put a rectangle on the image use the rectangle() function. To plot over the image, use the plot() function.
When you say "finding distance between two black line" I don't know what that means. There are lots of distances between lots of points on two black lines, like your horizontal line and your vertical line. What distance are you talking about?
  3 Comments
Prashant
Prashant on 16 Aug 2020
Hi Image analyst
I have checkerboard and i want to find number of pixel in one square block. I know the size of this block is
34 x 34 mm and now i want to see that in that one square block how many pixelis there?
I have written this code, but with this code i can find center to center distance not corner to corner. how can i find this?
the code is below:
fontSize = 13;
numImages = 20;
files = cell(1, numImages);
for i = 1:numImages
files{i} = fullfile('S:\EE_Elektrik_Elektronik\Licht_Sicht_Stud\1000_Studenten\Khandelwal\Masterarbeit\MATLAB\Image_processing\Calibration\10m\10m\Image_neue', sprintf('IMG_%d.JPG', i));
end
% Display one of the calibration images
magnification = 20;
I = imread(files{1});
imshow(I) % a1=original image (unprocessed)
a1G=mat2gray(I);
a1GCT=graythresh(a1G);
a1B=im2bw(a1G,a1GCT);
a1C=imcrop(a1B);
a1RP=regionprops(a1C,'Centroid','MajorAxisLength',...
'MinorAxisLength','Orientation', 'Eccentricity');
CentroidS=cat(1,a1RP.Centroid);
x = CentroidS(:,1);
y = CentroidS(:,2);
figure
imshow(a1C)
hold on
plot(x,y,'b*')
w = msgbox('Pick 2 points');
waitfor(w)
while 1
xy = ginput(2); % get coordinates of mouse clicks
% find 2 closes points
[~,ind] = pdist2([x y],xy,'euclidean','Smallest',1);
x1 = x(ind);
y1 = y(ind);
plot(x1,y1,'o-r') % plot closes points
d = pdist([x1 y1]); % distance between points
t = text(mean(x1),mean(y1),num2str(d));
set(t,'Color','Yellow','BackgroundColor','Black');
w = waitforbuttonpress; % mouse click - conntinue, button - quit
disp('press anything to quit')
if w % if button was pressed - quit
break
end
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!