📄 fluoseq.m
字号:
function [] = fluoseq(varargin)% FLUOSEQ - perform non-ratiometric imaging during drug application%% FLUOSEQ acquires a sequence of non-ratiometric images during drug% application. A GUI interface is provided to control the acquisition.%% If no PVCAM device is found, the program will operate in a demo mode% where images will be generated randomly.% 3/31/03 SCM% Files required:% ---------------% PVCAM*.DLL and PVCAM*.M% LAMBDACTRL.M and LAMBDAREAD.M% ROIPARSE.M% UINT8/UINT16 DLLs% UTILITY package% Image processing toolbox (for ROIPOLY command)% Files needed for compiling PVCAM DLLs:% --------------------------------------% PVCAM*.C & PVCAM*.H (for source code, compiled under MATLAB 6.5)% PVCAM32.LIB (PVCAM library)% PVCAM32_MANUAL.PDF (reference for parameter names)% validate argumentsif (nargin == 0) control_command = 'initialize';elseif (nargin ~= 2) warning('MATLAB:fluoseq', 'type ''help fluoseq'' for syntax'); returnelseif (isa(varargin{1}, 'serial') && isvalid(varargin{1}) && ... isfield(varargin{2}, 'Type') && isfield(varargin{2}, 'Data')) % Lambda 10-2 callback lambda_port = varargin{1}; lambda_event = varargin{2}; h_fig = gcf; control_command = 'lambda callback';elseif (~istype(varargin{1}, 'figure')) warning('MATLAB:fluoseq', 'H_FIG must be a valid figure window'); returnelseif (~ischar(varargin{2}) || isempty(varargin{2})) warning('MATLAB:fluoseq', 'CMD must be a string'); returnelse h_fig = varargin{1}; control_command = lower(varargin{2});end% obtain UserData from HFIG% check for valid contentsif (~strcmp(control_command, 'initialize')) user_data = get(h_fig, 'UserData'); if (iscell(user_data) && (length(user_data) >= 7)) [fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par] = deal(user_data{1 : 7}); else warning('MATLAB:fluoseq', 'cannot find valid UserData cell array in H_FIG'); return endend% figure window parameters% used by Lambda 10-2 interfacemotion_fcn = 'fluoseq(gcbo, ''pointer value'')';figure_tag = 'fluoseq';switch (control_command) case 'initialize' % open figure window % camera parameters %pvcam_getpar = {'PARAM_BIT_DEPTH', 'PARAM_CHIP_NAME', 'PARAM_FRAME_CAPABLE', 'PARAM_MPP_CAPABLE', ... % 'PARAM_PAR_SIZE', 'PARAM_SER_SIZE', 'PARAM_PREMASK', 'PARAM_TEMP'}; %pvcam_getvalue = {12, 'demo mode', 0, 'mpp mode unknown', ... % 512, 512, 0, 0}; pvcam_getpar = {'PARAM_BIT_DEPTH', 'PARAM_CHIP_NAME', ... 'PARAM_PAR_SIZE', 'PARAM_SER_SIZE', 'PARAM_PREMASK', 'PARAM_TEMP'}; pvcam_getvalue = {12, 'demo mode', 512, 512, 0, 0}; pvcam_setpar = {'PARAM_CLEAR_MODE', 'PARAM_CLEAR_CYCLES', 'PARAM_GAIN_INDEX', ... 'PARAM_PMODE', 'PARAM_SHTR_OPEN_MODE', 'PARAM_SHTR_CLOSE_DELAY', 'PARAM_SHTR_OPEN_DELAY', ... 'PARAM_SPDTAB_INDEX', 'PARAM_TEMP_SETPOINT'}; %pvcam_setvalue = {'clear pre-sequence', 2, 3, ... % 'normal parallel clocking', 'open shutter pre-sequence', 10, 5, 2, -2500}; pvcam_setvalue = {'clear pre-sequence', 2, 2, ... 'normal parallel clocking', 'open shutter pre-sequence', 10, 5, 0, 2000}; % Lambda 10-2 parameters % LAMBDA PARAMS WILL BE EDITABLE IN FUTURE VERSIONS! lambda_par = cell2struct({1, [1 0], [5 2], 5, 'lambda 10-2', @fluoseq, []}, ... {'wheel', 'filter', 'speed', 'wait', 'name', 'fcn', 'port'}, 2); % initialize camera % operate in demo mode & use camera defaults if error h_cam = pvcamopen(0); if (isempty(h_cam)) disp('FLUOSEQ: could not open camera, using DEMO mode'); pvcamclose(0); pvcam_get = cell2struct(pvcam_getvalue, pvcam_getpar, 2); pvcam_set = cell2struct(pvcam_setvalue, pvcam_setpar, 2); else % read camera parameters disp('FLUOSEQ: camera detected'); for i = 1 : length(pvcam_getpar) pvcam_get.(pvcam_getpar{i}) = pvcamgetvalue(h_cam, pvcam_getpar{i}); end % set camera parameters for i = 1 : length(pvcam_setpar) if (pvcamsetvalue(h_cam, pvcam_setpar{i}, pvcam_setvalue{i})) pvcam_set.(pvcam_setpar{i}) = pvcamgetvalue(h_cam, pvcam_setpar{i}); else warning('MATLAB:fluoseq', 'could not set %s, using current value', pvcam_setpar{i}); pvcam_set.(pvcam_setpar{i}) = pvcamgetvalue(h_cam, pvcam_setpar{i}); end end end % create image parameters structure % create default ROI from camera parameters w/o binning image_size = [pvcam_get.PARAM_SER_SIZE pvcam_get.PARAM_PAR_SIZE]; roi_coord = [1 1 image_size]; field_name = {'h_cam', 'h_lambda', 'h_fluoseq', 'filter_name', 'roi_full', 'roi_coord', 'image_mask', ... 'image_size', 'bit_depth', 'expose_time', 'image_time', 'image_total', 'bin_full', 'color_map'}; field_value = {h_cam, [], [], 'none', create_roi_struct(roi_coord, [1 1]), roi_coord, [], ... image_size, pvcam_get.PARAM_BIT_DEPTH, 10, 30, 20, [1 1], @jet}; image_par = cell2struct(field_value, field_name, 2); % create file parameters structure field_name = {'file_path', 'file_name', 'file_prefix', 'image_count', 'start_time', 'acq_time'}; field_value = {'c:\scm\cells', '', 'scm', 0, clock, clock}; file_par = cell2struct(field_value, field_name, 2); % open image window delete(findobj('Type', 'figure', 'Tag', figure_tag)); h_fig = make_image_win(figure_tag); % obtain figure handles from HFIG % initialize colormap % disable all buttons to start % these will be enabled during Lambda 10-2 callback fig_handle = get(h_fig, 'UserData'); disp_colorbar(h_fig, fig_handle.h_axes(2), image_par.color_map); % obtain focus parameters from PVCAMFOCUS % save structures in HFIG UserData %focus_par = pvcamfocus(fig_handle.h_axes(1), 'initialize', h_cam, image_par.expose_time, image_par.roi_full); focus_par = []; set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); fluoseq(h_fig, 'lambda detect'); case 'pointer value' % obtain value under mouse pointer h_image = get(fig_handle.h_axes(1), 'UserData'); if (istype(h_image, 'image')) image_data = get(h_image, 'UserData'); [ptr_pos, ptr_flag] = ptrpos(h_fig, fig_handle.h_axes(1), 'image'); if ((ptr_pos(1) >= 1) && (ptr_pos(1) <= size(image_data, 2)) && ... (ptr_pos(2) >= 1) && (ptr_pos(2) <= size(image_data, 1)) && ptr_flag) ptr_val = double(image_data(ptr_pos(2), ptr_pos(1))); elapsed_time = datestr(datenum(file_par.acq_time) - datenum(file_par.start_time), 13); ptr_text = sprintf('Image: %d Elapsed Time: %s Intensity at (%d, %d) = %g', file_par.image_count, ... elapsed_time, ptr_pos(1) + image_par.roi_coord(1) - 2, ptr_pos(2) + image_par.roi_coord(2) - 2, ptr_val); set(fig_handle.h_text(1), 'String', ptr_text); end end case 'lambda detect' % initialize filter wheel % set timer and Lambda 10-2 callbacks to determine if filter wheel present % presence of Lambda 10-2 is independent of DEMO mode % buttons will be enabled during either callback if (~isa(image_par.h_lambda, 'timer')) image_par.h_lambda = timer(... 'ExecutionMode', 'fixedrate', ... 'BusyMode', 'drop'); end set(image_par.h_lambda, ... 'TasksToExecute', 1, ... 'StartDelay', lambda_par.wait, ... 'Period', lambda_par.wait, ... 'StartFcn', 'fluoseq(gcf, ''lambda setup'')', ... 'TimerFcn', 'fluoseq(gcf, ''no lambda 10-2'')', ... 'StopFcn', '', ... 'ErrorFcn', 'fluoseq(gcf, ''no lambda 10-2'')'); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); set(h_fig, 'Tag', control_command); lambda_par.port = lambdactrl('initialize'); lambdactrl(lambda_par.port, 'callback', lambda_par.fcn); lambdactrl(lambda_par.port, 'wheel', lambda_par.wheel); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); start(image_par.h_lambda); case 'lambda setup' % setup filter and speed lambdactrl(lambda_par.port, 'batch', [0 0], lambda_par.filter, lambda_par.speed); case 'lambda callback' % check echo from serial port % check echo from serial port unless initializing % echo should not be completed until command is finished % proceed with acquisition if bytes read back err_msg = lambdaread(lambda_port, lambda_event); if (strcmp(get(h_fig, 'Tag'), 'lambda detect')) if (isa(image_par.h_lambda, 'timer')) stop(image_par.h_lambda); end image_par.filter_name = lambda_par.name; set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); set(h_fig, 'Tag', figure_tag); enable_buttons(fig_handle.h_button, file_par, image_par); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); disp('FLUOSEQ: Lambda 10-2 detected'); elseif (~isempty(err_msg)) warning('MATLAB:fluoseq', 'Lambda 10-2 error: %s', err_msg); set(h_fig, 'Tag', figure_tag); enable_buttons(fig_handle.h_button, file_par, image_par); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); elseif (~strcmp(get(h_fig, 'Tag'), figure_tag)) fluoseq(h_fig, 'acquire image'); end case 'no lambda 10-2' % configure the program to run w/o Lambda 10-2 stop(image_par.h_lambda); set(h_fig, 'Tag', figure_tag); disp(sprintf('FLUOSEQ: Lambda 10-2 not found after %d sec', round(lambda_par.wait))); yes_no = questdlg('Reset the Lambda 10-2 and try again?', 'Lambda 10-2 not found', 'yes', 'no', 'no'); if (strcmp(yes_no, 'yes')) fluoseq(h_fig, 'lambda detect'); else enable_buttons(fig_handle.h_button, file_par, image_par); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); end case 'start sequence' % setup timed image acquisition % setup timer if (isa(image_par.h_fluoseq, 'timer')) stop(image_par.h_fluoseq); else image_par.h_fluoseq = timer(... 'ExecutionMode', 'fixedrate', ... 'BusyMode', 'drop'); end set(image_par.h_fluoseq, ... 'TasksToExecute', image_par.image_total, ... 'StartDelay', 0, ... 'Period', image_par.image_time, ... 'StartFcn', '', ... 'StopFcn', 'fluoseq(gcf, ''stop sequence'')', ... 'ErrorFcn', 'fluoseq(gcf, ''stop sequence'')'); if (strcmp(image_par.filter_name, lambda_par.name)) set(image_par.h_fluoseq, 'TimerFcn', 'set(gcf, ''Tag'', ''start sequence''); fluoseq(gcf, ''open shutter'')'); else set(image_par.h_fluoseq, 'TimerFcn', 'set(gcf, ''Tag'', ''start sequence''); fluoseq(gcf, ''acquire image'')'); end % change stop button callback to stop timer % start timer set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); set(fig_handle.h_button(4), 'Callback', 'fluoseq(gcf, ''stop sequence'')'); set(fig_handle.h_button, 'Enable', 'off'); set(fig_handle.h_button(4), 'Enable', 'on'); set(h_fig, 'WindowButtonMotionFcn', ''); start(image_par.h_fluoseq); case 'open shutter' % open shutter for timed sequences
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -