⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmtmode.m

📁 SDFGASFASFASFAS EDGSGA DGSFGSA
💻 M
📖 第 1 页 / 共 3 页
字号:
                %focus_par = pvcamfocus(h_fig, 'set mark', focus_par, image_par.roi_pmt);                %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);                %    set(focus_par{1}.h_image, 'ButtonDownFcn', 'pmtmode(gcf, ''select pixel'')');                %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 PMT mode (high rate) sequence                [image_data, file_par] = get_pmt_seq(h_fig, image_par, file_par, lambda_par);                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);                if ((image_par.total_seq > 1) && (image_par.time_seq > 0))                else                    enable_buttons(fig_handle.h_button, file_par, image_par);                    if (~isempty(file_par.name_pmt))                        pmtmode(h_fig, 'gather files');                    end                end                % update graph of PMT data                if (~isempty(image_data) && isnumeric(image_data))                    pmtmode(h_fig, 'reset graph');                    axes(fig_handle.h_axes(3));                    % skip display of underexposed 1st sample                    % account for 3-D image data for 2-D PMT pixels                    if (ndims(image_data) == 2)                        h_line = line(2 : size(image_data, 2), image_data(:, 2 : end));                        set(fig_handle.h_axes(3), 'FontName', 'helvetica', 'FontSize', 8, 'Tag', 'graph', 'UserData', h_line);                    end                end        end    case 'select pixel'         % select pixel for PMT mode        curr_pt = get(fig_handle.h_axes(1), 'CurrentPoint');        if (axesflag(fig_handle.h_axes(1), curr_pt(1, 1), curr_pt(1, 2)) && strcmp(get(h_fig, 'SelectionType'), 'normal'))            image_par.offset_pmt = round(curr_pt(1, 1 : 2));            image_par = create_roi_struct(image_par);            set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par});            pmtmode(h_fig, 'draw pixel');        end    case 'draw pixel'           % draw zone on image        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');            disp_single_image(image_data, fig_handle, image_par, file_par);        end        enable_buttons(fig_handle.h_button, file_par, image_par);    case 'clear pixel'          % clear selected pixel        if (~isempty(image_par.roi_pmt) || ~isempty(image_par.offset_pmt))            [image_par.roi_pmt, image_par.offset_pmt] = deal([]);            set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par});            % clear zone from image            axes(fig_handle.h_axes(1));            h_image = get(fig_handle.h_axes(1), 'UserData');            if (istype(h_image, 'image'))                disp_single_image(get(h_image, 'UserData'), fig_handle, image_par, file_par);            end            enable_buttons(fig_handle.h_button, file_par, image_par);        end    case 'draw line'            % acquire image from line of pixels        % FUTURE IMPLEMENTATION        % TEMPORARILY IMPLEMENTED WITH PIXEL_PMT PARAM    case 'parameters'       % define sequence parameters        % setup editing of acquisition parameters for GUISTRUCT        field_name = {'file_path', 'file_prefix', 'expose_full', 'total_full', 'bin_full', ...            'expose_pmt', 'total_pmt', 'bin_pmt', 'pixel_pmt', 'total_seq', 'time_seq'};        field_lower = [-Inf -Inf 0 1 1 0 1 1 1 1 1];        field_upper = Inf * ones(size(field_lower));        field_title = {'File path', 'File prefix', 'Full exp (ms)', 'Full count', 'Full bin', ...            'PMT exp (ms)', 'PMT count', 'PMT bin', 'PMT pixels', 'Seq count', 'Seq time (s)'};        field_format = {'%s', '%s', '%d', '%d', '%d', ...            '%d', '%d', '%d', '%d', '%d', '%d'};        field_multi = {'string', 'string', 'scalar', 'scalar', 'vector', ...            'scalar', 'scalar', 'vector', 'vector', 'scalar', 'scalar'};        % 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            % recalculate PMT ROI in case binning has changed            % recalculate focus parameters            image_par = create_roi_struct(image_par);            %focus_par = pvcamfocus(fig_handle.h_axes(1), 'initialize', ...            %    image_par.h_cam, image_par.expose_full, image_par.roi_full);            set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par});            if (~isempty(image_par.offset_pmt))                pmtmode(h_fig, 'draw pixel');            end            enable_buttons(fig_handle.h_button, file_par, image_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 = create_roi_struct(image_par);        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 & MAT files        % generate file name        % full image example:  scm07feb03a.tif        % PMT series example:  scm07feb03a.mat        file_date = lower([datestr(datenum(date),'dd') datestr(datenum(date),'mmmyy')]);        for file_char = double('a') : double('z')            name_full = [file_par.file_prefix file_date char(file_char) '.tif'];            name_pmt = [file_par.file_prefix file_date char(file_char) '.mat'];            if (~exist(fullfile(file_par.file_path, name_full), 'file') && ...                    ~exist(fullfile(file_par.file_path, name_pmt), 'file'))                break            end        end        % have user select file name        old_dir = pwd;        if (exist(file_par.file_path, 'dir'))            cd(file_par.file_path);            [name_full, file_path] = uiputfile(name_full, 'Save Images to File');            cd(old_dir);        else            [name_full, file_path] = uiputfile(name_full, 'Save Images to File');            warning('MATLAB:pmtmode', '%s not found, saving file to %s',  file_par.file_path, old_dir)        end        if ((name_full(1) ~= 0) && (file_path(1) ~= 0))            % reset clock and filename display            % reset pixel intensity graph            % enable appropriate buttons            file_par.name_full = lower(name_full);            file_par.file_path = file_path;            % INSERT FUTURE CHECK FOR .TIF EXT BEFORE STRREP!!!            file_par.name_pmt = strrep(lower(name_full), '.tif', '.mat');            file_par.count_full = 0;            file_par.count_pmt = 0;            file_par.count_acq = 0;            file_par.start_time = clock;            set(h_fig, 'Name', file_par.name_full);            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);            pmtmode(h_fig, 'reset graph');        end    case 'close file'       % stop saving images to TIF file        file_par.name_full = '';        file_par.name_pmt = '';        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 'reset graph'      % reset time and graph display        delete(get(fig_handle.h_axes(3), 'Children'));    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        if (isa(image_par.h_pmtseq, 'timer'))            stop(image_par.h_pmtseq);            delete(image_par.h_pmtseq);        end        delete(h_fig);    otherwise               % invalid command        warning('MATLAB:pmtmode', 'command ''%s'' not recognized', control_command);endreturnfunction [image_data, new_file] = get_pmt_seq(h_fig, image_par, file_par, lambda_par)% 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))    image_data = uint16((2 ^ image_par.bit_depth - 1) * rand(1, prod(image_par.pixel_pmt) * image_par.total_pmt));    start_time = clock;    while (1000 * etime(clock, start_time) < (image_par.expose_pmt * image_par.total_pmt))    endelse    %icl_script = create_icl_script(image_par, pvcam_get, pvcam_set);    %[image_data, disp_info] = pvcamicl(image_par.h_cam, [icl_script{:}]);    image_data = pvcamacq(image_par.h_cam, ...        image_par.total_pmt, image_par.roi_pmt, image_par.expose_pmt, 'timed');end% close shutter if Lambda 10-2 presentif (strcmp(image_par.filter_name, 'lambda 10-2'))    set(h_fig, 'Tag', 'close');    lambdactrl(lambda_par.port, 'close');end% convert image stream into 2-D array% NOTE CAN HANDLE MULTIPLE PIXEL ROIS WITH RESHAPE?if (~isempty(image_data) && isnumeric(image_data))    %image_data = roiparse(image_data, image_par.roi_full);    if (all(image_par.pixel_pmt == 1))        image_data = reshape(image_data, 1, numel(image_data));    elseif (any(image_par.pixel_pmt == 1))        image_data = reshape(image_data, prod(image_par.pixel_pmt), numel(image_data) / prod(image_par.pixel_pmt));    else        image_data = reshape(image_data, [image_par.pixel_pmt (numel(image_data) / prod(image_par.pixel_pmt))]);    end    new_file.count_pmt = new_file.count_pmt + 1;    new_file.count_seq = new_file.count_seq + 1;    % save image data if file is open    % use temporary files then gather after stop    if (~isempty(new_file.name_pmt))        pmt_file = fullfile(new_file.file_path, new_file.name_pmt);        tmp_file = strrep(pmt_file, '.mat', sprintf('_pmt%04d.mat', new_file.count_pmt));        save_struct = cell2struct({new_file, image_par, image_data}, {'file_par', 'image_par', 'image_data'}, 2);        var_name = sprintf('pmt%04d', new_file.count_pmt);        eval(sprintf('%s = save_struct;', var_name), '');        if (exist(tmp_file, 'file'))            if (file_par.version < 7)                save(tmp_file, var_name, '-append');            else                save(tmp_file, var_name, '-append', '-v6');            end        else            if (file_par.version < 7)                save(tmp_file, var_name);            else                save(tmp_file, var_name, '-v6');            end        end    endendreturnfunction [image_data, new_file] = get_single_image(h_fig, fig_handle, image_par, file_par, lambda_par, focus_flag)% initialize outputsnew_file = file_par;if (strcmp(focus_flag, 'focus'))    image_par.total_full = 1;end% 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)), image_par.total_full));    start_time = clock;    while (1000 * etime(clock, start_time) < (image_par.expose_full + 100) * image_par.total_full)    endelse    image_data = pvcamacq(image_par.h_cam, ...        image_par.total_full, image_par.roi_full, image_par.expose_full, 'timed');end% close shutter if Lambda 10-2 present

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -