📄 fluoseq.m
字号:
delete(image_par.h_lambda); end if (isa(image_par.h_fluoseq, 'timer')) stop(image_par.h_fluoseq); delete(image_par.h_fluoseq); end delete(h_fig); otherwise % invalid command warning('MATLAB:fluoseq', '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:fluoseq', 'unable to find image axes'); returnendh_text = fig_handle.h_text;if (~istype(h_text, 'uicontrol')) warning('MATLAB:fluoseq', '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:fluoseq', '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', 'fluoseq(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(4), 'Enable', 'off');% camera setup buttonif (isscalar(image_par.h_cam)) set(h_button(10), 'Enable', 'on');else set(h_button(10), 'Enable', 'off');end% open/close file buttonif (isempty(file_par.file_name)) set(h_button(12), 'Enable', 'on'); set(h_button(13), 'Enable', 'off');else set(h_button(12), 'Enable', 'off'); set(h_button(13), '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.17 0.95 0.73 0.03]; % text label position (% of figure)button_pos = [0.02 0.23 0.13 0.72]; % button panel position (% of figure)image_pos = [0.17 0.23 0.73 0.72]; % image display position (% of figure)color_pos = [0.92 0.23 0.06 0.72]; % colorbar display position (% of figure)graph_pos = [0.08 0.05 0.90 0.15]; % graph display position (% of figure)% create figure windowh_fig = figure('Color', figure_bkgnd, ... 'Units', 'normalized', ... 'Position', figure_pos, ... 'BackingStore', 'off', ... 'CloseRequestFcn', 'fluoseq(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 Sequence', 'Start Focus', 'Stop Focus', 'Select Region', 'Show Region', ... 'Clear Region', 'Reset Graph', 'Parameters', 'Camera Setup', 'ROI Setup', 'Open File', 'Close File'};h_button = guipanel(h_fig, button_pos, 'vertical', ... 'Enable', 'off', ... 'FontName', 'Helvetica', ... 'FontSize', 8, ... 'Style', 'pushbutton', ... 'Callback', 'fluoseq(gcf, get(gcbo, ''Tag''))', ... 'String', labels, ... 'Tag', labels);set(h_button(4), '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');% create graph axesh_axes(3) = axes('Parent', h_fig, ... 'Units', 'normalized', ... 'Position', graph_pos, ... 'Box', 'on', ... 'FontName', 'helvetica', ... 'FontSize', 8, ... 'Tag', 'graph');% 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 + -