• clear all;

close all;

clc;

%% start

filename = 'untitled.png';

I = imread(filename);

info = imfinfo(filename);

thres = graythresh(I);

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

cmp = bwconncomp(I2);

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

bbox = vertcat(S.BoundingBox);

x = bbox(:,3);

y = bbox(:,4);

res = info.ResolutionUnit;

resX = info.XResolution;

resY = info.YResolution;

if strcmp(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);

  • for the image attached i'm getting zero value.how to mask tht rectangular region?
More Leena Silvoster's questions See All
Similar questions and discussions