-
Notifications
You must be signed in to change notification settings - Fork 0
/
doFinalImage.m
39 lines (35 loc) · 971 Bytes
/
doFinalImage.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function [I,objectImage] = doFinalImage(I,bw)
CC = bwconncomp(bw);
S = regionprops(CC, 'Area', 'Perimeter');
maxIndex = 1;
maxArea = 0;
for x=1:numel(S)
value = S(x);
value = value.Area;
if value>maxArea
maxIndex = x;
maxArea = value;
end
end
bw = zeros(size(I(:,:,1)));
bw(CC.PixelIdxList{maxIndex}) = 1;
SE = strel('disk',2,6);
aux = imerode(bw,SE);
perimeter = xor(aux,bw);
[nr,nc]= size(I(:,:,1));
objectImage = uint8(zeros(size(I)));
pixels = CC.PixelIdxList{maxIndex};
for num = 1:numel(pixels)
pixel = pixels(num,1);
j = ceil(pixel/nr);
i = ceil(mod(pixel,nr));
objectImage(i,j,1) = I(i,j,1);
objectImage(i,j,2) = I(i,j,2);
objectImage(i,j,3) = I(i,j,3);
if perimeter(i,j) == 1
I(i,j,1) = 255;
I(i,j,2) = 0;
I(i,j,3) = 0;
end
end
end