Skip to content

Commit 54a8654

Browse files
Merge pull request #19 from DIDSR/newsystem
Excellent work adapting the code for new hardware types (prior stage, USB 3 camera) and communications.
2 parents a233e98 + ea9bb01 commit 54a8654

31 files changed

+954
-376
lines changed

Administrator_Input_Screen.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Administrator_Input_Screen_OpeningFcn(hObject, eventdata, handles, vara
5151
handles.myData.wsi_files = [];
5252
handles.myData.graphics = struct;
5353

54-
addpath('gui_graphics', 'icc_profiles', 'tasks');
54+
addpath('gui_graphics', 'icc_profiles', 'tasks','stages/Prior','stages/Ludl');
5555

5656
handles.myData.sourcedir = [cd, '\'];
5757

@@ -215,7 +215,6 @@ function ExtractROIsButtonPressed(hObject, eventdata, handles) %#ok<DEFNU>
215215
handles.myData.tasks_out{i} = taskinfo;
216216

217217
end
218-
219218
guidata(handles.Administrator_Input_Screen, handles);
220219
close(wtb);
221220

@@ -334,7 +333,7 @@ function align_eye_cam(handles) %#ok<*INUSD>
334333
try
335334

336335
settings = handles.myData.settings;
337-
handles.cam = camera_open(settings.cam_format);
336+
handles.cam = camera_open(settings.cam_kind,settings.cam_format);
338337
handles.cam_figure = camera_preview(handles.cam, settings);
339338
pos_eye = [0,0];
340339
pos_cam = [0,0];
@@ -528,7 +527,6 @@ function ModeSelectionPopUpMenu_Callback(hObject, eventdata, handles) %#ok<DEFNU
528527
set(hObject_configure_camera, ...
529528
'Enable', 'on', ...
530529
'String', 'Configure Camera');
531-
532530
handles.myData.stage = stage_get_pos(handles.myData.stage); %#ok<NASGU>
533531
if handles.myData.stage.Pos == 0
534532
return
@@ -545,7 +543,7 @@ function ModeSelectionPopUpMenu_Callback(hObject, eventdata, handles) %#ok<DEFNU
545543

546544
% Determine and derive additional camera settings
547545
if handles.myData.yesno_micro==1
548-
cam=camera_open();
546+
cam=camera_open(settings.cam_kind,settings.cam_format);
549547
if cam == 0
550548
return
551549
end

Camera_stage_review.fig

23.2 KB
Binary file not shown.

Camera_stage_review.m

Lines changed: 105 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
% Edit the above text to modify the response to help Camera_stage_review
2424

25-
% Last Modified by GUIDE v2.5 29-Jun-2015 15:59:11
25+
% Last Modified by GUIDE v2.5 25-Apr-2016 16:52:17
2626

2727
% Begin initialization code - DO NOT EDIT
2828
gui_Singleton = 1;
@@ -54,24 +54,18 @@ function Camera_stage_review_OpeningFcn(hObject, eventdata, handles, varargin)
5454
% varargin command line arguments to Camera_stage_review (see VARARGIN)
5555

5656
% Choose default command line output for Camera_stage_review
57-
settings.mag_cam=1;
58-
settings.cam_pixel_size=6.9;
59-
settings.cam_format=char('RGB24_1024x768');
60-
settings.reticleID=char('KR-871');
61-
settings.cam_mask = reticle_make_mask(...
62-
settings.reticleID,...
63-
settings.cam_pixel_size/settings.mag_cam,...
64-
[0,0]);
65-
handles.cam=camera_open(settings.cam_format);
66-
camera_image_display(handles,handles.cam,settings);
67-
handles.imagenumber = 1;
68-
handles.position_flag_y=0;
69-
handles.position_flag_x=0;
70-
handles.stageflag=0;
71-
handles.firsttime = 1;
72-
handles.output=hObject;
73-
% Update handles structure
74-
guidata(hObject, handles);
57+
desc = {'\bfWelcome'...
58+
,'Please choose the camera format'};
59+
welcome_page(handles,desc );
60+
set(handles.Take_image,'Enable','off');
61+
handles.imagenumber = 1;
62+
handles.position_flag_y=0;
63+
handles.position_flag_x=0;
64+
handles.stageflag=0;
65+
handles.firsttime = 1;
66+
handles.output=hObject;
67+
% Update handles structure
68+
guidata(hObject, handles);
7569
end
7670

7771
% UIWAIT makes Camera_stage_review wait for user response (see UIRESUME)
@@ -266,15 +260,17 @@ function Choose_System_Callback(hObject, eventdata, handles)
266260
mode_index = get(handles.Choose_System, 'Value');
267261
mode_desc = deblank(modes{mode_index});
268262
handles.mode_desc = mode_desc;
269-
handles.stage=stage_open(mode_desc);
270-
handles.stage = stage_set_origin(handles.stage);
271-
handles.stage=stage_move(handles.stage,[50000,50000]);
272-
set(handles.Get_position,'Enable','on');
273-
set(handles.current_position_x,'Enable','on');
274-
set(handles.current_position_y,'Enable','on');
275-
set(handles.target_position_x,'Enable','on');
276-
set(handles.target_position_y,'Enable','on');
277-
handles.stageflag=1;
263+
if mode_index ~= 1
264+
addpath('stages/Prior','stages/Ludl');
265+
handles.stage=stage_open(mode_desc);
266+
handles.stage = stage_set_origin(handles.stage);
267+
set(handles.Get_position,'Enable','on');
268+
set(handles.current_position_x,'Enable','on');
269+
set(handles.current_position_y,'Enable','on');
270+
set(handles.target_position_x,'Enable','on');
271+
set(handles.target_position_y,'Enable','on');
272+
handles.stageflag=1;
273+
end
278274
guidata(hObject, handles);
279275
end
280276

@@ -299,7 +295,9 @@ function camera_image_display(handles,vid, settings)
299295
imWidth = vidRes(1);
300296
imHeight = vidRes(2);
301297
set(handles.ImageAxes,'Units', 'pixels')
302-
set(handles.ImageAxes,'Position', [5, 5, imWidth, imHeight]);
298+
startWidth = floor((1252-imWidth)/2);
299+
startHeight = floor((1051-imHeight)/2);
300+
set(handles.ImageAxes,'Position', [startWidth, startHeight, imWidth, imHeight]);
303301
hImage = image( uint8(zeros(imHeight, imWidth, nBands) ),'parent', handles.ImageAxes);
304302
set(hImage, 'UserData', settings)
305303
setappdata(hImage,'UpdatePreviewWindowFcn',@preview_image_with_cross);
@@ -347,5 +345,83 @@ function preview_image_with_cross(obj, event, himage)
347345
end
348346

349347

348+
% --- Choose camera format
349+
function Choose_Camera_Callback(hObject, eventdata, handles)
350+
try
351+
settings.mag_cam=1;
352+
settings.cam_pixel_size=6.9;
353+
modes=get(handles.Choose_Camera,'String');
354+
mode_index = get(handles.Choose_Camera, 'Value');
355+
cam_mode = deblank(modes{mode_index});
356+
if mode_index ~= 1
357+
handles.cam_mode = cam_mode;
358+
if strcmp(handles.cam_mode(1:3),'USB')
359+
settings.cam_kind = char('USB');
360+
settings.cam_format=char('F7_RGB_1224x1024_Mode1');
361+
else
362+
settings.cam_kind = char('Firewire');
363+
settings.cam_format=char('RGB24_1024x768');
364+
end
365+
settings.reticleID=char('KR-871');
366+
settings.cam_mask = reticle_make_mask(...
367+
settings.reticleID,...
368+
settings.cam_pixel_size/settings.mag_cam,...
369+
[0,0]);
370+
handles.cam=camera_open(settings.cam_kind,settings.cam_format);
371+
camera_image_display(handles,handles.cam,settings);
372+
set(handles.Take_image,'Enable','on');
373+
else
374+
desc = {'\bfWelcome'...
375+
,'Please choose the camera format'};
376+
welcome_page(handles, desc);
377+
set(handles.Take_image,'Enable','off');
378+
end
379+
guidata(hObject, handles);
380+
catch ME
381+
error_show(ME)
382+
end
350383

384+
end
385+
386+
% --- Executes during object creation, after setting all properties.
387+
function Choose_Camera_CreateFcn(hObject, eventdata, handles)
388+
% hObject handle to Choose_Camera (see GCBO)
389+
% eventdata reserved - to be defined in a future version of MATLAB
390+
% handles empty - handles not created until after all CreateFcns called
351391

392+
% Hint: popupmenu controls usually have a white background on Windows.
393+
% See ISPC and COMPUTER.
394+
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
395+
set(hObject,'BackgroundColor','white');
396+
end
397+
end
398+
function welcome_page(handles, desc)
399+
try
400+
% This function creates an image with text to be displayed to the user
401+
set(handles.ImageAxes,...
402+
'Units', 'pixels',...
403+
'Position', [1, 1, 1252, 1051],...
404+
'Visible', 'off');
405+
position = int64(get(handles.ImageAxes, 'Position'));
406+
temp_image = ones([position(4), position(3), 3])-.5;
407+
i=(1:double(position(3)))/double(position(3));
408+
for j=1:position(4)
409+
temp_image(j,:,1) = i;
410+
end
411+
img_object = image(temp_image, 'Parent', handles.ImageAxes); %#ok<NASGU>
412+
axis image
413+
set(handles.ImageAxes, 'Visible', 'off');
414+
fontsize=0.05;
415+
text('Parent', handles.ImageAxes,...
416+
'FontName', 'Times',...
417+
'FontUnits', 'normalized',...
418+
'FontSize', fontsize,...
419+
'HorizontalAlignment', 'center',...
420+
'VerticalAlignment', 'middle',...
421+
'Position', [position(3)/2, position(4)/2],...
422+
'String', desc);
423+
424+
catch ME
425+
error_show(ME)
426+
end
427+
end

GUI.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin)
180180
% The mode_index and the filename for the test are extracted from the
181181
% cell structure varargin. varargin stores the input arguments for the
182182
% whole Matlab application
183-
addpath('gui_graphics', 'icc_profiles', 'tasks');
183+
addpath('gui_graphics', 'icc_profiles', 'tasks','stages/Prior','stages/Ludl');
184184
handles_old = varargin{1};
185185
handles.Administrator_Input_Screen = handles_old.Administrator_Input_Screen;
186186
myData = handles_old.myData;
@@ -198,22 +198,21 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin)
198198
handles.reticle = 1;
199199
settings = myData.settings;
200200
guidata(handles.GUI, handles)
201-
202201
% Open communications to camera and begin preview
203202
% Open communications to stage
204203
switch myData.mode_desc
205204
case 'MicroRT'
206205
if myData.yesno_micro==1
207206
% Open communications to camera and begin preview
208-
handles.cam=camera_open();
207+
handles.cam=camera_open(settings.cam_kind,settings.cam_format);
209208
handles.cam_figure = ...
210209
camera_preview(handles.cam, settings);
211210
% To close:
212211
% delete handles.cam
213212
% close(cam_figure)
214213

215214
% Open communications to stage
216-
handles.myData.stage = stage_open(handles.myData.stage.label);
215+
handles.myData.stage = stage_open(handles.myData.stage.label);
217216
% To close:
218217
% delete(handles.stage)
219218
% If communications with the stage cannot be established,
@@ -780,7 +779,7 @@ function Fast_Register_Button_Callback(hObject, eventdata, handles) %#ok<DEFNU>
780779
[roi_h, roi_w] = size(roi_image);
781780

782781
% Get the stage position
783-
handles.myData.stage = stage_get_pos(handles.myData.stage,myData.stage.handle);
782+
handles.myData.stage = stage_get_pos(handles.myData.stage,myData.stage.handle);
784783
stage_current = int64(handles.myData.stage.Pos);
785784

786785
% Cross correlate the stage and wsi images
@@ -809,7 +808,6 @@ function Fast_Register_Button_Callback(hObject, eventdata, handles) %#ok<DEFNU>
809808
stage_new = stage_current + offset_roi;
810809
offset_stage = int64(myData.settings.offset_stage);
811810
stage_new = stage_new - offset_stage;
812-
813811
handles.myData.stage = stage_move(handles.myData.stage,stage_new, handles.myData.stage.handle);
814812
catch ME
815813
error_show(ME)
@@ -1074,12 +1072,12 @@ function Best_Register_Button_Callback(hObject, eventdata, handles)
10741072
[roi_h, roi_w] = size(roi_image);
10751073

10761074
% Get the stage position and snap a picture: cam_image
1077-
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
1075+
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
10781076
stage_current = int64(handles.myData.stage.Pos);
10791077
offset_stage = int64(myData.settings.offset_stage);
10801078
stage_new = stage_current + offset_stage;
10811079
handles.myData.stage = stage_move(handles.myData.stage,stage_new,handles.myData.stage.handle);
1082-
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
1080+
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
10831081
stage_current = int64(handles.myData.stage.Pos);
10841082
cam_image = camera_take_image(handles.cam);
10851083

@@ -1133,7 +1131,6 @@ function Best_Register_Button_Callback(hObject, eventdata, handles)
11331131
stage_new = stage_current + offset_roi;
11341132
offset_stage = int64(myData.settings.offset_stage);
11351133
stage_new = stage_new - offset_stage;
1136-
11371134
handles.myData.stage = stage_move(handles.myData.stage,stage_new, handles.myData.stage.handle);
11381135
catch ME
11391136
error_show(ME)

Load_Input_File.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ function Load_Input_File(handles)
182182
end
183183
tline = fgets(fid);
184184
[setting_name, setting_value]=strread(tline, '%s %s', 'delimiter', '=');
185+
name = 'cam_kind';
186+
if strcmp(strtrim(setting_name),name)==1
187+
settings.cam_kind=char(setting_value);
188+
else
189+
io_error(name);
190+
end
191+
tline = fgets(fid);
192+
[setting_name, setting_value]=strread(tline, '%s %s', 'delimiter', '=');
185193
name = 'cam_format';
186194
if strcmp(strtrim(setting_name),name)==1
187195
settings.cam_format=char(setting_value);

SerialPortSetUp.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
success = 0;
55

6-
for i=1:1:12
6+
for i=1:1:20
77
Ports{i}=strcat('COM',num2str(i));
88
end
99

Stage_Allighment.m

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ function Stage_Allighment_OpeningFcn(hObject, eventdata, handles, varargin) %#ok
3939
reg_flag = current.reg_flag; %#ok<NASGU>
4040
slot_i = current.slot_i;
4141
wsi_info = myData.wsi_files{slot_i};
42-
42+
addpath('stages/Prior','stages/Ludl');
4343
% Initiate the camera preview window
4444
% handles.cam = camera object
4545
if myData.yesno_micro==1
46-
handles.cam = camera_open(settings.cam_format);
46+
handles.cam = camera_open(settings.cam_kind,settings.cam_format);
4747
handles.cam_figure = camera_preview(handles.cam, settings);
48-
myData.stage = stage_set_origin(myData.stage);
49-
myData.stage=stage_move(myData.stage,[50000,50000]);
50-
48+
myData.stage = stage_set_origin(myData.stage);
5149
end
5250

5351
% Set the default size of the window and the axes
@@ -664,7 +662,7 @@ function take_stage1_Callback(hObject, eventdata, handles) %#ok<DEFNU>
664662

665663
if handles.current.load_stage_data(1) == 1
666664
display('automatically navigate to position 1')
667-
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(1,:));
665+
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(1,:));
668666
set(handles.take_stage1,'String','Take Stage Position 1');
669667
handles.current.load_stage_data(1) = 2;
670668
guidata(handles.Stage_Allighment,handles);
@@ -704,8 +702,7 @@ function take_stage2_Callback(hObject, eventdata, handles) %#ok<DEFNU>
704702

705703
if handles.current.load_stage_data(2) == 1
706704
display('automatically navigate to position 2')
707-
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(2,:));
708-
705+
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(2,:));
709706
set(handles.take_stage2,'String','Take Stage Position 2');
710707
handles.current.load_stage_data(2) = 2;
711708
guidata(handles.Stage_Allighment,handles);
@@ -743,8 +740,7 @@ function take_stage3_Callback(hObject, eventdata, handles) %#ok<DEFNU>
743740

744741
if handles.current.load_stage_data(3) == 1
745742
display('automatically navigate to position 3')
746-
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(3,:));
747-
743+
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(3,:));
748744
set(handles.take_stage3,'String','Take Stage Position 3');
749745
handles.current.load_stage_data(3) = 2;
750746
guidata(handles.Stage_Allighment,handles);

camera_open.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
function cam=camera_open(cam_format)
2+
function cam=camera_open(cam_kind,cam_format)
33
try
44

55
% imaqtool: launches an interactive GUI to allow you to explore,
@@ -25,12 +25,16 @@
2525
% delete any currently running (stale) video inputs
2626
objects = imaqfind;
2727
delete(objects);
28-
28+
if strcmp( cam_kind,'USB')
29+
cam_adaptor = 'pointgrey';
30+
elseif strcmp( cam_kind,'Firewire')
31+
cam_adaptor = 'dcam';
32+
end
2933
% Create the video object to communicate with the camera
3034
if exist('cam_format','var')
31-
cam = videoinput('dcam',1,cam_format) %#ok<NOPRT>
35+
cam = videoinput(cam_adaptor,1,cam_format) %#ok<NOPRT>
3236
else
33-
cam = videoinput('dcam',1) %#ok<NOPRT>
37+
cam = videoinput(cam_adaptor,1) %#ok<NOPRT>
3438
end
3539
imaqhwinfo(cam)
3640
cam.Tag = 'Microscope Camera Object';
@@ -57,7 +61,9 @@
5761
% Set value of a video source object property.
5862
cam_src = getselectedsource(cam);
5963
cam_src.Tag = 'Microscope Camera Source';
60-
64+
if strcmp( cam_kind,'USB')
65+
cam_src.WhiteBalanceRBMode = 'Off';
66+
end
6167
catch ME
6268
error_show(ME)
6369
end

0 commit comments

Comments
 (0)