-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightbulbDetect.m
51 lines (41 loc) · 1.34 KB
/
lightbulbDetect.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
function results = lightbulbDetect(im)
%Image Processing Function
%
% IM - Input image.
% RESULTS - A scalar structure with the processing results.
%
%--------------------------------------------------------------------------
% Auto-generated by imageBatchProcessor App.
%
% When used by the App, this function will be called for every input image
% file automatically. IM contains the input image as a matrix. RESULTS is a
% scalar structure containing the results of this processing function.
%
%--------------------------------------------------------------------------
% Replace the sample below with your code----------------------------------
imgray = im2gray(im);
% X = imadjust(imgray);
% Threshold image - manual threshold
BW = imgray > 2.499000e+02;
% Open mask with default
radius = 6;
decomposition = 0;
se = strel('disk', radius, decomposition);
BW = imopen(BW, se);
% Close mask with default
radius = 6;
decomposition = 0;
se = strel('disk', radius, decomposition);
BW = imclose(BW, se);
% Create masked image.
results.maskedImage = imgray;
% results.maskedImage(~BW) = 0;
st = regionprops(BW, 'Area');
totalArea = 0;
for k = 1 : length(st)
totalArea = totalArea + st(k).Area;
end
% results.area = totalArea;
results.proportion = totalArea / numel(imgray);
%--------------------------------------------------------------------------
end