Tugas 3

% Tugas 3 Analisis Citra dan Visi Komputer
%
% Nama : Afwan Badru Naim
% NRP : 5105100169

%fungsi untuk mengubah image ke dalam bentuk biner dengan nilai treshold tertentu
function ImageMorphology = mine(image)

%dapatkan input berupa image
inputImage = imread(image);

%ubah image ke dala, bentuk grayscale
grayscaleImage = rgb2gray(inputImage);

%gunakan nilai threshold untuk mengubah image grayscale ke dalam bentuk
%binary

binaryImage = im2bw(grayscaleImage);

structuredElement1 = strel(‘disk’,1);
closedImage = imclose(binaryImage,structuredElement1);

structuredElement2 = strel(‘octagon’,3);
openedImage = imopen(binaryImage, structuredElement2);

%lakukan operasi open-close
openClose = imclose(imopen(binaryImage,structuredElement2),structuredElement2);

%lakukan operasi close-open
closeOpen = imopen(imclose(binaryImage,structuredElement2), structuredElement2);

%imshow(binaryImage), figure, imshow(openClose), figure, imshow(closeOpen);
subplot(2,3,1),imshow(inputImage),title(‘Original Image’);
subplot(2,3,2),imshow(binaryImage),title(
‘Binary Image’);
subplot(2,3,3),imshow(closedImage),title(
‘Closed Image (strel(”disk”,1))’);
subplot(2,3,4),imshow(openedImage),title(
‘Opened Image (strel(”disk”,1))’);
subplot(2,3,5),imshow(openClose),title(
‘Open-Closed Result Image (strel(”octagon”,3)’);
subplot(2,3,6),imshow(closeOpen),title(
‘Closed-Open Result Image (strel(”octagon”,3)’);

Snapshot hasil running program :

Original image Binary Image
Closed Image, strel(‘disk’,1) Opened Image,strel(”octagon”,3)’
OpenClosed Imagestrel(”arbitrary”,[1 0 0; 0 0 0; 0 0 1]) OpenClosed Imagestrel(”arbitrary”,[1 0 0; 0 0 0; 0 0 1])

Tugas 4

% LOCATELANDMARKS – locates landmarks on SURF form
%
% Usage: [tl, tr, bl, br] = locatelandmarks(im)
%
% Argument: im – Image to be processed, assumed binary.
%
% Returns: tl, tr, bl, br
% – Coordinates of the centroids of the top-left, top-right,
% bottom-left and bottom-right landmarks respectively.
% These coordinates are returned as column vectors in the
% form [row; col] for each landmark.
%
% The function should also display the image with the centroids of the
% landmarks overlayed.

% Algoritma :
% ubah citra biner -> background hitam & objek putih
% open-close untuk menghilangkan noise
% bwlabel -> tandai blob & get blob number
% cari blob yang paling dekat dengan pojok
%

function [tl, tr, bl, br] = locatelandmarks(im)

% dapatkan input image
inputImage = imread(im);

%inverse image agar background hitam dan objek putih
inverseImage = ~inputImage;

% buat structured element
structuredElement = strel(‘square’,9);

% lakukan operasi opening
openedImage = imopen(inverseImage,structuredElement);
openClose = imclose(openedImage,structuredElement);

structuredElement2 = strel(‘square’,25);
imshow(openClose);

openClose1 = imclose(openClose,structuredElement2);
result = imopen(openClose,structuredElement2);

labeledImage = bwlabel(result);
imagesc(labeledImage),colormap(gray);
pixval on, title(‘4 pojok form’);

seBG = strel(‘square’,80);
background = imopen(openClose, seBG);

%dapatkan koordinat pusat image
[a b] = size(background);
pusatx = a/2;
pusaty = b/2;
pusatImage = [pusatx; pusaty];
imageCenter = [pusatx pusaty];

disp([‘pusat image : ‘, num2str(imageCenter)]);

for a = 1 : 4
object = labeledImage==a;
[rows,cols] = size(object);

%dapatkan koordinat x
x = ones(rows,1)*[1:cols];

%dapatkan koordinat y
y = [1:rows]’*ones(1,cols);

%dapatkan luasan object
area = sum(sum(object));

%hitung mean x
meanX = sum(sum(double(object).*x))/area;

%hitung mean y
meanY = sum(sum(double(object).*y))/area;

%dapatkan vektor centroid
centroid = [meanX; meanY];
c = [meanX meanY];

if centroid < pusatImage
tl = centroid;
topLeft = c;

elseif centroid > pusatImage
br = centroid;
bottomRight = c;
elseif meanX > pusatx && meanY < pusaty
tr = centroid;
topRight = c;
elseif meanX < pusatx && meanY > pusaty
bl = centroid;
bottomLeft = c;
end;
end;
disp([
‘topleft : ‘, num2str(topLeft)]);
disp([
‘topright : ‘, num2str(topRight)]);
disp([
‘bootomleft : ‘, num2str(bottomLeft)]);
disp([
‘bottomright : ‘, num2str(bottomRight)]);

figure,imshow(inputImage),title(‘Result Image’);
hold;
landmarks = [tl, tr, br, bl];
plot(landmarks(1,:), landmarks(2,:),‘or’,‘MarkerSize’,15,‘LineWidth’,1);
plot(landmarks(1,:), landmarks(2,:),‘+r’,‘MarkerSize’,35,‘LineWidth’,1);

Snapshot hasil running program :

Image surf01.png

pusat image : 564 392
topleft : 103.5 93.5
topright : 707 94
bottomleft : 104 965.5
bottomright : 708 965

Image surf02.png

pusat image : 564 392
topleft : 80.5 97.5
topright : 703.3547 98.21533
bottomleft : 81.03111 997.5334
bottomright : 704 996

Image surf02.png
pusat image : 564 392
topleft : 59.5 101.5
topright : 701 102
bottomleft : 59.5 1029.5
bottomright : 702 1028.5

One Response to “Portofolio 2”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s