Professional Documents
Culture Documents
Muhammad Iqbal Nahariqi-181080200225-PROJECT MENGHITUNG KELILING
Muhammad Iqbal Nahariqi-181080200225-PROJECT MENGHITUNG KELILING
Muhammad Iqbal Nahariqi-181080200225-PROJECT MENGHITUNG KELILING
UAS PCD
6. Labelling objek
7. Menghitung luas masing-masing objek Area
SOURCE KODE
clc;clear;close all;
I = imread('coins.png');
figure, imshow(I)
bw = im2bw(I, graythresh(I));
bw2 = imfill(bw,'holes');
s = regionprops(bw2, 'centroid','area','perimeter');
centroids = cat(1, s.Centroid);
area = cat(1, s.Area);
perimeter = cat(1, s.Perimeter);
hold on
plot(centroids(:,1), centroids(:,2), 'r*')
[B,L] = bwboundaries(bw2,'noholes');
[~,num] = bwlabel(bw2,8);
for k = 1:num
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'y', 'LineWidth', 2)
text(boundary(1,2),boundary(1,1)-7,strcat(['Label =
',num2str(k)]),'Color','r',...
'FontSize',10,'FontWeight','bold');
text(boundary(1,2),boundary(1,1),strcat(['Area =
',num2str(area(k))]),'Color','b',...
'FontSize',10,'FontWeight','bold');
text(boundary(1,2),boundary(1,1)+7,strcat(['Perim =
',num2str(perimeter(k))]),'Color','g',...
'FontSize',10,'FontWeight','bold');
text(boundary(1,2),boundary(1,1)+14,strcat(['X =
',num2str(centroids(k,1))]),'Color','c',...
'FontSize',10,'FontWeight','bold');
text(boundary(1,2),boundary(1,1)+21,strcat(['Y =
',num2str(centroids(k,2))]),'Color','c',...
'FontSize',10,'FontWeight','bold');
end