How to convert pixel size to inches

I have an image of my experimental specimen. I know the dimensions of my specimen. I have taken a picture of my specimen. Now, how can I convert pixel information from the image to get the dimensions of my specimen? Basically, I can measure pixel distance and want to correlate to real life dimensions.

 Accepted Answer

Image Analyst
Image Analyst on 11 Aug 2011
You need to have an object of known length, such as a ruler or some other calibration standard, in your image. Then measure its length to get a calibration factor with units of centimeters (or whatever) per pixel. Then when you have some other length, just simply multiply by that calibration factor to get a length in units of centimeters. If you have an area, multiply by the square of that factor to get the area in cm^2.

4 Comments

Yes, I agree. You also need to adjust for perspective and for non-linear imaging effects (of which "fish-eye" is just an extreme of a situation that happens for many lens.)
Hi! So I am actually using your blob method from the tutorial you posted. It's a great tutorial :). I used the code below to get out the properties
stats = regionprops(vivi, 'Area', 'MinFeretProperties' , 'MaxFeretProperties', 'Circularity', 'Perimeter', 'Solidity');
%add blob numbers to the struct
for x = 1:numBlob
stats(x).Blob = x;
end
I have a known pixel- mm ratio (1 pixel = 0.013mm). Is there a way to incorperate it before I make the structure so that it automatically applies to the structure? I've tried to multiply it in with a for loop
F= fieldnames(stats);
for iF = 1:length(F)
aF = F{iF};
stats.(aF) = stats.(aF) .* pixelSize;
end
which doesn't work, but even if it did it would not accuratly represent the true value.
Any advice?
@Ella you need to check the units of what stats is. Not all of the measurements are linear distance measurements. Some are unitless ratios (like Solidity) and don't need any spatial calibration factor, and some are area measurements and need the square of the factor.
mmPerPixel = 0.013;
stats = regionprops(vivi, 'Area', 'MinFeretProperties' , 'MaxFeretProperties', 'Circularity', 'Perimeter', 'Solidity');
allAreas = [stats.Area] * mmPerPixel ^ 2; % Areas need square of spatial calibration factor.
allPerims = [stats.Perimeter] * mmPerPixel; % Linear distances need spatial calibration factor.
allSolidities = [stats.Solidity]; % Unitless measurements don't need any spatial calibration factor.
allCircularities = [stats.Circularity]; % Unitless measurements don't need any spatial calibration factor.
Thanks for your help! Once I have these portions, can I put them back into stats? I'm not very familiar with structures.

Sign in to comment.

More Answers (2)

Ash.P
Ash.P on 15 Jan 2017
@Image Analyst - The 'calibration factor' that you talk about here would be different for objects at different distance from the camera right? How do you account for this fact?

6 Comments

Right. Personally I don't, as I assume the things to be measured are all in the same plane. For situations like you describe, the Mathworks handles that with the camera calibration capabilities of the Computer Vision System Toolbox. https://www.mathworks.com/products/computer-vision/features.html#camera-calibration
Thank you for the reply Image Analyst.
In the camera calibration, are you referring to the intrinsic parameters that help determine this conversion?
Not sure what the question means. I haven't used it, but I assume you'll have to enter some kind of information like working distance, focal length, or whatever.
Yes. That was my question. Intrinsic matrix uses those except the operating distance. I am trying to estimate 'calibration factor' at different planes without using the calibration matrix. I have an object of known dimension at depth1 and I estimate what 1 pixel corresponds to at this distance and estimate the value of 1 pixel at all other distances using this value and scene geometry.
Do you have any inputs for this?
Like I said, I have used the camera calibration software provided with the Computer Visions System Toolbox. I'd have to figure it out just like you'll have to. Contact the Mathworks for help. Good luck.
Thank you! Appreciate it!

Sign in to comment.

John BG
John BG on 16 Jan 2017
Edited: John BG on 16 Jan 2017
Ashwini
You correct distance by correcting 2 angles, vertical and horizontal.
Try Michael Chan's perspective correction pack available from the File Exchange
it prompts you to key in a few points to reference elements in the picture and the a perspective transform is applied.
If you find this link useful, would please be so kind to mark my answer as accepted answer?
Thanks for time and attention,
John BG

Categories

Tags

Community Treasure Hunt

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

Start Hunting!