필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
sara
sara 2014년 1월 9일
편집: jue xi 2018년 4월 26일
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
Image Analyst
Image Analyst 2018년 4월 22일
Start your own question for this, and attach 'img11.jpg'.
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