Skip to content

Commit

Permalink
Merge pull request #19 from DIDSR/newsystem
Browse files Browse the repository at this point in the history
Excellent work adapting the code for new hardware types (prior stage, USB 3 camera) and communications.
  • Loading branch information
brandon-gallas committed May 11, 2016
2 parents a233e98 + ea9bb01 commit 54a8654
Show file tree
Hide file tree
Showing 31 changed files with 954 additions and 376 deletions.
8 changes: 3 additions & 5 deletions Administrator_Input_Screen.m
Expand Up @@ -51,7 +51,7 @@ function Administrator_Input_Screen_OpeningFcn(hObject, eventdata, handles, vara
handles.myData.wsi_files = [];
handles.myData.graphics = struct;

addpath('gui_graphics', 'icc_profiles', 'tasks');
addpath('gui_graphics', 'icc_profiles', 'tasks','stages/Prior','stages/Ludl');

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

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

end

guidata(handles.Administrator_Input_Screen, handles);
close(wtb);

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

settings = handles.myData.settings;
handles.cam = camera_open(settings.cam_format);
handles.cam = camera_open(settings.cam_kind,settings.cam_format);
handles.cam_figure = camera_preview(handles.cam, settings);
pos_eye = [0,0];
pos_cam = [0,0];
Expand Down Expand Up @@ -528,7 +527,6 @@ function ModeSelectionPopUpMenu_Callback(hObject, eventdata, handles) %#ok<DEFNU
set(hObject_configure_camera, ...
'Enable', 'on', ...
'String', 'Configure Camera');

handles.myData.stage = stage_get_pos(handles.myData.stage); %#ok<NASGU>
if handles.myData.stage.Pos == 0
return
Expand All @@ -545,7 +543,7 @@ function ModeSelectionPopUpMenu_Callback(hObject, eventdata, handles) %#ok<DEFNU

% Determine and derive additional camera settings
if handles.myData.yesno_micro==1
cam=camera_open();
cam=camera_open(settings.cam_kind,settings.cam_format);
if cam == 0
return
end
Expand Down
Binary file modified Camera_stage_review.fig
Binary file not shown.
134 changes: 105 additions & 29 deletions Camera_stage_review.m
Expand Up @@ -22,7 +22,7 @@

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

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

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

% Choose default command line output for Camera_stage_review
settings.mag_cam=1;
settings.cam_pixel_size=6.9;
settings.cam_format=char('RGB24_1024x768');
settings.reticleID=char('KR-871');
settings.cam_mask = reticle_make_mask(...
settings.reticleID,...
settings.cam_pixel_size/settings.mag_cam,...
[0,0]);
handles.cam=camera_open(settings.cam_format);
camera_image_display(handles,handles.cam,settings);
handles.imagenumber = 1;
handles.position_flag_y=0;
handles.position_flag_x=0;
handles.stageflag=0;
handles.firsttime = 1;
handles.output=hObject;
% Update handles structure
guidata(hObject, handles);
desc = {'\bfWelcome'...
,'Please choose the camera format'};
welcome_page(handles,desc );
set(handles.Take_image,'Enable','off');
handles.imagenumber = 1;
handles.position_flag_y=0;
handles.position_flag_x=0;
handles.stageflag=0;
handles.firsttime = 1;
handles.output=hObject;
% Update handles structure
guidata(hObject, handles);
end

% UIWAIT makes Camera_stage_review wait for user response (see UIRESUME)
Expand Down Expand Up @@ -266,15 +260,17 @@ function Choose_System_Callback(hObject, eventdata, handles)
mode_index = get(handles.Choose_System, 'Value');
mode_desc = deblank(modes{mode_index});
handles.mode_desc = mode_desc;
handles.stage=stage_open(mode_desc);
handles.stage = stage_set_origin(handles.stage);
handles.stage=stage_move(handles.stage,[50000,50000]);
set(handles.Get_position,'Enable','on');
set(handles.current_position_x,'Enable','on');
set(handles.current_position_y,'Enable','on');
set(handles.target_position_x,'Enable','on');
set(handles.target_position_y,'Enable','on');
handles.stageflag=1;
if mode_index ~= 1
addpath('stages/Prior','stages/Ludl');
handles.stage=stage_open(mode_desc);
handles.stage = stage_set_origin(handles.stage);
set(handles.Get_position,'Enable','on');
set(handles.current_position_x,'Enable','on');
set(handles.current_position_y,'Enable','on');
set(handles.target_position_x,'Enable','on');
set(handles.target_position_y,'Enable','on');
handles.stageflag=1;
end
guidata(hObject, handles);
end

Expand All @@ -299,7 +295,9 @@ function camera_image_display(handles,vid, settings)
imWidth = vidRes(1);
imHeight = vidRes(2);
set(handles.ImageAxes,'Units', 'pixels')
set(handles.ImageAxes,'Position', [5, 5, imWidth, imHeight]);
startWidth = floor((1252-imWidth)/2);
startHeight = floor((1051-imHeight)/2);
set(handles.ImageAxes,'Position', [startWidth, startHeight, imWidth, imHeight]);
hImage = image( uint8(zeros(imHeight, imWidth, nBands) ),'parent', handles.ImageAxes);
set(hImage, 'UserData', settings)
setappdata(hImage,'UpdatePreviewWindowFcn',@preview_image_with_cross);
Expand Down Expand Up @@ -347,5 +345,83 @@ function preview_image_with_cross(obj, event, himage)
end


% --- Choose camera format
function Choose_Camera_Callback(hObject, eventdata, handles)
try
settings.mag_cam=1;
settings.cam_pixel_size=6.9;
modes=get(handles.Choose_Camera,'String');
mode_index = get(handles.Choose_Camera, 'Value');
cam_mode = deblank(modes{mode_index});
if mode_index ~= 1
handles.cam_mode = cam_mode;
if strcmp(handles.cam_mode(1:3),'USB')
settings.cam_kind = char('USB');
settings.cam_format=char('F7_RGB_1224x1024_Mode1');
else
settings.cam_kind = char('Firewire');
settings.cam_format=char('RGB24_1024x768');
end
settings.reticleID=char('KR-871');
settings.cam_mask = reticle_make_mask(...
settings.reticleID,...
settings.cam_pixel_size/settings.mag_cam,...
[0,0]);
handles.cam=camera_open(settings.cam_kind,settings.cam_format);
camera_image_display(handles,handles.cam,settings);
set(handles.Take_image,'Enable','on');
else
desc = {'\bfWelcome'...
,'Please choose the camera format'};
welcome_page(handles, desc);
set(handles.Take_image,'Enable','off');
end
guidata(hObject, handles);
catch ME
error_show(ME)
end

end

% --- Executes during object creation, after setting all properties.
function Choose_Camera_CreateFcn(hObject, eventdata, handles)
% hObject handle to Choose_Camera (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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
end
function welcome_page(handles, desc)
try
% This function creates an image with text to be displayed to the user
set(handles.ImageAxes,...
'Units', 'pixels',...
'Position', [1, 1, 1252, 1051],...
'Visible', 'off');
position = int64(get(handles.ImageAxes, 'Position'));
temp_image = ones([position(4), position(3), 3])-.5;
i=(1:double(position(3)))/double(position(3));
for j=1:position(4)
temp_image(j,:,1) = i;
end
img_object = image(temp_image, 'Parent', handles.ImageAxes); %#ok<NASGU>
axis image
set(handles.ImageAxes, 'Visible', 'off');
fontsize=0.05;
text('Parent', handles.ImageAxes,...
'FontName', 'Times',...
'FontUnits', 'normalized',...
'FontSize', fontsize,...
'HorizontalAlignment', 'center',...
'VerticalAlignment', 'middle',...
'Position', [position(3)/2, position(4)/2],...
'String', desc);

catch ME
error_show(ME)
end
end
15 changes: 6 additions & 9 deletions GUI.m
Expand Up @@ -180,7 +180,7 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin)
% The mode_index and the filename for the test are extracted from the
% cell structure varargin. varargin stores the input arguments for the
% whole Matlab application
addpath('gui_graphics', 'icc_profiles', 'tasks');
addpath('gui_graphics', 'icc_profiles', 'tasks','stages/Prior','stages/Ludl');
handles_old = varargin{1};
handles.Administrator_Input_Screen = handles_old.Administrator_Input_Screen;
myData = handles_old.myData;
Expand All @@ -198,22 +198,21 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin)
handles.reticle = 1;
settings = myData.settings;
guidata(handles.GUI, handles)

% Open communications to camera and begin preview
% Open communications to stage
switch myData.mode_desc
case 'MicroRT'
if myData.yesno_micro==1
% Open communications to camera and begin preview
handles.cam=camera_open();
handles.cam=camera_open(settings.cam_kind,settings.cam_format);
handles.cam_figure = ...
camera_preview(handles.cam, settings);
% To close:
% delete handles.cam
% close(cam_figure)

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

% Get the stage position
handles.myData.stage = stage_get_pos(handles.myData.stage,myData.stage.handle);
handles.myData.stage = stage_get_pos(handles.myData.stage,myData.stage.handle);
stage_current = int64(handles.myData.stage.Pos);

% Cross correlate the stage and wsi images
Expand Down Expand Up @@ -809,7 +808,6 @@ function Fast_Register_Button_Callback(hObject, eventdata, handles) %#ok<DEFNU>
stage_new = stage_current + offset_roi;
offset_stage = int64(myData.settings.offset_stage);
stage_new = stage_new - offset_stage;

handles.myData.stage = stage_move(handles.myData.stage,stage_new, handles.myData.stage.handle);
catch ME
error_show(ME)
Expand Down Expand Up @@ -1074,12 +1072,12 @@ function Best_Register_Button_Callback(hObject, eventdata, handles)
[roi_h, roi_w] = size(roi_image);

% Get the stage position and snap a picture: cam_image
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
stage_current = int64(handles.myData.stage.Pos);
offset_stage = int64(myData.settings.offset_stage);
stage_new = stage_current + offset_stage;
handles.myData.stage = stage_move(handles.myData.stage,stage_new,handles.myData.stage.handle);
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle);
stage_current = int64(handles.myData.stage.Pos);
cam_image = camera_take_image(handles.cam);

Expand Down Expand Up @@ -1133,7 +1131,6 @@ function Best_Register_Button_Callback(hObject, eventdata, handles)
stage_new = stage_current + offset_roi;
offset_stage = int64(myData.settings.offset_stage);
stage_new = stage_new - offset_stage;

handles.myData.stage = stage_move(handles.myData.stage,stage_new, handles.myData.stage.handle);
catch ME
error_show(ME)
Expand Down
8 changes: 8 additions & 0 deletions Load_Input_File.m
Expand Up @@ -182,6 +182,14 @@ function Load_Input_File(handles)
end
tline = fgets(fid);
[setting_name, setting_value]=strread(tline, '%s %s', 'delimiter', '=');
name = 'cam_kind';
if strcmp(strtrim(setting_name),name)==1
settings.cam_kind=char(setting_value);
else
io_error(name);
end
tline = fgets(fid);
[setting_name, setting_value]=strread(tline, '%s %s', 'delimiter', '=');
name = 'cam_format';
if strcmp(strtrim(setting_name),name)==1
settings.cam_format=char(setting_value);
Expand Down
2 changes: 1 addition & 1 deletion SerialPortSetUp.m
Expand Up @@ -3,7 +3,7 @@

success = 0;

for i=1:1:12
for i=1:1:20
Ports{i}=strcat('COM',num2str(i));
end

Expand Down
16 changes: 6 additions & 10 deletions Stage_Allighment.m
Expand Up @@ -39,15 +39,13 @@ function Stage_Allighment_OpeningFcn(hObject, eventdata, handles, varargin) %#ok
reg_flag = current.reg_flag; %#ok<NASGU>
slot_i = current.slot_i;
wsi_info = myData.wsi_files{slot_i};

addpath('stages/Prior','stages/Ludl');
% Initiate the camera preview window
% handles.cam = camera object
if myData.yesno_micro==1
handles.cam = camera_open(settings.cam_format);
handles.cam = camera_open(settings.cam_kind,settings.cam_format);
handles.cam_figure = camera_preview(handles.cam, settings);
myData.stage = stage_set_origin(myData.stage);
myData.stage=stage_move(myData.stage,[50000,50000]);

myData.stage = stage_set_origin(myData.stage);
end

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

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

if handles.current.load_stage_data(2) == 1
display('automatically navigate to position 2')
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(2,:));

handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(2,:));
set(handles.take_stage2,'String','Take Stage Position 2');
handles.current.load_stage_data(2) = 2;
guidata(handles.Stage_Allighment,handles);
Expand Down Expand Up @@ -743,8 +740,7 @@ function take_stage3_Callback(hObject, eventdata, handles) %#ok<DEFNU>

if handles.current.load_stage_data(3) == 1
display('automatically navigate to position 3')
handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(3,:));

handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(3,:));
set(handles.take_stage3,'String','Take Stage Position 3');
handles.current.load_stage_data(3) = 2;
guidata(handles.Stage_Allighment,handles);
Expand Down
16 changes: 11 additions & 5 deletions camera_open.m
@@ -1,5 +1,5 @@

function cam=camera_open(cam_format)
function cam=camera_open(cam_kind,cam_format)
try

% imaqtool: launches an interactive GUI to allow you to explore,
Expand All @@ -25,12 +25,16 @@
% delete any currently running (stale) video inputs
objects = imaqfind;
delete(objects);

if strcmp( cam_kind,'USB')
cam_adaptor = 'pointgrey';
elseif strcmp( cam_kind,'Firewire')
cam_adaptor = 'dcam';
end
% Create the video object to communicate with the camera
if exist('cam_format','var')
cam = videoinput('dcam',1,cam_format) %#ok<NOPRT>
cam = videoinput(cam_adaptor,1,cam_format) %#ok<NOPRT>
else
cam = videoinput('dcam',1) %#ok<NOPRT>
cam = videoinput(cam_adaptor,1) %#ok<NOPRT>
end
imaqhwinfo(cam)
cam.Tag = 'Microscope Camera Object';
Expand All @@ -57,7 +61,9 @@
% Set value of a video source object property.
cam_src = getselectedsource(cam);
cam_src.Tag = 'Microscope Camera Source';

if strcmp( cam_kind,'USB')
cam_src.WhiteBalanceRBMode = 'Off';
end
catch ME
error_show(ME)
end
Expand Down

0 comments on commit 54a8654

Please sign in to comment.