Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
0 of .
Results for:
P. 1
How to Calculate Original Size of Objects in Digital Image by Matlab

# How to Calculate Original Size of Objects in Digital Image by Matlab

Ratings: (0)|Views: 1,495|Likes:

### Availability:

See more
See less

11/09/2013

pdf

[digital image processing] December 9, 2012

[janshendry@gmail.com] Page 1
HOW TO CALCULATE ORIGINAL SIZE OF OBJECTSIN DIGITAL IMAGE BY MATLAB
In this article, I will elaborate how do we calculate size of objects in digital image by Matlab. Thissize is the original one, which is measure in cm. We actually do not need sophisticated algorithm todo that. But when the combination of objects get complicated, we are gonna need some algorithm tosolve. Why do we need such algorithm? To extract the objects from background, then distinguisheach of them and decide what kind of objects they are.I have prepared some images that contain an object which is square and use these images as input to program. Below are steps I arrange in order to accomplish our task:-

Convert to binary file-

If the detected objects are not white colored then inverse it -

If the object more than one then distinguish them and then process it individually-

Get width and height of the object then divide it with value of resolution. One can take thevalue of image resolution by using IMFINFO from matlab.-

Convert size of object to cm if resolution in inch or let it as it is if already in cm.Okay, based on the steps I mention above I already made a program to fulfill the task. Lets take alook.
clearall;

closeall;

clc;

%% start

filename ='back.jpg';% resolusi = 96

% filename = 'back2.jpg'; % resolusi = 200

% filename = 'back3.jpg'; % resolusi = 300

% filename = 'back4.jpg';

info = imfinfo(filename);

thres = graythresh(I);

I2 = ~(im2bw(I, thres));

cmp = bwconncomp(I2);

S = regionprops(cmp, {'BoundingBox'});

x = S.BoundingBox(3);

[digital image processing] December 9, 2012

[janshendry@gmail.com] Page 2
y = S.BoundingBox(4);

res = info.ResolutionUnit;

resX = info.XResolution;

resY = info.YResolution;

ifstrcmp(res,'Inch')

lebar = 2.54 * x / resX;

tinggi = 2.54 * y / resY;

else lebar = x / resX;

tinggi = y / resY;

end

fprintf('X Resolution = %.2f %s\n', resX, res);

fprintf('Y Resolution = %.2f %s\n', resY, res);

disp('Size of Object:');

fprintf('Width = %.2f cm\n', lebar);

fprintf('Height = %.2f cm\n', tinggi);

%% end

When I run this program, I get results below: I have put an square object in an image, size of theobject is 2 cm x 2 cm. Now, we ask Matlab to calculate it by using steps we made above.Result

[digital image processing] December 9, 2012

[janshendry@gmail.com] Page 3
Result Result