📄 anatseq.m
字号:
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:anatseq', '%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 % enable appropriate buttons file_par.file_name = file_name; file_par.file_path = file_path; file_par.image_count = 0; file_par.start_time = clock; 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); 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); delete(image_par.h_lambda); end delete(h_fig); otherwise % invalid command warning('MATLAB:anatseq', 'command ''%s'' not recognized', control_command);endreturnfunction [image_data, new_file] = get_single_image(h_fig, fig_handle, image_par, file_par, lambda_par, focus_flag)% initialize outputsnew_file = file_par;% acquire image if device available% otherwise generate random image% wait for exposure time to pass in DEMO mode% prevents Lambda 10-2 confusion during byte read from serial portnew_file.acq_time = clock;if (isempty(image_par.h_cam)) roi_size = diff(reshape(image_par.roi_coord, 2, 2), 1, 2)' + 1; image_data = uint16((2 ^ image_par.bit_depth - 1) * rand(1, prod(floor(roi_size ./ image_par.bin_full)))); start_time = clock; while (1000 * etime(clock, start_time) < (image_par.expose_time + 100)) endelse image_data = pvcamacq(image_par.h_cam, 1, image_par.roi_full, image_par.expose_time, 'timed');end% close shutter if Lambda 10-2 presentif (strcmp(image_par.filter_name, 'lambda 10-2') && ~strcmp(focus_flag, 'focus')) set(h_fig, 'Tag', 'close'); lambdactrl(lambda_par.port, 'close');end% convert image stream into 2-D arrayif (~isempty(image_data) && isnumeric(image_data)) image_data = roiparse(image_data, image_par.roi_full); disp_single_image(image_data, fig_handle, image_par, new_file); % save image data if file is open if (~isempty(new_file.file_name) && ~strcmp(focus_flag, 'focus')) new_file.image_count = new_file.image_count + 1; imwrite(image_data, fullfile(new_file.file_path, new_file.file_name), ... 'tif', 'WriteMode', 'append', 'Description', datestr(new_file.acq_time)); endendreturnfunction [] = disp_single_image(image_data, fig_handle, image_par, file_par)% obtain image axes and texth_axes = fig_handle.h_axes(1);if (istype(h_axes, 'axes')) axes(h_axes); h_image = get(h_axes, 'UserData');else warning('MATLAB:anatseq', 'unable to find image axes'); returnendh_text = fig_handle.h_text;if (~istype(h_text, 'uicontrol')) warning('MATLAB:anatseq', 'unable to find text label'); returnend% display image% shift image down to 8 bits before displayif (isa(image_data, 'uint8')) image_disp = image_data;else image_disp = uint8(image_data / feval(class(image_data), max(1, 2 ^ (image_par.bit_depth - 8))));endif (istype(h_image, 'image')) set(h_image, 'CData', image_disp, 'UserData', image_data); set(h_axes, 'XLim', [1 size(image_disp, 2)], 'YLim', [1 size(image_disp, 1)]);else h_image = image(image_disp); set(h_image, 'EraseMode', 'none', 'UserData', image_data); set(h_axes, 'XDir', 'reverse', ... 'XTick', [], ... 'YDir', 'normal', ... 'YTick', [], ... 'Tag', 'image', ... 'UserData', h_image);end% update text label with times, counts, etc.elapsed_time = datestr(datenum(file_par.acq_time) - datenum(file_par.start_time), 13);text_string = sprintf('Image: %d Elapsed Time: %s Min: %d Max: %d Size: %d x %d', ... file_par.image_count, elapsed_time, double(min(min(image_data))), double(max(max(image_data))), ... floor(image_par.image_size ./ image_par.bin_full));set(h_text, 'String', text_string);drawnow;returnfunction [] = disp_colorbar(h_fig, h_axes, color_func)% obtain colorbar axesif (istype(h_axes, 'axes')) axes(h_axes); h_image = get(h_axes, 'UserData');else warning('MATLAB:anatseq', 'unable to find colorbar axes'); returnend% obtain colormapcolor_map = feval(color_func, 256);set(h_fig, 'Colormap', color_map);display_map = uint8(255 * reshape(color_map, [size(color_map, 1) 1 size(color_map, 2)]));% display colorbarif (istype(h_image, 'image')) set(h_image, 'CData', display_map);else h_image = image(display_map); set(h_image, 'EraseMode', 'none', ... 'ButtonDownFcn', 'anatseq(gcf, ''colormap'')'); set(h_axes, 'XDir', 'normal', ... 'XTick', [], ... 'YDir', 'normal', ... 'YTick', [], ... 'Tag', 'colorbar', ... 'UserData', h_image);endreturnfunction [] = enable_buttons(h_button, file_par, image_par)% enable all buttons except stopset(h_button, 'Enable', 'on');set(h_button(3), 'Enable', 'off');% camera setup buttonif (isscalar(image_par.h_cam)) set(h_button(5), 'Enable', 'on');else set(h_button(5), 'Enable', 'off');end% open/close file buttonif (isempty(file_par.file_name)) set(h_button(7), 'Enable', 'on'); set(h_button(8), 'Enable', 'off');else set(h_button(7), 'Enable', 'off'); set(h_button(8), 'Enable', 'on');endreturnfunction roi_struct = create_roi_struct(roi_coord, image_bin)% create valid ROI% round pixels to provide exact binningfield_name = {'s1', 's2', 'sbin', 'p1', 'p2', 'pbin'};field_value = {roi_coord(1) - 1, roi_coord(3) - mod(diff(roi_coord([1 3])) + 1, image_bin(1)) - 1, image_bin(1), ... roi_coord(2) - 1, roi_coord(4) - mod(diff(roi_coord([2 4])) + 1, image_bin(2)) - 1, image_bin(2)};roi_struct = cell2struct(field_value, field_name, 2);returnfunction h_fig = make_image_win(figure_tag)% default parametersfigure_bkgnd = [0.8 0.8 0.8]; % figure window background colorspecfigure_pos = [0.10 0.10 0.80 0.80]; % figure window position (% of screen)text_pos = [0.03 0.95 0.87 0.03]; % text label position (% of figure)button_pos = [0.08 0.03 0.72 0.05]; % button panel position (% of figure)image_pos = [0.03 0.10 0.87 0.85]; % image display position (% of figure)color_pos = [0.92 0.10 0.06 0.85]; % colorbar display position (% of figure)% create figure windowh_fig = figure('Color', figure_bkgnd, ... 'Units', 'normalized', ... 'Position', figure_pos, ... 'BackingStore', 'off', ... 'CloseRequestFcn', 'anatseq(gcf, ''finish'')', ... 'MenuBar', 'none', ... 'Name', 'No file open', ... 'NumberTitle', 'off', ... 'Pointer', 'arrow', ... 'UserData', [], ... 'Tag', figure_tag);% create text labelh_text = uicontrol('Parent', h_fig, ... 'Units', 'normalized', ... 'Position', text_pos, ... 'BackgroundColor', figure_bkgnd, ... 'ForegroundColor', [0.0 0.0 0.0], ... 'FontName', 'Helvetica', ... 'FontSize', 8, ... 'String', '', ... 'Style', 'text', ... 'Tag', 'imagetext');% create button panellabels = {'Snap Image', 'Start Focus', 'Stop Focus', 'Parameters', 'Camera Setup', 'ROI Setup', 'Open File', 'Close File'};h_button = guipanel(h_fig, button_pos, 'horizontal', ... 'Enable', 'off', ... 'FontName', 'Helvetica', ... 'FontSize', 8, ... 'Style', 'pushbutton', ... 'Callback', 'anatseq(gcf, get(gcbo, ''Tag''))', ... 'String', labels, ... 'Tag', labels);set(h_button(3), 'Callback', 'set(gcf, ''Tag'', ''stop'')');% create image axesh_axes(1) = axes('Parent', h_fig, ... 'Units', 'normalized', ... 'Position', image_pos, ... 'Box', 'on', ... 'XDir', 'reverse', ... 'XTick', [], ... 'YDir', 'normal', ... 'YTick', [], ... 'Tag', 'image');% create colorbar axesh_axes(2) = axes('Parent', h_fig, ... 'Units', 'normalized', ... 'Position', color_pos, ... 'Box', 'on', ... 'XDir', 'normal', ... 'XTick', [], ... 'YDir', 'normal', ... 'YTick', [], ... 'Tag', 'colorbar');% save handles to figure UserData structurefig_handle = cell2struct({h_axes, h_text, h_button}, {'h_axes', 'h_text', 'h_button'}, 2);set(h_fig, 'UserData', fig_handle);return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -