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

📄 pvcamfocus.m

📁 SDFGASFASFASFAS EDGSGA DGSFGSA
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = pvcamfocus(varargin)

% PVCAMFOCUS - runs an ICL script for camera focus
%
%    PVCAMFOCUS acquires a series of images from a PVCAM camera using ICL
%    and frame transfer mode if available.  The images are displayed within
%    a new figure window that has Start and Stop buttons.
%
%    PVCAMFOCUS(HAXES, 'initialize', HCAM, EXPTIME, ROI) specifies various
%    parameters for image acquisition and display.  HAXES is the handle to
%    the image display axes.  HCAM is the handle to an open PVCAM camera to
%    use for image acquisition.  EXPTIME specifies the exposure time in ms.
%    ROI specifies the CCD region(s) from which images will be acquired.
%    The structure array ROI must have the following scalar fields:
%
%					s1 = first serial register
%					s2 = last serial register
%					sbin = serial binning factor
%					p1 = first parallel register
%					p2 = last parallel register
%					pbin = parallel binning factor
%
%	 The length of the structure array ROI determines the number of CCD
%	 regions that will be imaged.
%
%    PVCAMFOCUS(HFIG, 'set mark') sets a registration mark for display.
%
%    PVCAMFOCUS(HFIG, 'start focus') starts the image acquisition.
%
%    PVCAMFOCUS(HFIG, 'stop focus') interrupts image acquisition.
%
%    PVCAMFOCUS(HFIG, 'color map') changes the color map of the image
%    display.
%
%    PVCAMFOCUS(HFIG, 'finish') closes the camera and figure window.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    Use the following with another image acquisition program:
%
%        USER_DATA = PVCAMFOCUS(HAXES, 'initialize', HCAM, EXPTIME, ROI);
%        USER_DATA = PVCAMFOCUS(HFIG, 'start_focus', USER_DATA);
%
%    The calling program must provide a valid axis handle HAXES for image
%    display and a handle to an open PVCAM device HCAM.  The default
%    exposure time EXPTIME is 0 ms and the default ROI is the full array
%    with 1 x 1 binning if not provided by the calling routine.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 1/30/04 SCM

% initialize outputs
if (nargout > 0)
    varargout = cell(1, nargout);
end

% validate fixed arguments
if (nargin > 5)
    warning('MATLAB:pvcamfocus', 'type ''help pvcamfocus'' for syntax');
    return
else
    control_command = lower(chkvarargin(varargin, 2, 'char', [1 10], 'cmd', 'initialize'));
end

% call routine to initialize variable inputs on first call
% obtain parameters from figure window if callback
if (strcmp(control_command, 'initialize'))
    h_axes = chkvarargin(varargin, 1, 'double', [1 1], 'haxes', NaN);
    h_cam = chkvarargin(varargin, 3, 'double', [1 1], 'hcam', NaN);
    camera_struct.exp_time = max(floor(chkvarargin(varargin, 4, 'double', [1 1], 'exptime', 100)), 0);
    if (nargin >= 5)
        roi_struct = varargin{5};
    else
        roi_struct = [];
    end

    % figure window parameters
    motion_fcn = 'pvcamfocus(gcbo, ''pointer value'')';
    figure_tag = 'pvcamfocus';

    % default camera parameters
    pvcam_setpar = {'TEMP_SETPOINT', 'CLEAR_MODE', 'CLEAR_CYCLES', ...
        'SHTR_OPEN_MODE', 'SPDTAB_INDEX', 'GAIN_INDEX'};
    pvcam_setvalue = {-2500, 'clear pre-exposure', 2, 'do not change shutter state', 2, 3};
    pvcam_getpar = {'SER_SIZE', 'PRESCAN', 'POSTSCAN', 'PAR_SIZE', 'PREMASK', 'POSTMASK', ...
        'BIT_DEPTH', 'FRAME_CAPABLE', 'PIX_TIME', 'TEMP'};
    pvcam_getvalue = {535, 13, 6, 512, 528, 16, 12, 1, 333, -2500};

else
    h_fig = chkvarargin(varargin, 1, 'double', [1 1], 'hfig', NaN);
    if (istype(h_fig, 'figure'))
        if (nargin > 2)
            user_data = varargin{3};
            if (nargin > 3)
                roi_mark = varargin{4};
            end
        else
            user_data = get(h_fig, 'UserData');
        end
        if (iscell(user_data) && (length(user_data) >= 4))
            [figure_struct, camera_struct, pvcam_struct, icl_script] = deal(user_data{1 : 4});
        else
            warning('MATLAB:pvcamfocus', 'cannot find valid UserData cell array in H_FIG');
            return
        end
    else
        warning('MATLAB:pvcamfocus', 'HFIG must be a valid figure window');
        return
    end
end

% execute callback command
switch (control_command)

    case 'initialize'   % initialize figure window and camera
        % open camera if needed
        if (isnan(h_cam))
            camera_struct.h_cam = pvcamopen(0);
            if (isempty(camera_struct.h_cam))
                disp('PVCAMFOCUS: could not open camera, using DEMO mode');
                pvcamclose(0);
            else
                disp('PVCAMFOCUS: camera detected');
            end

            % set camera parameters
            for i = 1 : length(pvcam_setpar)
                if (isempty(camera_struct.h_cam))
                    pvcam_struct.(lower(pvcam_setpar{i})) = pvcam_setvalue{i};
                elseif (pvcamsetvalue(camera_struct.h_cam, ...
                        sprintf('PARAM_%s', upper(pvcam_setpar{i})), pvcam_setvalue{i}))
                    pvcam_struct.(lower(pvcam_setpar{i})) = pvcam_setvalue{i};
                else
                    warning('MATLAB:pvcamfocus', 'could not set PARAM_%s, use current value', pvcam_setpar{i});
                    pvcam_struct.(lower(pvcam_setpar{i})) = ...
                        pvcamgetvalue(camera_struct.h_cam, sprintf('PARAM_%s', upper(pvcam_setpar{i})));
                end
            end
        else
            % obtain camera parameters
            camera_struct.h_cam = h_cam;
            for i = 1 : length(pvcam_setpar)
                if (isempty(camera_struct.h_cam))
                    pvcam_struct.(lower(pvcam_setpar{i})) = pvcam_setvalue{i};
                else
                    pvcam_struct.(lower(pvcam_setpar{i})) = ...
                        pvcamgetvalue(camera_struct.h_cam, sprintf('PARAM_%s', upper(pvcam_setpar{i})));
                end
            end
        end

        % obtain chip geometry & other camera parameters
        % some values (PRESCAN, POSTSCAN & POSTMASK) are irrelevant
        for i = 1 : length(pvcam_getpar)
            if (isempty(camera_struct.h_cam))
                camera_struct.(lower(pvcam_getpar{i})) = pvcam_getvalue{i};
            else
                camera_struct.(lower(pvcam_getpar{i})) = ...
                    pvcamgetvalue(camera_struct.h_cam, sprintf('PARAM_%s', upper(pvcam_getpar{i})));
            end
        end

        % initialize ROI if needed
        % call ROIOVERLAP to check for valid ROI coordinates
        % create ICL scripts for shutter and focus
        camera_struct.roi_struct = roioverlap(defstruc(roi_struct, ...
            {'s1', 's2', 'sbin', 'p1', 'p2', 'pbin'}, ...
            {0, camera_struct.ser_size - 1, 1, 0, camera_struct.par_size - 1, 1}), ...
            camera_struct.ser_size, camera_struct.par_size);
        camera_struct.roi_mark = [];
        icl_script = create_icl_script(camera_struct, pvcam_struct);

        % create figure window if needed
        % obtain object handles
        if (istype(h_axes, 'axes'))
            h_fig = get(h_axes, 'Parent');
            figure_struct.h_axes = h_axes;
            figure_struct.h_image = [];
        else
            h_fig = make_image_win(figure_tag);
            figure_struct = get(h_fig, 'UserData');
            disp_colorbar(h_fig, figure_struct.h_axes(2), figure_struct.color_map);

            % setup mouse pointer motion callback
            % enable Start & disable Stop button
            set(h_fig, 'WindowButtonMotionFcn', motion_fcn);
            set(figure_struct.h_button(1), 'Enable', 'on');
            set(figure_struct.h_button(2), 'Enable', 'off');
        end

    case 'set mark'
        if (isempty(roi_mark))
            camera_struct.roi_mark = [];
        else
            camera_struct.roi_mark = defstruc(roi_mark, {'s1', 's2', 'p1', 'p2'}, ...
                {0, camera_struct.ser_size - 1, 0, camera_struct.par_size - 1});
        end

    case 'start focus'  % start focus
        % disable Start & enable Stop button if provided
        if (isfield(figure_struct, 'h_button'))
            set(figure_struct.h_button(1), 'Enable', 'off');
            set(figure_struct.h_button(2), 'Enable', 'on');
        end

        % reset figure text if provided
        if (isfield(figure_struct, 'h_text'))
            set(figure_struct.h_text(1), 'String', 'Acquiring Images ...');
        end

        % clear Tag to stop acquisition
        % disable WindowButtonMotionFcn
        old_tag = get(h_fig, 'Tag');
        set(h_fig, 'Tag', 'start');
        motion_fcn = get(h_fig, 'WindowButtonMotionFcn');
        set(h_fig, 'WindowButtonMotionFcn', '');

        % open camera shutter & load acquisition script if not demo mode
        if (isempty(camera_struct.h_cam))
            data_struct = zeros(1, sum(sum(roimask(camera_struct.roi_struct))));
        else
            [data_struct, disp_info] = pvcamicl(camera_struct.h_cam, [icl_script.open{:}], 'full');
            if (isempty(data_struct) && ischar(disp_info))
                if (strcmp(disp_info, 'no image'))
                    %[data_struct, disp_info] = pvcamicl(camera_struct.h_cam, [icl_script.acq{:}], 'load');
                    %if (~isempty(data_struct) && isstruct(disp_info))
                    %else
                    %    set(h_fig, 'Tag', 'stop');
                    %end
                else
                    set(h_fig, 'Tag', 'stop');
                end
            else
                set(h_fig, 'Tag', 'stop');
            end
        end

        % acquire images if stop detected
        image_mask = [];
        while (~strcmp(get(h_fig, 'Tag'), 'stop'))
            if (isempty(camera_struct.h_cam))
                data_struct = uint16((2 ^ camera_struct.bit_depth - 1) * rand(size(data_struct)));
                pause(camera_struct.exp_time / 1000);
            else
                data_struct = pvcamicl(camera_struct.h_cam, data_struct, 'run');
                %data_struct = pvcamacq(camera_struct.h_cam, 1, ...
                %    camera_struct.roi_struct, camera_struct.exp_time, 'timed');
                if (isempty(data_struct))
                    break
                end
            end

            % convert image to UINT8 for display
            image_data = roiparse(data_struct, camera_struct.roi_struct);
            if (camera_struct.bit_depth > 8)
                image_disp = uint8(image_data / 2 ^ (camera_struct.bit_depth - 8));
            else
                image_disp = uint8(image_data);
            end

            % create image mask if needed
            if (isstruct(camera_struct.roi_mark))
                if (isempty(image_mask))
                    image_mask = feval(class(image_disp), ones(size(image_disp)));
                    image_mask(camera_struct.roi_mark.p1 : camera_struct.roi_mark.p2, ...
                        camera_struct.roi_mark.s1 : camera_struct.roi_mark.s2) = feval(class(image_disp), 0);

⌨️ 快捷键说明

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