PORTOFOLIO 2 ACVK

# Threshold yang digunakan untuk mengubah gray image menjadi image biner ialah 68
# Structuring element yang digunakan untuk operasi open-close maupun close-open ialah menggunakan fungsi circularstruct dengan radius 2

# Gambar diri

Foto Diri Asli

# Gambar diri versi biner

Gambar Diri Biner

# Open-close gambar diri

Gambar diri open-close

# Close-open gambar diri

Close-open gambar diri

# Output surf01.png dengan locatelandmarks.m

locatelandmarks surf01.png

# Output surf02.png dengan locatelandmarks.m

locatelandmarks surf02.png

# Output surf05.png dengan locatelandmarks.m

locatelandmarks surf05.png

# Listing code locatelandmarks.m

% 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.

function [tl, tr, bl, br] = locatelandmarks(im)
[rows,cols] = size(im);
   
    % inisialisasi koordinat landmarks ke extreme
    tl=[rows;cols];
    tr=[rows;0   ];
    bl=[0   ;cols];
    br=[0   ;0   ];
   
    %mengubah tampilan image biner
    bw = ~im;
  
    %faktor skala
    a = 8/784;
   
    SE = ones(a*rows, a*cols);
   
    %melakukan operasi open close
    closeopen = imopen(imclose(bw,SE),SE);
   
    %matriks dengan tiap pixwl diset sesuai dengan koordinat x-nya
    x = ones(rows,1)*[1:cols];
    %matriks dengan tiap pixwl diset sesuai dengan koordinat y-nya
    y = [1:rows]’*ones(1,cols);
   
    %melabeli semua blobs
    [L, num] = bwlabel(closeopen);
   
    %mencari blobs untuk menemukan pusat dan landmarknya
    for i = 1:num
        img = L==i;
        area(i) = sum(sum(img));
        meanx = sum(sum(double(img).*x))/area(i);
        meany = sum(sum(double(img).*y))/area(i);
       
        %menentukan tl
        if tl(1)+tl(2) > meanx + meany
            tl = [meanx; meany];
            tlindex = i;
        end
        %menentukan tr
        if tr(1)-tr(2) > meanx - meany
            tr = [meanx; meany];
            trindex = i;
        end
        %menentukan br
        if br(1)+br(2) < meanx + meany
            br = [meanx; meany];
            brindex = i;
        end
        %menentukan bl
        if bl(1)-bl(2) < meanx - meany
            bl = [meanx; meany];
            blindex = i;
        end
    end
   
    % ujicoba untuk upside down form
    if area(tlindex) < area(blindex) && area(trindex) < area(brindex)
        ‘warning: upside down form’
        locatelandmarks(imrotate(im,180));
       
    else imshow(im)
        hold;
        landmarks = [tl, tr, br, bl];   
        plot(landmarks(1,:), landmarks(2,:),’+r’,'MarkerSize’,50,’LineWidth’,2);
        hold;
end