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

📄 pmtmode.m

📁 SDFGASFASFASFAS EDGSGA DGSFGSA
💻 M
📖 第 1 页 / 共 3 页
字号:
function [] = pmtmode(varargin)% PMTMODE - perform high-speed non-ratiometric imaging%%    PMTMODE acquires a sequence of non-ratiometric images from a single%    binned pixel.  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.% 10/29/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:pmtmode', 'type ''help pmtmode'' 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};    %lambda_struct = get(lambda_port, 'UserData');    h_fig = gcf;    control_command = 'lambda callback';elseif (~istype(varargin{1}, 'figure'))    warning('MATLAB:pmtmode', 'H_FIG must be a valid figure window');    returnelseif (~ischar(varargin{2}) || isempty(varargin{2}))    warning('MATLAB:pmtmode', '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:pmtmode', 'cannot find valid UserData cell array in H_FIG');        return    endend% figure window parameters% used by Lambda 10-2 interfacemotion_fcn = 'pmtmode(gcbo, ''pointer value'')';figure_tag = 'pmtmode';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', @pmtmode, []}, ...            {'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('PMTMODE: 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('PMTMODE: 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:pmtmode', '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_pmtseq', 'filter_name', ...            'roi_full', 'roi_coord', 'roi_pmt', 'offset_pmt', 'image_size', 'bit_depth', ...            'expose_full', 'total_full', 'bin_full', 'expose_pmt', 'total_pmt', ...            'bin_pmt', 'pixel_pmt', 'total_seq', 'time_seq', 'color_map'};        field_value = {h_cam, [], [], 'none', ...            [], roi_coord, [], [], image_size, pvcam_get.PARAM_BIT_DEPTH, ...            10, 1, [1 1], 1, 85, ...            [4 4], [20 1], 1, 5, @jet};        image_par = cell2struct(field_value, field_name, 2);        image_par = create_roi_struct(image_par);        % create file parameters structure        field_name = {'file_path', 'name_full', 'name_pmt', 'file_prefix', ...            'count_full', 'count_pmt', 'count_seq', 'count_acq', 'start_time', 'acq_time', 'version'};        field_value = {'c:\scm\cells', '', '', 'scm', 0, 0, 0, 0, clock, clock, getversion};        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_full, image_par.roi_full);        focus_par = [];        set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par});        pmtmode(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.count_full, ...                    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', 'pmtmode(gcf, ''lambda setup'')', ...            'TimerFcn', 'pmtmode(gcf, ''no lambda 10-2'')', ...            'StopFcn', '', ...            'ErrorFcn', 'pmtmode(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('PMTMODE: Lambda 10-2 detected');        elseif (~isempty(err_msg))            warning('MATLAB:pmtmode', '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))            pmtmode(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('PMTMODE: 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'))            pmtmode(h_fig, 'lambda detect');        else            enable_buttons(fig_handle.h_button, file_par, image_par);            set(h_fig, 'WindowButtonMotionFcn', motion_fcn);        end    case 'pmt sequence'     % timed sequences like electrophysiologic acquisition        % setup timer if needed        file_par.count_seq = 0;        file_par.count_acq = file_par.count_acq + 1;        if ((image_par.total_seq > 1) && (image_par.time_seq > 0))            set(fig_handle.h_button(5), 'Callback', 'pmtmode(gcf, ''stop sequence'')', 'String', 'Stop Sequence');            if (~isa(image_par.h_pmtseq, 'timer'))                image_par.h_pmtseq = timer(...                    'ExecutionMode', 'fixedrate', ...                    'BusyMode', 'drop');            end            set(image_par.h_pmtseq, ...                'TasksToExecute', image_par.total_seq, ...                'StartDelay', 0, ...                'Period', image_par.time_seq, ...                'StartFcn', '', ...                'TimerFcn', 'pmtmode(gcf, ''start sequence'')', ...                'StopFcn', 'pmtmode(gcf, ''stop sequence'')', ...                'ErrorFcn', '');            set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par});            start(image_par.h_pmtseq);        else            set(h_fig, 'UserData', {fig_handle, image_par, file_par, pvcam_get, pvcam_set, lambda_par, focus_par});            pmtmode(h_fig, 'start sequence');        end    case 'stop sequence'    % end or interrupt timed sequences        if (isa(image_par.h_pmtseq, 'timer'))            set(image_par.h_pmtseq, 'StopFcn', '');            stop(image_par.h_pmtseq);        end                 % gather & delete temporary files after stop        if (~isempty(file_par.name_pmt))            pmtmode(h_fig, 'gather files');        end                % reset controls        set(fig_handle.h_button(5), 'Callback', 'set(gcf, ''Tag'', ''stop'')', 'String', 'Stop Focus');        enable_buttons(fig_handle.h_button, file_par, image_par);           case 'gather files'     % gather & delete temporary files        pmt_file = fullfile(file_par.file_path, file_par.name_pmt);        tmp_file = strrep(pmt_file, '.mat', '_pmt*.mat');        dir_list = dir(tmp_file);        var_name = sprintf('img%04d_acq%04d', file_par.count_full, file_par.count_acq);        save_struct = [];        for i = 1 : length(dir_list)            v = load(fullfile(file_par.file_path, dir_list(i).name));            v_list = fieldnames(v);            for j = 1 : length(v_list)                save_struct.(v_list{j}) = v.(v_list{j});            end        end        eval(sprintf('%s = save_struct;', var_name), '');        if (exist(pmt_file, 'file'))            if (file_par.version < 7)                save(pmt_file, var_name, '-append');            else                save(pmt_file, var_name, '-append', '-v6');            end        else            if (file_par.version < 7)                save(pmt_file, var_name);            else                save(pmt_file, var_name, '-v6');            end        end        delete(tmp_file);    case {'snap image', 'image sequence', 'start focus', 'start sequence'}  % initiate image acquisition        % disable buttons and open shutter        % this will execute lambda 10-2 command callback upon completion        % remainder of image acquisition will be completed during callback        set(fig_handle.h_button, 'Enable', 'off');        set(fig_handle.h_button(5), '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            pmtmode(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                total_full = image_par.total_full;                image_par.total_full = 1;                [image_data, file_par] = get_single_image(h_fig, fig_handle, image_par, file_par, lambda_par, 'normal');                image_par.total_full = total_full;                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 'image sequence'   % acquire image sequence                [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

⌨️ 快捷键说明

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