Measuring Object Length (with a Reference Object)

It has been a long long time I've not update this blog due to my new notebook modem spoiled just after I bought it! The support staff came 3 times and now I am waiting for a replacement model...

Further more, life become more and more busy, and sometimes I really out of idea what to post here. :P

Until I receive some e-mail from some reader...

This is rather a simple example to measure a length of an object in an image. We could easily get the reading in pixels, and with a reference, we could just use a simple mathematic to compute the lenght in some standard unit.

Let's see this simple example:

1. Reading image and show the true color image.
clear all;clc;
I = imread('pic29.tif');
imshow (I);



2. Assuming that we know the length of the red object (as reference) which is 5 cm, locate the red object with simple command and find the length in pixels:


Ired_labeled = bwlabel(Ired);
Ired_props = regionprops(Ired_labeled);
Ired_length_in_pixel = Ired_props.BoundingBox(3);
disp(Ired_length_in_pixel);

212

3. To measure the length of the green object, extract the object:

Igreen_labeled = bwlabel(Igreen);
Igreen_props = regionprops(Igreen_labeled);
Igreen_length_in_pixel = Igreen_props.BoundingBox(3);
disp(Igreen_length_in_pixel);

146


4. Calculate the length of green object in cm

Igreen_length_in_cm = Igreen_length_in_pixel/Ired_length_in_pixel*5;
disp(Igreen_length_in_cm);

3.4434