Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

clc

clear all
close all
pic=imread('wei.jpg');
imshow(pic);
% % % untuk filtering ybr
ybr=rgb2ycbcr(pic);
% figure;imshow(ybr)
y=ybr(:,:,1);
b=ybr(:,:,2);
r=ybr(:,:,3);
figure;imshow(y)
% figure;imsh1show(r)
% % % pengambilan nilai mask
nr=150;
d=5;
mask=(r > nr-d) & (r < nr+d);
% figure;imshow(mask)
% % % membuang sampah bit 0 yang luasnya 500 pixel
mask2=bwareaopen(mask,100);
% figure;imshow(mask2)
% % % membuang sampah bit 1 dalam luas putih
mask3=imfill(mask2,'hole');
figure;imshow(mask3)
% % % memunculkan centroid
s=regionprops(mask3, 'Centroid', 'Area', 'BoundingBox');
center=round(cat(1,s.Centroid));
luas=cat(1,s.Area);
bbox=cat(1,s.BoundingBox);
numSegmen=numel(luas);
figure;
imshow(mask3)
hold on
plot(center(:,1),center(:,2),'go','markersize',10,'markerfacecolor','m')
facebox=[];
for k=1:numSegmen
box=bbox(k,:);
rwh=box(4)/box(3);
if rwh>1 & rwh<2
facebox=[facebox; box];
end
rectangle('position',[box(1) box(2) box(3) box(4)],'edgecolor','r');
text(center(k,1),center(k,2),num2str(luas(k)),'color','b')
end
figure;
imshow(pic);hold on
rectangle('position',facebox(2,:),'edgecolor','r');
LR=pic(:,:,1);
LG=pic(:,:,2);
LB=pic(:,:,3);

nr=108;
ng=200;
nb=60;
d=47;
maskr=(LR > nr-d) & (LR < nr+d);
% figure;
% imshow(maskr)
maskg=(LG > ng-d) & (LG < ng+d);
% figure;
% imshow(maskg)
maskb=(LB > nb-d) & (LB < nb+d);
% figure;
% imshow(maskb)
mask=maskr & maskg & maskb;
figure;
imshow(mask)
mask2=bwareaopen(mask,5000);
figure;
imshow(mask2)
mask3=imfill(mask2,'hole');
figure;
imshow(mask3)
s=regionprops(mask3, 'Centroid', 'Area', 'BoundingBox');
center=round(cat(1,s.Centroid));
luas=cat(1,s.Area);
bbox=cat(1,s.BoundingBox);
numSegmen=numel(luas);
figure;
imshow(mask3)
hold on
plot(center(:,1),center(:,2),'go','markersize',10,'markerfacecolor','m')
for k=1:numSegmen
box=bbox(k,:);
rectangle('position',[box(1) box(2) box(3) box(4)],'edgecolor','r');
text(center(k,1),center(k,2),num2str(luas(k)),'color','b')
end

figure;
subplot(1,3,1);
imshow(LR);
subplot(1,3,2);
imshow(LG);
subplot(1,3,3);
imshow(LB);
r=LG;
g=LB;
b=LR;
pic2=cat(3,zeros(size(LR)),LG,zeros(size(LB)));

figure;imshow(pic2)

386
269

475

8090

153

clc
136
clear all
397 1045
close all
pic=imread('ma
173
117
war.jpg');
imshow(pic);
% % % untuk
filtering ybr
ybr=rgb2ycbcr(pic);
% figure;imshow(ybr)
y=ybr(:,:,1);
b=ybr(:,:,2);
r=ybr(:,:,3);
figure;imshow(y)
% figure;imsh1show(r)
% % % pengambilan nilai mask
nr=150;
d=5;
mask=(r > nr-d) & (r < nr+d);
% figure;imshow(mask)
% % % membuang sampah bit 0 yang luasnya 500 pixel
mask2=bwareaopen(mask,100);
% figure;imshow(mask2)
% % % membuang sampah bit 1 dalam luas putih
mask3=imfill(mask2,'hole');
figure;imshow(mask3)
% % % memunculkan centroid
s=regionprops(mask3, 'Centroid', 'Area', 'BoundingBox');
center=round(cat(1,s.Centroid));
luas=cat(1,s.Area);
bbox=cat(1,s.BoundingBox);
numSegmen=numel(luas);

figure;
imshow(mask3)
hold on
plot(center(:,1),center(:,2),'go','markersize',10,'markerfacecolor','m')
facebox=[];
for k=1:numSegmen
box=bbox(k,:);
rwh=box(4)/box(3);
if rwh>1 & rwh<2
facebox=[facebox; box];
end
rectangle('position',[box(1) box(2) box(3) box(4)],'edgecolor','r');
text(center(k,1),center(k,2),num2str(luas(k)),'color','b')
end
figure;
imshow(pic);hold on
rectangle('position',facebox(2,:),'edgecolor','r');
LR=pic(:,:,1);
LG=pic(:,:,2);
LB=pic(:,:,3);
nr=108;
ng=200;
nb=60;
d=47;
maskr=(LR > nr-d) & (LR < nr+d);
% figure;
% imshow(maskr)
maskg=(LG > ng-d) & (LG < ng+d);
% figure;
% imshow(maskg)
maskb=(LB > nb-d) & (LB < nb+d);
% figure;
% imshow(maskb)
mask=maskr & maskg & maskb;
figure;
imshow(mask)
mask2=bwareaopen(mask,5000);
figure;
imshow(mask2)
mask3=imfill(mask2,'hole');
figure;
imshow(mask3)
s=regionprops(mask3, 'Centroid', 'Area', 'BoundingBox');
center=round(cat(1,s.Centroid));
luas=cat(1,s.Area);
bbox=cat(1,s.BoundingBox);
numSegmen=numel(luas);
figure;
imshow(mask3)

hold on
plot(center(:,1),center(:,2),'go','markersize',10,'markerfacecolor','m')
for k=1:numSegmen
box=bbox(k,:);
rectangle('position',[box(1) box(2) box(3) box(4)],'edgecolor','r');
text(center(k,1),center(k,2),num2str(luas(k)),'color','b')
end

figure;
subplot(1,3,1);
imshow(LR);
subplot(1,3,2);
imshow(LG);
subplot(1,3,3);
imshow(LB);
r=LG;
g=LB;
b=LR;
pic2=cat(3,zeros(size(LR)),LG,zeros(size(LB)));
figure;imshow(pic2)

7200

19990

129
126

4978

578
155
136

829
571
161 870
784

203
123

1162 3325
159
952 974
150 300
200
2131053
695519
414 2020
3018

335

2535
100

1172

161
123

232
702 470119
386
959 218
600
534
572
117
2062

125

You might also like