Muhammad Iqbal Nahariqi-181080200225-PROJECT MENGHITUNG KELILING

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

PROJECT

UAS PCD

MENGHITUNG LUAS DAN KELILING

Muhammad Iqbal Nahariqi


(181080200225)

PROGRAM STUDI INFORMATIKA


FAKULTAS SAINS DAN TEKNOLOGI
UNIVERSITAS MUHAMMADIYAH SIDOARJO
2020
1. Membaca dan menampilkan citra grayscale

2. Mengkonversi citra grayscale menjadi citra biner


3. Melakukan operasi morfologi filling holes

4. Menentukan centroid dan boundary objek


5. Menampilkan koordinat centroid masing-masing objek

6. Labelling objek
7. Menghitung luas masing-masing objek Area

8. Menghitung keliling masing-masing objek perimeter


9. Menampilkan semua hasil penghitungan

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

You might also like