-
Notifications
You must be signed in to change notification settings - Fork 1
/
getObjectInfo.m
64 lines (50 loc) · 2.48 KB
/
getObjectInfo.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
59
60
61
62
63
64
function [centralColor, colorRange, validPix] = getObjectInfo(img)
%TODO: mvoe this to gui and remove the figure call
%create new window so image is not placed on gui
figure;
%here the user should select a single object
singleObjectImg = imcrop(img);
%imshow(singleObjectImg);
% the value of 2 will cause the script to exit the crop/filter loop
% the value of 1 indicates that the auto default color offset or the
% initial crop was unacceptable
acceptableImg = 3;
%colorOffset greatly alters results. It is increadibly important
%that this be set to a good value
colorOffset = 0; %20;
singleObjectImgBackup = singleObjectImg;
%continue untill good result if found
while acceptableImg ~= 2
%if the last result was bad allow the user to add an offset
if acceptableImg == 1
%reset the img to its pre-croped state
singleObjectImg = singleObjectImgBackup;
prompt = 'Pick an offset less than 255 and greater than -255 to alter the color sensitivity by (Positive numbers increase sensitivity to dark pixels and negative numbers increase sensitivity to light pixels)';
%userInput is a temp variable to facilitate the setting of
%colorOffset
userInput = inputdlg(prompt);
colorOffset = str2double(userInput{1,1});
end
%select the color to search for
colorSample = imcrop(singleObjectImg);
centralColor = L_Mean(colorSample) - colorOffset;
colorRange = L_Range(colorSample) / 2;
%convert all invalid pixels to white and sum all valid pixels
validPix = 0;
for k = 1:size(singleObjectImg,1)
for u = 1:size(singleObjectImg,2)
if singleObjectImg(k,u) < (centralColor - colorRange) || singleObjectImg(k,u) > (centralColor + colorRange)
singleObjectImg(k,u) = intmax('uint8');
else
validPix = validPix + 1;
end
end
end
% display image and ask user is result is acceptable
imshow(singleObjectImg);
acceptableImg = menu('Would you like to re-crop and alter the accepted color range?', 'Yes', 'No');
%remove calibration image to reduce clutter
%TODO: move display to gui will make this command useless
%TODO: perm remove close command if no issues
%close;
end