Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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 !!!

Respuesta aceptada

Image Analyst
Image Analyst el 9 de En. de 2014
Editada: Image Analyst el 11 de En. de 2014
Sara, you need to spatially calibrate. Run my attached demo and it will show you how.
[EDIT] Attached updated spatial_calibration_demo.m
  12 comentarios
Joachim Huet
Joachim Huet el 20 de Sept. de 2017
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 el 20 de Sept. de 2017
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...).

Iniciar sesión para comentar.

Más respuestas (1)

Caroline David
Caroline David el 4 de Feb. de 2018
Can someone show me the code for length measurements of an image in pixels. Most preferred in mm
  9 comentarios
Image Analyst
Image Analyst el 22 de Abr. de 2018
Start your own question for this, and attach 'img11.jpg'.
jue xi
jue xi el 26 de Abr. de 2018
Editada: jue xi el 26 de Abr. de 2018
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));

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by