How do I measure a distance in real world with a picture in matlab?

21 次查看(过去 30 天)
first i have to convert pixels to cm , than i have the length between to points in cm . (in the picture) but in the real world , how many cm between the same point ? I do not know !!!

采纳的回答

Image Analyst
Image Analyst 2014-1-9
编辑:Image Analyst 2014-1-11
Sara, you need to spatially calibrate. Run my attached demo and it will show you how.
[EDIT] Attached updated spatial_calibration_demo.m
  12 个评论
Joachim Huet
Joachim Huet 2017-9-20
I would like to open this topic again, is there a way to do this calibration phase automatically ? Without needing the user to draw a line with known value !?
Image Analyst
Image Analyst 2017-9-20
Of course. For example I automatically calibrate some systems by (1) finding a 4 inch square filter paper, and (2) by using the known dimensions of the X-Rite Color Checker chart. All you need is a known real world distance of some thing , and some way to find that thing in the image and measure the distance in pixels (like by thresholding or whatever...).

请先登录,再进行评论。

更多回答(1 个)

Caroline David
Caroline David 2018-2-4
Can someone show me the code for length measurements of an image in pixels. Most preferred in mm
  9 个评论
jue xi
jue xi 2018-4-26
编辑:jue xi 2018-4-26
i used this coding, now i want to convert the width in cm.. and i have read and try out the calibration demo and still got no clue on how to convert it to cm. </matlabcentral/answers/uploaded_files/114879/Capture.PNG>
if true
% code
folder=('C:\Users\user\MATLAB');
baseFileName=('img2copy.jpg');
fullFileName=fullfile(folder,baseFileName);
format long g;
format compact;
fontSize = 20;
%IMAGE SEGMENTATION
img=imread(fullFileName);
img=rgb2ycbcr(img);
for i=1:size(img,1)
for j= 1:size(img,2)
cb = img(i,j,2);
cr = img(i,j,3);
if(~(cr > 132 && cr < 173 && cb > 76 && cb < 126))
img(i,j,1)=235;
img(i,j,2)=128;
img(i,j,3)=128;
end
end
end
img=ycbcr2rgb(img);
subplot(2,2,1);
image1=imshow(img);
axis on;
title('Skin Segmentation', 'FontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
%SEGMENTED IMAGE TO GRAYIMAGE
grayImage=rgb2gray(img);
subplot(2,2,2);
image2=imshow(grayImage);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
%GRAY TO BINARY IMAGE
binaryImage = grayImage < 245;
subplot(2, 2, 3);
axis on;
image3=imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Label the image
labeledImage = bwlabel(binaryImage); % label the connected components in an image and assigning each one a unique label
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
% Let's extract the second biggest blob - that will be the hand.
allAreas = [measurements.Area];
[sortedAreas, sortingIndexes] = sort(allAreas, 'descend');
handIndex = sortingIndexes(2); % The hand is the second biggest, face is biggest.
% Use ismember() to extact the hand from the labeled image.
handImage = ismember(labeledImage, handIndex);
% Now binarize
handImage = handImage > 0;
% Display the image.
subplot(2, 2, 4);
image4=imshow(handImage, []);
axis on;
axis image;
title('Hand Image', 'FontSize', fontSize);
% Label the image
labeledImage = bwlabel(handImage); % label the connected components in an image and assigning each one a unique label
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
% Make measurements of bounding box
props = regionprops(labeledImage, 'BoundingBox');
width = props.BoundingBox(3);
height = props.BoundingBox(4);
hold on;
rectangle('Position', props.BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
message = sprintf('The width = %f.\nThe height = %f', width, height);
uiwait(helpdlg(message));

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by