Portofolio 1
Dalam portofolio 1 berisi 2 tugas yaitu
Tugas 1
lego1.png
- Buatlah sebuah fungsi yang dapat mengubah citra lego berwarna menjadi citra lego biner dengan nilai threshold tertentu.
fungsi dalam matlab yang digunakan untuk mengubah citra berwarna menjadi citra biner dengan nilai threshold tertentu (nilai threshold yang saya gunakan antara 0-255) :
function bw = myfunct(imagefile,thresh)
im = imread(imagefile); % membaca file
imgray = rgb2gray(im); % mengubah citra berwarna menjadi citra abu2
thresh = thresh / 255; % merubah nilai threshold menjadi pecahan (antara 0-1)
imbw = im2bw(imgray,thresh); % mengubah citra menjadi black dan white dengan nilai threshold tertentu
figure, imshow(imbw);
bw = imbw;
- Citra biner yang terbentuk akan mempunyai warna hitam untuk obyek, dan warna putih untuk background. Ubahlah menjadi sebaliknya, warna hitam untuk background, dan warna putih untuk obyek.
Hasil Citra lego biner (warna hitam untuk obyek dan warna putih untuk background):
lego 1 versi biner.jpg
lego1 versi biner (background hitam)
Note : nilai threshold yang saya gunakan adalah 140
Tugas 2
- Output dari fungsi moments pada beberapa obyek di citra lego label 1
[area, centroid, thetamin, roundness] = moments(obj1)
area =
5357
centroid =
155.1107 160.3125
thetamin =
0.3715
roundness =
0.0083
- Output dari fungsi moments pada beberapa obyek di citra lego label 3:
[area, centroid, thetamin, roundness] = moments(obj3)
area =
1171
centroid =
136.5201 352.3271
thetamin =
0.1176
roundness =
0.8898
- Output dari fungsi moments pada beberapa obyek di citra lego label 9:
[area, centroid, thetamin, roundness] = moments(obj9)
area =
2184
centroid =
285.9565 76.3608
thetamin =
1.2581
roundness =
0.9777
Listing program moments.m:
function [area, centroid, thetamin, roundness] = moments(im)
[rows,cols] = size(im);
x = ones(rows,1)*[1:cols]; % Matrix with each pixel set to its x coordinate
y = [1:rows]‘*ones(1,cols); % Matrix with each pixel set to its y coordinate
area = sum(sum(im));
meanx = sum(sum(double(im).*x))/area;
meany = sum(sum(double(im).*y))/area;
centroid = [meanx, meany];
% coordinates changed with respect to centre of mass
x = x – meanx;
y = y – meany;
a = sum(sum(double(im).*x.^2));
b = sum(sum(double(im).*x.*y))*2;
c = sum(sum(double(im).*y.^2));
denom = b^2 + (a-c)^2;
if denom == 0
% let thetas equal arbitrary angles
thetamin = 2*pi*rand;
thetamax = 2*pi*rand;
roundness = 1;
else
sin2thetamin = b/sqrt(denom); %positive solution
sin2thetamax = -sin2thetamin;
cos2thetamin = (a-c)/sqrt(denom); %positive solution
cos2thetamax = -cos2thetamin;
thetamin = atan2(sin2thetamin, cos2thetamin)/2;
thetamax = atan2(sin2thetamax, cos2thetamax)/2;
Imin = 0.5*(c+a) – 0.5*(a-c)*cos2thetamin – 0.5*b*sin2thetamin;
Imax = 0.5*(c+a) – 0.5*(a-c)*cos2thetamax – 0.5*b*sin2thetamax;
roundness = Imin/Imax;
end
% draw an axis proportional to object size
% 0.5 takes into acount lines with roundness = 0
% 5 takes into acount small objects, so axis is still visible.
rho = sqrt(area)/(roundness + 0.5) + 5 ;
[X1,Y1] = pol2cart(thetamin, rho);
[X2,Y2] = pol2cart(thetamin + pi, rho);
imshow(im);
hold;
line([X1 + meanx, X2 + meanx],[Y1 + meany, Y2 + meany])
plot(meanx, meany,’r+’)
hold;
1 Tanggapan sejauh ini »
RSS Komentar · URI Lacak Balik






Pikti « It’s My Life… berkata,
Juni 6, 2008 @ 3:08 am
[...] Juni 6, 2008 at 3:08 am (Uncategorized) tes [...]