📄 fluoseq.m
字号:
lambdactrl(lambda_par.port, 'open'); case 'stop sequence' % stop timed image acquisition % stop running timer if (isa(image_par.h_fluoseq, 'timer')) stop(image_par.h_fluoseq); end set(fig_handle.h_button(4), 'Callback', 'set(gcf, ''Tag'', ''stop'')'); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); enable_buttons(fig_handle.h_button, file_par, image_par); case {'snap image', 'start focus'} % setup snap or focus % disable buttons and open shutter % this will execute lambda 10-2 command callback upon completion % remainder of image acquisition will be completed here set(fig_handle.h_button, 'Enable', 'off'); set(fig_handle.h_button(4), 'Enable', 'on'); set(h_fig, 'WindowButtonMotionFcn', ''); set(h_fig, 'Tag', control_command); % initiate acquisition directly or via Lambda 10-2 callback if (strcmp(image_par.filter_name, lambda_par.name)) lambdactrl(lambda_par.port, 'open'); else fluoseq(h_fig, 'acquire image'); end case 'acquire image' % callback following lambda 10-2 command echo % perform single or repetitive acquisition if specified image_cmd = get(h_fig, 'Tag'); switch (image_cmd) case 'snap image' % acquire single image [image_data, file_par] = get_single_image(h_fig, fig_handle, image_par, file_par, lambda_par, 'normal'); set(h_fig, 'Tag', figure_tag); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); enable_buttons(fig_handle.h_button, file_par, image_par); case 'start focus' % continuously acquire until stop is detected % call PVCAMFOCUS to obtain images % reset image parameters following focus %focus_par = pvcamfocus(h_fig, 'start focus', focus_par); %if (istype(focus_par{1}.h_image, 'image')) % set(fig_handle.h_axes(1), 'UserData', focus_par{1}.h_image); %end % old focus code if (~isempty(image_par.h_cam)) [param_value, param_type, param_access, param_range] = pvcamgetvalue(image_par.h_cam, 'PARAM_SPDTAB_INDEX'); pvcamsetvalue(image_par.h_cam, 'PARAM_SPDTAB_INDEX', max(param_range)); end while (~strcmp(get(h_fig, 'Tag'), 'stop')) [image_data, file_par] = get_single_image(h_fig, fig_handle, image_par, file_par, lambda_par, 'focus'); if (isempty(image_data) || ~isnumeric(image_data)) break end end % end old focus code % close LAMBDA 10-2 shutter and reset other parameters set(h_fig, 'Tag', figure_tag); if (strcmp(image_par.filter_name, lambda_par.name)) lambdactrl(lambda_par.port, 'close'); end set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); enable_buttons(fig_handle.h_button, file_par, image_par); case 'start sequence' % acquire single image for timed sequence [image_data, file_par] = get_single_image(h_fig, fig_handle, image_par, file_par, lambda_par, 'normal'); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); % update display of pixel intensity if (isempty(image_data) || ~isnumeric(image_data)) fluoseq(h_fig, 'stop sequence'); else image_time = etime(file_par.acq_time, file_par.start_time) / 60; if (all(size(image_par.image_mask) == size(image_data))) pixel_value = sum(sum(double(image_par.image_mask) .* ... double(image_data))) / sum(sum(double(image_par.image_mask))); else pixel_value = mean(mean(double(image_data))); end h_line = get(fig_handle.h_axes(3), 'UserData'); if (istype(h_line, 'line')) set(h_line, 'XData', [get(h_line, 'XData') image_time]); set(h_line, 'YData', [get(h_line, 'YData') pixel_value]); else axes(fig_handle.h_axes(3)); h_line = line(image_time, pixel_value); set(fig_handle.h_axes(3), 'FontName', 'helvetica', 'FontSize', 8, 'Tag', 'graph', 'UserData', h_line); end end end case 'select region' % select region for intensity calculation axes(fig_handle.h_axes(1)); h_image = get(fig_handle.h_axes(1), 'UserData'); if (istype(h_image, 'image')) image_par.image_mask = roipoly; set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); fluoseq(h_fig, 'show region'); end case 'show region' % display region for intensity calculation axes(fig_handle.h_axes(1)); h_image = get(fig_handle.h_axes(1), 'UserData'); if (istype(h_image, 'image')) image_data = get(h_image, 'UserData'); if (all(size(image_par.image_mask) == size(image_data))) image_mask = image_data .* (1 - feval(class(image_data), image_par.image_mask)); disp_single_image(image_mask, fig_handle, image_par, file_par); set(h_image, 'UserData', image_data); end end case 'clear region' % clear region for intensity calculation image_par.image_mask = []; h_image = get(fig_handle.h_axes(1), 'UserData'); if (istype(h_image, 'image')) image_data = get(h_image, 'UserData'); if (~isempty(image_data)) disp_single_image(image_data, fig_handle, image_par, file_par); end end set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); case 'reset graph' % reset time and graph display file_par.image_count = 0; file_par.start_time = clock; delete(get(fig_handle.h_axes(3), 'Children')); set(fig_handle.h_axes(3), 'UserData', []); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); case 'parameters' % define sequence parameters % setup editing of acquisition parameters for GUISTRUCT field_name = {'file_path', 'file_prefix', 'expose_time', 'image_time', 'image_total', 'bin_full'}; field_lower = [-Inf -Inf 0 0 1 1]; field_upper = Inf * ones(size(field_lower)); field_title = {'File path', 'File prefix', 'Exposure (ms)', 'Cycle (sec)', 'Image count', 'Pixel bins'}; field_format = {'%s', '%s', '%d', '%d', '%d', '%d'}; field_multi = {'string', 'string', 'scalar', 'scalar', 'scalar', 'vector'}; % obtain parameters from FILE_PAR and IMAGE_PAR to edit edit_struct = []; for i = 1 : length(field_name) if (isfield(file_par, field_name{i})) edit_struct.(field_name{i}) = file_par.(field_name{i}); elseif (isfield(image_par, field_name{i})) edit_struct.(field_name{i}) = image_par.(field_name{i}); end end [edit_struct, edit_flag] = guistruct('Acquisition Parameters', ... edit_struct, field_lower, field_upper, field_title, field_format, field_multi); % modify parameters if selected if (isstruct(edit_struct) && edit_flag) field_name = fieldnames(edit_struct); for i = 1 : length(field_name) if (isfield(file_par, field_name{i})) file_par.(field_name{i}) = edit_struct.(field_name{i}); elseif (isfield(image_par, field_name{i})) image_par.(field_name{i}) = edit_struct.(field_name{i}); end end % update ROI structure in case binning changed % recalculate focus parameters image_par.roi_full = create_roi_struct(image_par.roi_coord, image_par.bin_full); %focus_par = pvcamfocus(fig_handle.h_axes(1), 'initialize', ... % image_par.h_cam, image_par.expose_time, image_par.roi_full); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); end case 'camera setup' % edit PVCAM parameters pvcam_setpar = fieldnames(pvcam_set); [new_value, edit_flag] = pvcameditor(image_par.h_cam, pvcam_setpar); if (edit_flag) for i = 1 : length(pvcam_setpar) pvcam_set.(pvcam_setpar{i}) = pvcamgetvalue(image_par.h_cam, pvcam_setpar{i}); end set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); end case 'roi setup' % create/remove ROI set(h_fig, 'WindowButtonMotionFcn', ''); [x1, y1, x2, y2, roi_flag] = guirbsel(h_fig, fig_handle.h_axes(1)); if (roi_flag) image_par.roi_coord = round([x1, y1, x2, y2]); else image_par.roi_coord = [1 1 image_par.image_size]; end% ans_cell = inputdlg('Enter ROI coords', 'ROI setup', 1, {num2str(image_par.roi_coord)});% if (isempty(ans_cell))% return% else% image_par.roi_coord = str2num(ans_cell{1});% end image_par.roi_full = create_roi_struct(image_par.roi_coord, image_par.bin_full); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); set(h_fig, 'WindowButtonMotionFcn', motion_fcn); case 'open file' % save images to TIF file % generate file name % filename example: scm07feb03a.tif file_date = lower([datestr(datenum(date),'dd') datestr(datenum(date),'mmmyy')]); for file_char = double('a') : double('z') file_name = [file_par.file_prefix file_date char(file_char) '.tif']; if (~exist(fullfile(file_par.file_path, file_name), 'file')) break end end % have user select file name old_dir = pwd; if (exist(file_par.file_path, 'dir')) cd(file_par.file_path); [file_name, file_path] = uiputfile(file_name, 'Save Images to File'); cd(old_dir); else [file_name, file_path] = uiputfile(file_name, 'Save Images to File'); warning('MATLAB:fluoseq', '%s not found, saving file to %s', file_par.file_path, old_dir) end if ((file_name(1) ~= 0) && (file_path(1) ~= 0)) % reset clock and filename display % reset pixel intensity graph % enable appropriate buttons file_par.file_name = file_name; file_par.file_path = file_path; set(h_fig, 'Name', file_par.file_name); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); enable_buttons(fig_handle.h_button, file_par, image_par); fluoseq(h_fig, 'reset graph'); end case 'close file' % stop saving images to TIF file file_par.file_name = ''; enable_buttons(fig_handle.h_button, file_par, image_par); set(h_fig, 'Name', 'No file open'); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); case 'colormap' % select a new colormap palette_list = {'autumn', 'bone', 'cool', 'copper', ... 'gray', 'hot', 'hsv', 'invgray', ... 'invhsv', 'jet', 'jetshift', 'lucifer', ... 'pink', 'spectrum', 'spring', 'summer', 'winter'}; [new_value, select_flag] = guilist('Palette', palette_list, func2str(image_par.color_map)); if (select_flag) image_par.color_map = str2func(new_value); disp_colorbar(h_fig, fig_handle.h_axes(2), image_par.color_map); set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par}); end case 'finish' % close figure window, camera and filter wheel if (isempty(image_par.h_cam)) pvcamclose(0); else pvcamclose(image_par.h_cam); end lambdactrl(lambda_par.port, 'clear'); if (isa(image_par.h_lambda, 'timer')) stop(image_par.h_lambda);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -