218 lines
7.9 KiB
Matlab
218 lines
7.9 KiB
Matlab
function varargout = flowcytometergui(varargin)
|
|
% FLOWCYTOMETERGUI MATLAB code for flowcytometergui.fig
|
|
% FLOWCYTOMETERGUI, by itself, creates a new FLOWCYTOMETERGUI or raises the existing
|
|
% singleton*.
|
|
%
|
|
% H = FLOWCYTOMETERGUI returns the handle to a new FLOWCYTOMETERGUI or the handle to
|
|
% the existing singleton*.
|
|
%
|
|
% FLOWCYTOMETERGUI('CALLBACK',hObject,eventData,handles,...) calls the local
|
|
% function named CALLBACK in FLOWCYTOMETERGUI.M with the given input arguments.
|
|
%
|
|
% FLOWCYTOMETERGUI('Property','Value',...) creates a new FLOWCYTOMETERGUI or raises the
|
|
% existing singleton*. Starting from the left, property value pairs are
|
|
% applied to the GUI before flowcytometergui_OpeningFcn gets called. An
|
|
% unrecognized property name or invalid value makes property application
|
|
% stop. All inputs are passed to flowcytometergui_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 flowcytometergui
|
|
|
|
% Last Modified by GUIDE v2.5 09-Jul-2018 11:27:06
|
|
|
|
% Begin initialization code - DO NOT EDIT
|
|
gui_Singleton = 1;
|
|
gui_State = struct('gui_Name', mfilename, ...
|
|
'gui_Singleton', gui_Singleton, ...
|
|
'gui_OpeningFcn', @flowcytometergui_OpeningFcn, ...
|
|
'gui_OutputFcn', @flowcytometergui_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 flowcytometergui is made visible.
|
|
function flowcytometergui_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 flowcytometergui (see VARARGIN)
|
|
|
|
% Choose default command line output for flowcytometergui
|
|
handles.output = hObject;
|
|
s = serial('COM12');
|
|
set(s,'BaudRate',57600); set(s,'Terminator','#');
|
|
set(s,'Timeout',30); % s.RecordName = 'CytoSerialTxnLog.txt';
|
|
fopen(s); % record(s);
|
|
handles.s = s;
|
|
|
|
msg=strcat(datestr(clock,'yyyy-mm-dd-HHMM'),'m',datestr(clock,'ss'),'s');
|
|
fid = fopen(strcat(msg,'.txt'),'w');
|
|
handles.fid = fid;
|
|
if (fid == -1)
|
|
disp('could not open logging file. You probably need to change working directory to the one where the MATLAB file is located.');
|
|
return;
|
|
end
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
% Start cam
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
tic
|
|
fprintf(fid, '\r\nStarting camera...');
|
|
% choose which webcam (winvideo-1) and which mode (YUY2_176x144)
|
|
%vid = videoinput('winvideo', 1, 'RGB32_744x480');
|
|
vid = videoinput('winvideo', 2, 'RGB24_640x480');
|
|
% Configure the object for manual trigger mode.
|
|
triggerconfig(vid, 'manual');
|
|
% only capture one frame per trigger, we are not recording a video
|
|
vid.FramesPerTrigger = 1;
|
|
% output would image in RGB color space
|
|
vid.ReturnedColorspace = 'rgb';
|
|
% tell matlab to start the webcam on user request, not automatically
|
|
triggerconfig(vid, 'manual');
|
|
% we need this to know the image height and width
|
|
vidRes = get(vid, 'VideoResolution');
|
|
% image width
|
|
imWidth = vidRes(1);
|
|
% image height
|
|
imHeight = vidRes(2);
|
|
% number of bands of our image (should be 3 because it's RGB)
|
|
nBands = get(vid, 'NumberOfBands');
|
|
% create an empty image container and show it on axPreview
|
|
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview);
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
% do auto white balance
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
src = getselectedsource(vid);
|
|
% src.BalanceWhiteAuto = 'Continuous';
|
|
% begin the webcam preview
|
|
currzpos = 0;
|
|
preview(vid, hImage);
|
|
% expose the objects so we can handle them in other functions
|
|
handles.vid = vid;
|
|
handles.src = src;
|
|
handles.currz = currzpos;
|
|
guidata(hObject,handles);
|
|
%start(vid);
|
|
drawnow;
|
|
|
|
% % set and display the exposure
|
|
% src.ExposureTime = 360;
|
|
%set(handles.expDisp,'string', src.ExposureTime );
|
|
Time_to_init_cam = toc
|
|
|
|
% Update handles structure
|
|
guidata(hObject, handles);
|
|
|
|
% UIWAIT makes flowcytometergui wait for user response (see UIRESUME)
|
|
% uiwait(handles.figure1)
|
|
|
|
% --- Outputs from this function are returned to the command line.
|
|
function varargout = flowcytometergui_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;
|
|
|
|
|
|
% --- Executes on button press in autofocus.
|
|
function autofocus_Callback(hObject, eventdata, handles)
|
|
% hObject handle to autofocus (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
s = handles.s; vid = handles.vid; currzpos = handles.currz;
|
|
[~, ~, ~] = focusstack_1(s,vid,currzpos);pause(2)
|
|
|
|
|
|
|
|
|
|
% --- Executes on button press in moveleft.
|
|
function moveleft_Callback(hObject, eventdata, handles)
|
|
% hObject handle to moveleft (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
s = handles.s; fprintf(s,'A')
|
|
|
|
|
|
% --- Executes on button press in moveright.
|
|
function moveright_Callback(hObject, eventdata, handles)
|
|
% hObject handle to moveright (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
s = handles.s; fprintf(s,'D')
|
|
|
|
|
|
% --- Executes on button press in snapshot.
|
|
function snapshot_Callback(hObject, eventdata, handles)
|
|
% hObject handle to snapshot (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
vid = handles.vid;
|
|
snapshot = getsnapshot(vid);
|
|
imwrite(snapshot,'snap.jpg')
|
|
|
|
function figure1_DeleteFcn(hObject, eventdata, handles)
|
|
% hObject handle to figure1 (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
|
|
if ~isempty(instrfind)
|
|
fclose(instrfind);
|
|
delete(instrfind);
|
|
end
|
|
|
|
try
|
|
fid=handles.fid; fclose(fid);
|
|
vid = handles.vid; stoppreview(vid); delete(vid);
|
|
catch
|
|
clear all;
|
|
clc;
|
|
end
|
|
|
|
%s=handles.s; fclose(s); delete(s);
|
|
disp('Killed all before exiting');
|
|
|
|
|
|
% --- Executes on button press in startvid.
|
|
function startvid_Callback(hObject, eventdata, handles)
|
|
% hObject handle to startvid (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
vid = handles.vid;
|
|
vid_trigger = 1; handles.vid_trigger = vid_trigger;
|
|
for x=1:1000
|
|
snap = getsnapshot(vid)
|
|
imwrite(strcat('Image_',num2str(x),'.jpg'),snap)
|
|
end
|
|
% aviObject = VideoWriter('newfile.avi','Motion JPEG AVI'); handles.aviObject = aviObject;
|
|
% open(aviObject);
|
|
% while(vid_trigger == 1)
|
|
% snap = getsnapshot(vid);
|
|
% writeVideo(aviObject,snap);
|
|
% end
|
|
|
|
% --- Executes on button press in stopvid.
|
|
function stopvid_Callback(hObject, eventdata, handles)
|
|
% hObject handle to stopvid (see GCBO)
|
|
% eventdata reserved - to be defined in a future version of MATLAB
|
|
% handles structure with handles and user data (see GUIDATA)
|
|
aviObject = handles.aviObject;
|
|
handles.vid_trigger = 0;
|
|
close(aviObject);
|