📄 pvcamfocus.m
字号:
end
image_disp = image_disp .* image_mask;
end
% display acquired image
if (istype(figure_struct.h_image, 'image'))
set(figure_struct.h_image, 'CData', image_disp, 'UserData', image_data);
set(figure_struct.h_axes(1), 'XLim', [1 size(image_disp, 2)], 'YLim', [1 size(image_disp, 1)]);
else
axes(figure_struct.h_axes(1));
figure_struct.h_image = image(image_disp);
set(figure_struct.h_image, 'EraseMode', 'none', 'UserData', image_data);
set(figure_struct.h_axes(1), 'XDir', 'reverse', ...
'XTick', [], ...
'YDir', 'normal', ...
'YTick', []);
end
drawnow;
end
% remove acquisition script & close camera shutter if not demo mode
if (~isempty(camera_struct.h_cam))
if (pvcamicl(camera_struct.h_cam, [], 'uninit'))
[data_struct, disp_info] = pvcamicl(camera_struct.h_cam, [icl_script.close{:}], 'full');
end
end
% reset figure Tag
% enable WindowButtonMotionFcn
% enable Start & disable Stop button
set(h_fig, 'Tag', old_tag);
set(h_fig, 'WindowButtonMotionFcn', motion_fcn);
if (isfield(figure_struct, 'h_button'))
set(figure_struct.h_button(1), 'Enable', 'on');
set(figure_struct.h_button(2), 'Enable', 'off');
end
case 'stop focus' % start focus
set(h_fig, 'Tag', 'stop');
return
case 'color map' % change color map
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(figure_struct.color_map));
if (select_flag)
figure_struct.color_map = str2func(new_value);
disp_colorbar(h_fig, figure_struct.h_axes(2), figure_struct.color_map);
else
return
end
case 'pointer value' % obtain value under mouse pointer
if (istype(figure_struct.h_image, 'image'))
image_data = get(figure_struct.h_image, 'UserData');
[ptr_pos, ptr_flag] = ptrpos(h_fig, figure_struct.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)
set(figure_struct.h_text(1), 'String', sprintf('Intensity at (%d, %d) = %g', ...
ptr_pos(1), ptr_pos(2), double(image_data(ptr_pos(2), ptr_pos(1)))));
end
end
return
case 'finish' % close camera and figure window
if (isempty(camera_struct.h_cam))
pvcamclose(0);
else
pvcamclose(camera_struct.h_cam);
end
delete(h_fig);
return
otherwise % invalid command
warning('MATLAB:pvcamfocus', '%s is not a valid command', upper(control_command));
return
end
% return cell array of parameters if output argument
% otherwise store all parameters to figure UserData field
if (nargout > 0)
varargout{1} = {figure_struct, camera_struct, pvcam_struct, icl_script};
else
set(h_fig, 'UserData', {figure_struct, camera_struct, pvcam_struct, icl_script});
end
return
% CREATE_ICL_SCRIPT
function icl_script = create_icl_script(camera_struct, pvcam_struct)
% obtain ICL coordinates from ROI structure
s_offset = [camera_struct.roi_struct(:).s1];
s_size = [camera_struct.roi_struct(:).s2] - [camera_struct.roi_struct(:).s1] + 1;
s_bin = [camera_struct.roi_struct(:).sbin];
x_size = floor(s_size ./ s_bin);
p_shift(1) = camera_struct.roi_struct(1).p1 + camera_struct.premask - 1;
if (length(camera_struct.roi_struct) > 1)
p_shift(2 : length(camera_struct.roi_struct)) = ...
[camera_struct.roi_struct(2 : end).p1] - [camera_struct.roi_struct(1 : end - 1).p2] - 1;
end
p_size = [camera_struct.roi_struct(:).p2] - [camera_struct.roi_struct(:).p1] + 1;
p_bin = [camera_struct.roi_struct(:).pbin];
y_size = floor(p_size ./ p_bin);
% create scripts to open & close shutter
% clear CCD array after shutter opens & closes
% make sure camera is in proper shift mode if frame transfer capable
icl_script.open = {'script_begin( );', ...
'shutter_open( );', ...
sprintf('clear_parallel( %d );', pvcam_struct.clear_cycles), ...
sprintf('clear_serial( %d );', pvcam_struct.clear_cycles)};
if (camera_struct.frame_capable)
icl_script.open{end + 1} = 'shift_mode_is( );';
end
icl_script.open{end + 1} = 'script_end( 0 );';
icl_script.close = {'script_begin( );', ...
'shutter_close( );', ...
sprintf('clear_parallel( %d );', pvcam_struct.clear_cycles), ...
sprintf('clear_serial( %d );', pvcam_struct.clear_cycles), ...
'script_end( 0 );'};
% initialize acquisition script
% clear array and expose for specified time
icl_script.acq = {'script_begin( );', ...
sprintf('clear_parallel( %d );', pvcam_struct.clear_cycles), ...
sprintf('clear_serial( %d );', pvcam_struct.clear_cycles), ...
sprintf('expose( %d );', camera_struct.exp_time)};
% shift exposed pixels into serial register if needed
if (p_shift(1) > 0)
icl_script.acq{end + 1} = sprintf('shift( %d );', p_shift(1));
end
% readout pixels from serial register
% shift subsequent ROIs into serial register if present
for i = 1 : length(camera_struct.roi_struct)
icl_script.acq{end + 1} = sprintf('pixel_readout( %d, %d, %d, %d, %d );', ...
s_offset(i), s_size(i), s_bin(i), p_size(i), p_bin(i));
icl_script.acq{end + 1} = sprintf('pixel_display( %d, %d );', x_size(i), y_size(i));
if (i < length(camera_struct.roi_struct))
if (p_shift(i + 1) > 0)
icl_script.acq{end + 1} = sprintf('shift( %d );', p_shift(i + 1));
end
end
end
icl_script.acq{end + 1} = 'script_end( 0 );';
return
% MAKE_IMAGE_WIN
function h_fig = make_image_win(figure_tag)
% default parameters
figure_bkgnd = [0.8 0.8 0.8]; % figure window background colorspec
figure_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.28 0.03 0.42 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 window
h_fig = figure('Color', figure_bkgnd, ...
'Units', 'normalized', ...
'Position', figure_pos, ...
'BackingStore', 'off', ...
'CloseRequestFcn', 'pvcamfocus(gcf, ''finish'')', ...
'MenuBar', 'none', ...
'Name', 'Focus Window', ...
'NumberTitle', 'off', ...
'Pointer', 'arrow', ...
'UserData', [], ...
'Tag', figure_tag);
% create text label
h_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 panel
labels = {'Start Focus', 'Stop Focus'};
h_button = guipanel(h_fig, button_pos, 'horizontal', ...
'Enable', 'off', ...
'FontName', 'Helvetica', ...
'FontSize', 8, ...
'Style', 'pushbutton', ...
'Callback', 'pvcamfocus(gcf, get(gcbo, ''Tag''))', ...
'String', labels, ...
'Tag', labels);
set(h_button(2), 'Callback', 'set(gcf, ''Tag'', ''stop'')');
% create image axes
h_axes(1) = axes('Parent', h_fig, ...
'Units', 'normalized', ...
'Position', image_pos, ...
'Box', 'on', ...
'XDir', 'reverse', ...
'XTick', [], ...
'YDir', 'normal', ...
'YTick', [], ...
'Tag', 'image');
% create colorbar axes
h_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 structure
figure_struct = cell2struct({h_axes, h_text, h_button, [], @gray}, ...
{'h_axes', 'h_text', 'h_button', 'h_image', 'color_map'}, 2);
set(h_fig, 'UserData', figure_struct);
return
% DISP_COLORBAR
function [] = disp_colorbar(h_fig, h_axes, color_func)
% obtain colorbar axes
if (istype(h_axes, 'axes'))
axes(h_axes);
h_image = get(h_axes, 'UserData');
else
warning('MATLAB:disp_colorbar', 'unable to find colorbar axes');
return
end
% obtain color map
color_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 colorbar
if (istype(h_image, 'image'))
set(h_image, 'CData', display_map);
else
h_image = image(display_map);
set(h_image, 'EraseMode', 'none', ...
'ButtonDownFcn', 'pvcamfocus(gcf, ''color map'')');
set(h_axes, 'XDir', 'normal', ...
'XTick', [], ...
'YDir', 'normal', ...
'YTick', [], ...
'Tag', 'colorbar', ...
'UserData', h_image);
end
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -