This repository has been archived by the owner on Dec 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
endline_detection.m
58 lines (48 loc) · 1.88 KB
/
endline_detection.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
currstate = linestate.START;
v = VideoReader('new_video.mp4');
while (hasFrame(v))
%imname = 'mag2.jpg';
%image1 = imread(imname);
image1 = readFrame(v);
subplot(3,3,1), imshow(image1);
image1_HSV = rgb2hsv(image1);
magenta = (image1_HSV(:,:,1) > 19/24 & image1_HSV(:,:,1) < 23/24) & image1_HSV(:,:,2) > 1/4 & image1_HSV(:,:,3) > 2/4;
n = 5;
filt1 = ones(n,n)/n^2;
filtsize = 5;
sigma = 3;
filt_gauss = fspecial('gaussian', filtsize, sigma);
image1_gauss = imfilter(magenta, filt1);
mag = imfill(image1_gauss, 'holes');
subplot(3,3,2), imshow(mag);
labeledImage = logical(mag);
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
subplot(3,3,3), imshow(coloredLabels);
blobMeasurements = regionprops(labeledImage, 'Area', 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
for k = 1 : numberOfBlobs
blobArea = blobMeasurements(k).Area; % Get area.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid one at a time
%fprintf(1,'#%2d %11.1f %8.1f\n', k, blobArea, blobCentroid);
end
allBlobAreas = [blobMeasurements.Area];
keeperIndexes = find(allBlobAreas > 1500);
binimg = ismember(labeledImage, keeperIndexes);
numofBlobs = numel(keeperIndexes);
if (numofBlobs > 0)
if (currstate == linestate.START)
currstate = linestate.STARTL;
elseif (currstate == linestate.MIDDLE)
currstate = linestate.ENDL;
end
else
if (currstate == linestate.STARTL)
currstate = linestate.MIDDLE;
elseif (currstate == linestate.ENDL)
currstate = linestate.FINISH;
end
end
display(currstate);
subplot(3, 3, 4), imshow(binimg);
pause(0.1);
end