-
Notifications
You must be signed in to change notification settings - Fork 1
/
MoldAlarm2.m
345 lines (257 loc) · 12.3 KB
/
MoldAlarm2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
function varargout = MoldAlarm2(varargin)
% MOLDALARM2 MATLAB code for MoldAlarm2.fig
% MOLDALARM2, by itself, creates a new MOLDALARM2 or raises the existing
% singleton*.
%
% H = MOLDALARM2 returns the handle to a new MOLDALARM2 or the handle to
% the existing singleton*.
%
% MOLDALARM2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MOLDALARM2.M with the given input arguments.
%
% MOLDALARM2('Property','Value',...) creates a new MOLDALARM2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MoldAlarm2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MoldAlarm2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help MoldAlarm2
% Last Modified by GUIDE v2.5 02-Jun-2015 15:09:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MoldAlarm2_OpeningFcn, ...
'gui_OutputFcn', @MoldAlarm2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before MoldAlarm2 is made visible.
function MoldAlarm2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to MoldAlarm2 (see VARARGIN)
% Choose default command line output for MoldAlarm2
handles.output = hObject;
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%stores the filepath of the images
handles.filePath = '';
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MoldAlarm2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MoldAlarm2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function FilePath_Callback(hObject, eventdata, handles)
% hObject handle to FilePath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%read in the given string and save to handles.filePath
filePath = get(hObject,'String');
%TODO: print error if issue
%if the filepath is valid save it and enable thte FirstReferenceImage box
if isdir(filePath)
handles.filePath = filePath;
set(handles.FirstReferenceImage, 'Enable', 'on');
set(handles.Start, 'Enable', 'on');
set(handles.StartingImage, 'Enable', 'on');
set(handles.NumOfContainer, 'Enable','on');
set(handles.ImFormat, 'Enable','on');
end
% Update handles structure
guidata(hObject, handles);
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
% Hints: get(hObject,'String') returns contents of FilePath as text
% str2double(get(hObject,'String')) returns contents of FilePath as a double
% --- Executes during object creation, after setting all properties.
function FilePath_CreateFcn(hObject, eventdata, handles)
% hObject handle to FilePath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set(handles.Start, 'Enable', 'off');
%find axes;
axes1 = handles.axes1;
imageCounterStr = get(handles.StartingImage, 'String');
set(handles.ImageCounter, 'String', imageCounterStr);
guidata(hObject, handles);
%get reference to tif Files;
filePath = get(handles.FilePath, 'String');
imageFormat = get(handles.ImFormat, 'String');
tifFiles = dir(strcat(filePath,'/*.',imageFormat)); %Annette: I think this
% needs to be included in the loop as well, not just be here otherwise it
% doesn't update it
%get referenceImage and rectangle for future cropping(cropRect)
refImageNum = uint8(str2double(get(handles.FirstReferenceImage,'String')));
containerNum = str2double(get(handles.NumOfContainer,'String'));
[referenceImage, cropRect] = GetReferenceImage(filePath, refImageNum, containerNum, tifFiles);
refImages = [];
for i = 1:containerNum
[a(i),b(i)] = size(referenceImage{i});
end
amax = max(a);
bmax = max(b);
%
for i = 1:containerNum
[a,b] = size(referenceImage{i});
if (a<amax)
fill = zeros((amax-a),b);
images{i} = [referenceImage{i};fill];
else
images{i} = referenceImage{i};
end
end
for i = 1:containerNum
refImages = [refImages,images{i}];
end
imshow(refImages);
%image to start checking for mold at
checkFrame = uint8(str2double(get(handles.StartingImage,'String')));
%every 40 seconds check to see if there is an unchecked frame
mold = false;
%while mold has not been found check frames for mold
while ~mold
tifFiles = dir(strcat(filePath,'/*.',imageFormat));
pause(2);
%if there are files that have not been checked
if checkFrame < length(tifFiles) +1
%TODO: inc img counter with every loop
imageCounterStr = get(handles.ImageCounter, 'String');
imageNumber = str2double(imageCounterStr);
%incriment image number
imageNumber = imageNumber + 1;
%convert back to string and update gui
newStr = num2str(imageNumber);
set(handles.ImageCounter, 'String', newStr);
guidata(hObject, handles);
'analyze:'
tifFiles(checkFrame)
%aquire the cropped image to check for mold
imageToCheck = GetImage(filePath, tifFiles(checkFrame), cropRect);
%check the frame for mold
mold = CheckFrameForMold(imageToCheck, referenceImage);
checkFrame = checkFrame + 1;
%wait 40 seconds only if there are no unchecked frames
else
pause(40);
end
end
tifFiles(checkFrame-1).name %print out name
%mold found if here
SoundAlarm();
%update starting image to lastCheckedFrame in case of false positive
set(handles.StartingImage, 'String', num2str(checkFrame));
% Update handles structure
guidata(hObject, handles);
set(handles.Start, 'Enable', 'on');
%TODO if there is an unchecked frame check for mold
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
function FirstReferenceImage_Callback(hObject, eventdata, handles, axes1)
% hObject handle to FirstReferenceImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of FirstReferenceImage as text
% str2double(get(hObject,'String')) returns contents of FirstReferenceImage as a double
% --- Executes during object creation, after setting all properties.
function FirstReferenceImage_CreateFcn(hObject, eventdata, handles)
% hObject handle to FirstReferenceImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function ImFormat_Callback(hObject, eventdata, handles)
% hObject handle to ImFormat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of ImFormat as text
% str2double(get(hObject,'String')) returns contents of ImFormat as a double
% --- Executes during object creation, after setting all properties.
function ImFormat_CreateFcn(hObject, eventdata, handles)
% hObject handle to ImFormat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function StartingImage_Callback(hObject, eventdata, handles)
% hObject handle to StartingImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imageCounterStr = get(handles.StartingImage, 'String');
set(handles.ImageCounter, 'String', imageCounterStr);
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of StartingImage as text
% str2double(get(hObject,'String')) returns contents of StartingImage as a double
% --- Executes during object creation, after setting all properties.
function StartingImage_CreateFcn(hObject, eventdata, handles)
% hObject handle to StartingImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function NumOfContainer_Callback(hObject, eventdata, handles)
% hObject handle to NumOfContainer (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of NumOfContainer as text
% str2double(get(hObject,'String')) returns contents of NumOfContainer as a double
% --- Executes during object creation, after setting all properties.
function NumOfContainer_CreateFcn(hObject, eventdata, handles)
% hObject handle to NumOfContainer (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Continue.
function Continue_Callback(hObject, eventdata, handles)
% --- Executes on button press in Close.
function Close_Callback(hObject, eventdata, handles)
% hObject handle to Close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%quit program
clear all;
close all;