function varargout = imageviewer(varargin) % IMAGEVIEWER - GUI for interactive image browsing % (M-file for imageviewer.fig) % % IMAGEVIEWER, by itself, creates a new IMAGEVIEWER or raises the existing % singleton*. % % H = IMAGEVIEWER returns the handle to a new IMAGEVIEWER or the handle to % the existing singleton*. % % Notes: % ------ % 1.) IMAGEVIEWER is based on several other routines developed at PSI: % - imageread.m % - medianfilter.m % - pilatus.m % - setroi.m % - readscanlog.m % In order for IMAGEVIEWER to run properly, all the above routines % must be available and accessible through MATLABS working path. % Use 'addpath' to add the corresponding directory where the files % are saved to MATLAB's current working path. % % 2.) IMAGEVIEWER was developed and tested using MATLAB R2006a. % Backwards compatibility is neither expected nor guaranteed. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % IMAGEREAD, MEDIANFILTER, PILATUS, SETROI, READSCANLOG % ADDPATH % Edit the above text to modify the response to help imageviewer % Last Modified by GUIDE v2.5 18-Oct-2006 14:56:02 %========================================================================== % Further info for function IMAGEVIEWER % ------------------------------------- % % CVS-Info: % --------- % $Date: 2006/12/05 16:57:16 $ % $Author: schlepuetz $ % $Revision: 1.3 $ % $Source: /import/cvs/X/PILATUS/X04SA/App/lib/X_PILATUS_X04SA_Matlab/imageviewer.m,v $ % $Tag: $ % % Author(s): C.M. Schlepuetz (CS) % Address: Surface Diffraction Station % Materials Science Beamline X04SA % Swiss Light Source (SLS) % Paul Scherrer Institut % CH - 5232 Villigen PSI % Created: 2006/10/17 % % Change Log: % ----------- % % 2006/10/17 (CS): % - first version of this file % % 2006/10/18 (CS): % - implemented separated autoscaling for min, max, gamma % - fixed bug in edit_image_depth % - fixed bug with rescaling the image when changing the image dimensions. %######################################################################### % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @imageviewer_OpeningFcn, ... 'gui_OutputFcn', @imageviewer_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT %######################################################################### %------------------------------------------------------------------------- % --- Executes just before imageviewer is made visible. function imageviewer_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to imageviewer (see VARARGIN) % Choose default command line output for imageviewer handles.output = hObject; % ------------------------------------------------------------------ % add some struct arrays to store handle data in an organized manner handles.data = struct(... 'image_dim',{[487 195]},... 'image',{''},... 'filter_image',{''},... 'disp_image',{''},... 'image_cdepth',{32},... 'scanlog',{''},... 'scanlogheader',{''},... 'npoints',{0}); handles.files = struct(... 'image',{''},... 'imagepath',{''},... 'image_file_format',{'image_%05d.img'},... 'scanlogfile',{''},... 'scanlogpath',{''},... 'list_scan_files',{0},... 'file_filter',{'*.img'},... 'cwdir',{''}); handles.image_control = struct(... 'gamma',{1},... 'max',{56535},... 'min',{0},... 'caxis',{''},... 'colormap',{'jet'},... 'filter',{'none'},... 'autoscale_max',{1},... 'autoscale_min',{1},... 'autoscale_gamma',{0},... 'slider_max',{56535},... 'slider_min',{0}); handles.roi = struct(... 'roi',{ones([handles.data.image_dim(2) handles.data.image_dim(1)])},... 'roi_color',{[1 0 0]}); handles.figures.view_scanlogfile.text_scanlog = struct(... 'figure',{0},... 'text_scanlog',{0}); handles.data.image = ones([handles.data.image_dim(2) handles.data.image_dim(1)]); %------------------------------------- % populate the axes with image objects. ydim = handles.data.image_dim(1); xdim = handles.data.image_dim(2); handles.image_zoom_image = image(zeros([xdim ydim]),... 'Tag','image_zoom_image',... 'CDataMapping','scaled',... 'Parent', handles.axes_zoom_image); handles.image_colorbar = imagesc(ones([1024 1]),... 'Tag','image_colorbar',... 'CDataMapping','direct',... 'Parent', handles.axes_colorbar); set(handles.axes_colorbar,'YDir','normal'); % prepare the image scroll panel and set magnification to 400% handles.zoom_image_scrollpanel = imscrollpanel(handles.uipanel_zoom_image,... handles.image_zoom_image); set(handles.zoom_image_scrollpanel,... 'Clipping','on',... 'Units','normalized',... 'Position',[0 .1 1 .9]) scrollapi = iptgetapi(handles.zoom_image_scrollpanel); handles.zoom_image_scrollpanel_api = scrollapi; scrollapi.setMagnification(4); % create the image magnification box axes(handles.axes_zoom_image); handles.zoom_image_magbox = immagbox(handles.uipanel_zoom_image,... handles.image_zoom_image); set(handles.zoom_image_magbox,... 'Units','normalized',... 'Position',[0.1 0 0.2 0.1]); % create the pixel information tool handles.zoom_image_pixinf = impixelinfoval(handles.uipanel_zoom_image,... [handles.image_zoom_image]); set(handles.zoom_image_pixinf,... 'Units','normalized',... 'FontSize',12,... 'Position',[0.41 0 0.5 0.08]); % create the image overview panel inside the Image Overview uipanel handles.uipanel_image_overview = imoverviewpanel(handles.uipanel_original_image,... handles.image_zoom_image); set(handles.uipanel_image_overview,'Units','Normalized',... 'Position',[0.015 0 0.8 1]); % get handles of axis and image object inside the overview panel % 1) axis handles.axes_original_image = findobj(handles.uipanel_image_overview,... 'Type','axes'); set(handles.axes_original_image,'Tag','axes_original_image'); % 2) image handles.image_original_image = findobj(handles.axes_original_image,... 'Type','image'); set(handles.image_original_image,'Tag','image_original_image'); % Update handles structure guidata(hObject, handles); % make sure that a colormap is ready at startup popupmenu_colormap_Callback(handles.popupmenu_colormap, eventdata, handles) % position figure at upper left corner of screen set(0,'Units','Pixels') screen_pos = get(0,'ScreenSize'); set(hObject,'Units','Pixels') fig_pos = get(hObject,'Position'); set(hObject,'Position',[10 screen_pos(4)-fig_pos(4)-50 fig_pos(3) fig_pos(4)]) % UIWAIT makes imageviewer wait for user response (see UIRESUME) % uiwait(handles.figure_imageviewer); %------------------------------------------------------------------------- % --- Outputs from this function are returned to the command line. function varargout = imageviewer_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; %========================================================================= % Object callbacks, CreateFcn, etc. %========================================================================= %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function axes_original_image_CreateFcn(hObject, eventdata, handles) % hObject handle to axes_original_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate axes_original_image %------------------------------------------------------------------------- function edit_scanlogfile_Callback(hObject, eventdata, handles) % hObject handle to edit_scanlogfile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_scanlogfile as text % str2double(get(hObject,'String')) returns contents of edit_scanlogfile as a double [path,base,ext] = fileparts(get(hObject,'String')); % check if directory exists if ~isdir(strcat(path,filesep)) errordlg('directory does not exist','Directory error','on'); return end handles.files.scanlogpath = strcat(path,filesep); % check if scanlogfile exists if ~exist(strcat(path,filesep,base,ext),'file') errordlg('file does not exist','File error','on') return end handles.files.scanlogfile = strcat(base,ext); scanlog = strcat(path,filesep,base,ext); [handles.data.scanlog,handles.data.scanlogheader]=readscanlog(scanlog); data_dim = size(handles.data.scanlog); handles.data.npoints = data_dim(1); set(handles.popupmenu_image_column,'String',handles.data.scanlogheader') % try to guess correct values for image data column if any(strcmp('ID', handles.data.scanlogheader)) set(handles.popupmenu_image_column,'Value',... find(strcmp('ID', handles.data.scanlogheader))); elseif any(strcmp('image', handles.data.scanlogheader)) set(handles.popupmenu_image_column,'Value',... find(strcmp('image', handles.data.scanlogheader))); end % update handles guidata(handles.figure_imageviewer,handles) % try to guess image path based on standard directory structure if ~isdir(handles.files.imagepath) imdir = fileparts(fileparts(fileparts(handles.files.scanlogpath))); imdir = strcat(imdir,filesep,'pixel',filesep,'images'); if isdir(imdir) set(handles.edit_imagepath,'String',imdir) edit_imagepath_Callback(handles.edit_imagepath, eventdata, handles) end end % update handles structure, otherwise the one passed to this function % will be used which does not contain the changes made by % fcn_image_autoscale. handles = guidata(handles.figure_imageviewer); % call the rescan pushbutton callback function to update imagelist. pushbutton_rescan_images_Callback(handles.pushbutton_rescan_images, ... eventdata, handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_scanlogfile_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_scanlogfile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_browse_scanlogfile. function pushbutton_browse_scanlogfile_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_browse_scanlogfile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if isdir(handles.files.scanlogpath) uigetfile_filter = strcat(handles.files.scanlogpath,'*.dat'); elseif isdir(handles.files.imagepath) scanlogdir = fileparts(fileparts(handles.files.imagepath)); scanlogdir = [scanlogdir filesep 'spec' filesep 'scanlogs' filesep]; if isdir(scanlogdir) uigetfile_filter = strcat(scanlogdir,'*.dat'); else uigetfile_filter = '*.dat'; end else uigetfile_filter = '*.dat'; end [filename, path] = uigetfile(uigetfile_filter); % don't do anything if user clicked Cancel if isequal(filename,0) return end set (handles.edit_scanlogfile,'String',strcat(path,filename)); edit_scanlogfile_Callback(handles.edit_scanlogfile,eventdata,handles) %------------------------------------------------------------------------- % --- Executes on selection change in listbox_select_scanimage. function listbox_select_scanimage_Callback(hObject, eventdata, handles) % hObject handle to listbox_select_scanimage (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox_select_scanimage contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox_select_scanimage contents = get(hObject,'String'); imagename = contents(get(hObject,'Value'),:); imagefile = strcat(handles.files.imagepath,imagename); % retrieve file format [pathstr, name, ext] = fileparts(imagefile); switch ext case '.img' imageformat = 'img'; case {'.tif','.tiff'} imageformat = 'tif'; case '.edf' imageformat = 'edf'; case '.ff' imageformat = 'ff'; otherwise errordlg('image has invalid extension','File format error','on'); return end imagedata = imageread(imagefile, imageformat,... handles.data.image_dim,handles.data.image_cdepth); handles.data.image = imagedata; % update navigation tools: set(handles.edit_nofm,'String',... sprintf('%d',get(hObject,'Value'))); % update handles guidata(handles.figure_imageviewer,handles) popupmenu_filter_Callback(handles.popupmenu_filter, eventdata, handles) fcn_update_image_info(handles.figure_imageviewer, eventdata, handles) fcn_update_roi_info(handles.figure_imageviewer, eventdata, handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function listbox_select_scanimage_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox_select_scanimage (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_image_xdim_Callback(hObject, eventdata, handles) % hObject handle to edit_image_xdim (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_image_xdim as text % str2double(get(hObject,'String')) returns contents of edit_image_xdim as a double xdim = str2double(get(hObject,'String')); if xdim ~= floor(xdim) errordlg('xdim must be integer number','Value error','on'); return else handles.data.image_dim(1) = uint32(xdim); guidata(handles.figure_imageviewer,handles) end %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_image_xdim_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_image_xdim (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_image_ydim_Callback(hObject, eventdata, handles) % hObject handle to edit_image_ydim (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_image_ydim as text % str2double(get(hObject,'String')) returns contents of edit_image_ydim as a double ydim = str2double(get(hObject,'String')); if ydim ~= floor(ydim) errordlg('ydim must be integer number','Value error','on'); return else handles.data.image_dim(2) = uint32(ydim); guidata(handles.figure_imageviewer,handles) end %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_image_ydim_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_image_ydim (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_image_depth_Callback(hObject, eventdata, handles) % hObject handle to edit_image_depth (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_image_depth as text % str2double(get(hObject,'String')) returns contents of edit_image_depth as a double depth = str2double(get(hObject,'String')); if ~(any(depth == [8 16 32 64])) errordlg('color depth can only be: 8, 16, 32, or 64','Value error','on'); return else handles.data.image_cdepth = uint32(depth); guidata(handles.figure_imageviewer,handles) end %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_image_depth_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_image_depth (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_navigation_begin. function pushbutton_navigation_begin_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_begin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.listbox_select_scanimage,'Value',1); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_navigation_minusn. function pushbutton_navigation_minusn_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_minusn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) currentpoint = get(handles.listbox_select_scanimage,'Value'); point = currentpoint - ... int32(str2double(get(handles.edit_navigation_stepn,'String'))); % restrict to allowed values if out of bounds if point < 1 point =1; elseif point > handles.data.npoints point = handles.data.npoints; end set(handles.listbox_select_scanimage,'Value',point); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_navigation_previous. function pushbutton_navigation_previous_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_previous (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) currentpoint = get(handles.listbox_select_scanimage,'Value'); point = currentpoint - 1; % restrict to allowed values if out of bounds if point < 1 point =1; elseif point > handles.data.npoints point = handles.data.npoints; end set(handles.listbox_select_scanimage,'Value',point); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_navigation_next. function pushbutton_navigation_next_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_next (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) currentpoint = get(handles.listbox_select_scanimage,'Value'); point = currentpoint + 1; % restrict to allowed values if out of bounds if point < 1 point =1; elseif point > handles.data.npoints point = handles.data.npoints; end set(handles.listbox_select_scanimage,'Value',point); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_navigation_plusn. function pushbutton_navigation_plusn_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_plusn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) currentpoint = get(handles.listbox_select_scanimage,'Value'); point = currentpoint + ... int32(str2double(get(handles.edit_navigation_stepn,'String'))); % restrict to allowed values if out of bounds if point < 1 point =1; elseif point > handles.data.npoints point = handles.data.npoints; end set(handles.listbox_select_scanimage,'Value',point); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_navigation_end. function pushbutton_navigation_end_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_end (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.listbox_select_scanimage,'Value',handles.data.npoints); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- function edit_navigation_stepn_Callback(hObject, eventdata, handles) % hObject handle to edit_navigation_stepn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_navigation_stepn as text % str2double(get(hObject,'String')) returns contents of edit_navigation_stepn as a double %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_navigation_stepn_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_navigation_stepn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on slider movement. function slider_gamma_Callback(hObject, eventdata, handles) % hObject handle to slider_gamma (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider slipos = get (hObject, 'Value'); gamma = 10^slipos; set (handles.edit_gamma, 'String', num2str (gamma, '% 2.4g')); edit_gamma_Callback(handles.edit_gamma,eventdata,handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function slider_gamma_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_gamma (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end %------------------------------------------------------------------------- % --- Executes on slider movement. function slider_intensity_max_Callback(hObject, eventdata, handles) % hObject handle to slider_intensity_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider slipos = get (hObject, 'Value'); set (handles.edit_intensity_max, 'String', num2str (slipos, '%.0f')); edit_intensity_max_Callback(handles.edit_intensity_max,eventdata,handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function slider_intensity_max_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_intensity_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end %------------------------------------------------------------------------- % --- Executes on slider movement. function slider_intensity_min_Callback(hObject, eventdata, handles) % hObject handle to slider_intensity_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider slipos = get (hObject, 'Value'); set (handles.edit_intensity_min, 'String', num2str (slipos, '%.0f')); edit_intensity_min_Callback(handles.edit_intensity_min,eventdata,handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function slider_intensity_min_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_intensity_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end %------------------------------------------------------------------------- % --- Executes on selection change in popupmenu_filter. function popupmenu_filter_Callback(hObject, eventdata, handles) % hObject handle to popupmenu_filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu_filter contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu_filter contents = get(hObject, 'String'); imagefilter = contents{get(hObject, 'Value')}; % apply ff-data to the original image % do that here... % handles.data.filter_image = handles.data.image * ffdata; handles.data.filter_image = handles.data.image; % then apply filter switch imagefilter case '3x3 median' handles.data.filter_image = medianfilter(handles.data.filter_image, ... [3 3], -1, [], [], 'median'); case '3x3 mean' handles.data.filter_image = medianfilter(handles.data.filter_image, ... [3 3], -1, [], [], 'mean'); case 'no filter' % don't do anything... end % update handles guidata(handles.figure_imageviewer,handles) % call function to display the image fcn_image_display(handles.figure_imageviewer, eventdata, handles) % apply image control parameters fcn_image_control(hObject, eventdata, handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function popupmenu_filter_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu_filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on button press in checkbox_autoscale_max. function checkbox_autoscale_max_Callback(hObject, eventdata, handles) % hObject handle to checkbox_autoscale_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox_autoscale_max auto = get(hObject,'Value'); % update handles handles.image_control.autoscale_max = auto; guidata(handles.checkbox_autoscale_max,handles) if auto fcn_image_control(handles.checkbox_autoscale_max, eventdata, handles) end %------------------------------------------------------------------------- % --- Executes on button press in checkbox_autoscale_gamma. function checkbox_autoscale_gamma_Callback(hObject, eventdata, handles) % hObject handle to checkbox_autoscale_gamma (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox_autoscale_gamma auto = get(hObject,'Value'); % update handles handles.image_control.autoscale_gamma = auto; guidata(handles.checkbox_autoscale_gamma,handles) if auto fcn_image_control(handles.figure_imageviewer, eventdata, handles) end %------------------------------------------------------------------------- % --- Executes on button press in checkbox_autoscale_min. function checkbox_autoscale_min_Callback(hObject, eventdata, handles) % hObject handle to checkbox_autoscale_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox_autoscale_min auto = get(hObject,'Value'); % update handles handles.image_control.autoscale_min = auto; guidata(handles.checkbox_autoscale_min,handles) if auto fcn_image_control(handles.figure_imageviewer, eventdata, handles) end %------------------------------------------------------------------------- function edit_intensity_range_min_Callback(hObject, eventdata, handles) % hObject handle to edit_intensity_range_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_intensity_range_min as text % str2double(get(hObject,'String')) returns contents of edit_intensity_range_min as a double slider_range_min = str2double(get(hObject,'String')); % make sure slider_range_min is lower than value of min-slider and bigger % than zero slider_min_val = str2double(get(handles.edit_intensity_min,'String')); slider_range_min = max([0 slider_range_min]); slider_range_min = min([slider_min_val slider_range_min]); % update string and slider ranges set (hObject,'String',slider_range_min); set (handles.slider_intensity_min,'Min',slider_range_min) set (handles.slider_intensity_max,'Min',slider_range_min) % update handles handles.image_control.slider_min = slider_range_min; guidata(handles.edit_intensity_range_min,handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_intensity_range_min_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_intensity_range_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_intensity_range_max_Callback(hObject, eventdata, handles) % hObject handle to edit_intensity_range_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_intensity_range_max as text % str2double(get(hObject,'String')) returns contents of edit_intensity_range_max as a double slider_range_max = str2double(get(hObject,'String')); % make sure slider_range_max is higher than value of max-slider slider_max_val = str2double(get(handles.edit_intensity_max,'String')); slider_range_max = max([slider_range_max slider_max_val]); % update string and slider ranges set(hObject,'String',slider_range_max); set (handles.slider_intensity_min,'Max',slider_range_max); set (handles.slider_intensity_max,'Max',slider_range_max); % update handles handles.image_control.slider_max = slider_range_max; guidata(handles.edit_intensity_range_max,handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_intensity_range_max_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_intensity_range_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_gamma_Callback(hObject, eventdata, handles) % hObject handle to edit_gamma (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_gamma as text % str2double(get(hObject,'String')) returns contents of edit_gamma as a double % deactivate auto-scaling set(handles.checkbox_autoscale_gamma,'Value',0); checkbox_autoscale_gamma_Callback(handles.checkbox_autoscale_gamma, ... eventdata, handles) gamma = str2double(get(hObject,'String')); % restrict to values between 0.1 and 10 gamma = max([gamma 0.1]); gamma = min([gamma 10]); set(hObject,'String',gamma) handles.image_control.gamma = gamma; % update slider value set(handles.slider_gamma,'Value',log10(gamma)); % update handles guidata(handles.figure_imageviewer,handles) % redisplay image fcn_image_control(handles.figure_imageviewer, eventdata, handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_gamma_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_gamma (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_intensity_max_Callback(hObject, eventdata, handles) % hObject handle to edit_intensity_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_intensity_max as text % str2double(get(hObject,'String')) returns contents of edit_intensity_max as a double % deactivate auto-scaling set(handles.checkbox_autoscale_max,'Value',0); checkbox_autoscale_max_Callback(handles.checkbox_autoscale_max, ... eventdata, handles) int_max = str2double(get(hObject,'String')); int_min_val = str2double(get(handles.edit_intensity_min,'String')); % make sure int_max is larger than the value for int_min int_max = max([int_min_val+1 int_max]); % adjust slider ranges if value is out of bounds slider_min = str2double(get(handles.edit_intensity_range_min,'String')); slider_max = str2double(get(handles.edit_intensity_range_max,'String')); if int_max < slider_min set(handles.edit_intensity_range_min,'String',int_max) edit_intensity_range_min_Callback(handles.edit_intensity_range_min,... eventdata,handles) elseif int_max > slider_max set(handles.edit_intensity_range_max,'String',int_max) edit_intensity_range_max_Callback(handles.edit_intensity_range_max,... eventdata,handles) end handles.image_control.max = int_max; % update strint and slider value set(handles.edit_intensity_max,'String',int_max); set(handles.slider_intensity_max,'Value',int_max); % update handles guidata(handles.figure_imageviewer,handles) % redisplay image fcn_image_control(handles.figure_imageviewer, eventdata, handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_intensity_max_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_intensity_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_intensity_min_Callback(hObject, eventdata, handles) % hObject handle to edit_intensity_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_intensity_min as text % str2double(get(hObject,'String')) returns contents of edit_intensity_min as a double % deactivate auto-scaling set(handles.checkbox_autoscale_min,'Value',0); checkbox_autoscale_min_Callback(handles.checkbox_autoscale_min, ... eventdata, handles) int_min = str2double(get(hObject,'String')); int_max_val = str2double(get(handles.edit_intensity_max,'String')); % make sure int_min is between 0 and the value for int_max int_min = max([0 int_min]); int_min = min([int_min int_max_val-1]); % adjust slider ranges if value is out of bounds slider_min = str2double(get(handles.edit_intensity_range_min,'String')); slider_max = str2double(get(handles.edit_intensity_range_max,'String')); if int_min < slider_min set(handles.edit_intensity_range_min,'String',int_min) edit_intensity_range_min_Callback(handles.edit_intensity_range_min,... eventdata,handles) elseif int_min > slider_max set(handles.edit_intensity_range_max,'String',int_min) edit_intensity_range_max_Callback(handles.edit_intensity_range_max,... eventdata,handles) end handles.image_control.min = int_min; % update slider and string value set(handles.edit_intensity_min,'String',int_min); set(handles.slider_intensity_min,'Value',int_min); % update handles guidata(handles.figure_imageviewer,handles) % redisplay image fcn_image_control(handles.figure_imageviewer, eventdata, handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_intensity_min_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_intensity_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_zoom_out. function pushbutton_zoom_out_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_zoom_out (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) scrollapi = handles.zoom_image_scrollpanel_api; mag = scrollapi.getMagnification(); mag = max([0.25 mag/2]); scrollapi.setMagnification(mag); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_zoom_in. function pushbutton_zoom_in_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_zoom_in (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) scrollapi = handles.zoom_image_scrollpanel_api; mag = scrollapi.getMagnification(); mag = min([100 mag*2]); scrollapi.setMagnification(mag); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_zoom_area. function pushbutton_zoom_area_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_zoom_area (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %------------------------------------------------------------------------- % --- Executes on selection change in popupmenu_colormap. function popupmenu_colormap_Callback(hObject, eventdata, handles) % hObject handle to popupmenu_colormap (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu_colormap contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu_colormap contents = get(hObject,'String'); cmap = contents{get(hObject,'Value')}; cmap = [cmap '(1024)']; handles.image_control.colormap = colormap(cmap); % adjust colorbar gamma = handles.image_control.gamma; cmap_dim = size(handles.image_control.colormap); set(handles.axes_colorbar,'YLim',[0 cmap_dim(1)]); cbardata = (0:1:cmap_dim(1))'; cbardata = cbardata;%.^(gamma); set(handles.image_colorbar,'CData',cbardata,'CDataMapping','scaled'); % update handles guidata(hObject,handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function popupmenu_colormap_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu_colormap (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function pushbutton_navigation_begin_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_begin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function pushbutton_navigation_minusn_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_minusn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function pushbutton_navigation_previous_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_previous (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function pushbutton_navigation_next_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_next (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function pushbutton_navigation_plusn_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_plusn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function pushbutton_navigation_end_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_navigation_end (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called %------------------------------------------------------------------------- function edit_nofm_Callback(hObject, eventdata, handles) % hObject handle to edit_nofm (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_nofm as text % str2double(get(hObject,'String')) returns contents of edit_nofm as a double point = int32(str2double(get(hObject,'String'))); % restrict to allowed values if out of bounds if point < 1 point =1; elseif point > handles.data.npoints point = handles.data.npoints; end set(handles.listbox_select_scanimage,'Value',point); % call listbox callback listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata,handles); %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_nofm_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_nofm (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- function edit_imagepath_Callback(hObject, eventdata, handles) % hObject handle to edit_imagepath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_imagepath as text % str2double(get(hObject,'String')) returns contents of edit_imagepath as a double imagepath = get(hObject,'String'); % check if directory exists if ~isdir(imagepath) errordlg('directory does not exist','Directory error','on'); return end if ~strcmp(imagepath(length(imagepath)),filesep) imagepath = strcat(imagepath,filesep); set(hObject,'String',imagepath); end handles.files.imagepath = imagepath; % update handles guidata(handles.figure_imageviewer,handles) pushbutton_rescan_images_Callback(handles.pushbutton_rescan_images, eventdata, handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_imagepath_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_imagepath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_browse_imagepath. function pushbutton_browse_imagepath_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_browse_imagepath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if isdir(handles.files.imagepath) && ... (strcmp(handles.files.imagepath,filesep)==0) uigetdir_startpath = handles.files.imagepath; elseif isdir(handles.files.scanlogpath) imagedir = fileparts(fileparts(fileparts(handles.files.scanlogpath))); imagedir = [imagedir filesep 'pixel' filesep 'images' filesep]; if isdir(imagedir) uigetdir_startpath = imagedir; else uigetdir_startpath = handles.files.scanlogpath; end else uigetdir_startpath = pwd; end imagepath = uigetdir(uigetdir_startpath,'Select image path'); % don't do anything if user clicked Cancel if isequal(imagepath,0) return else imagepath = strcat(imagepath,filesep); set (handles.edit_imagepath,'String',imagepath) edit_imagepath_Callback(handles.edit_imagepath,eventdata,handles) end %------------------------------------------------------------------------- function edit_image_file_format_Callback(hObject, eventdata, handles) % hObject handle to edit_image_file_format (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_image_file_format as text % str2double(get(hObject,'String')) returns contents of edit_image_file_format as a double image_file_format = get(hObject,'String'); % % here we should check whether syntax is valid... % i.e. whether it contains a %0Xd string. % handles.files.image_file_format = image_file_format; % update handles guidata(handles.figure_imageviewer,handles) % call the rescan pushbutton callback function to update filelist. pushbutton_rescan_images_Callback(handles.pushbutton_rescan_images, eventdata, handles) %------------------------------------------------------------------------- % --- Executes during object creation, after setting all properties. function edit_image_file_format_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_image_file_format (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_show_scanlog. function pushbutton_show_scanlog_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_show_scanlog (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.figures.view_scanlogfile.figure = ... figure('Name','view_scanlogfile',... 'ResizeFcn',@fcn_view_scanlogfile_ResizeFcn); pos = get(handles.figures.view_scanlogfile.figure,'Position'); text_handle = uicontrol(handles.figures.view_scanlogfile.figure,... 'style','listbox','Position',[0 0 pos(3) pos(4)],... 'horizontalAlignment','left',... 'FontName', 'FixedWidth',... 'FontSize',9,... 'Tag','text_view_scanlogfile',... 'max',20,'min',1); handles.figures.view_scanlogfile.text_scanlog = text_handle; %------------------------------- % find out maximum column widths col_width = zeros(size(handles.data.scanlogheader)); data_dim = size(handles.data.scanlog); % 1. header line for i=1:length(handles.data.scanlogheader) col_width(i) = length(handles.data.scanlogheader{i}); end % 2. data section for i=1:data_dim(2) data_string = []; for j=1:data_dim(1) data_string = strvcat(data_string,... sprintf('%g ',handles.data.scanlog(j,i))); end data_string_size = size(data_string); col_width(i) = max([col_width(i) data_string_size(2)]); end %---------------------------- % build formatted data string % build header line from handles.data.scanlogheader char array header_string = ''; for i=1:length(handles.data.scanlogheader) format_tag = sprintf('%%%ds ',col_width(i)); header_string = [header_string sprintf(format_tag,... handles.data.scanlogheader{i})]; end header_string = char(header_string); % print formatted data lines from handles.data.scanlog data_string = []; for i=1:data_dim(2) data_string_col = []; for j=1:data_dim(1) format_tag = sprintf('%%%dg ',col_width(i)); data_string_col = strvcat(data_string_col,... sprintf(format_tag,handles.data.scanlog(j,i))); end data_string = [data_string data_string_col]; end % display scanlogfile in the text field set(handles.figures.view_scanlogfile.text_scanlog,... 'String',strvcat(header_string, data_string)); %------------------------------------------------------------------------- % --- Resize function for the scanlog preview window. function fcn_view_scanlogfile_ResizeFcn(hObject, eventdata, handles) pos=get(gcbo,'Position'); set(findobj('Tag','text_view_scanlogfile'),'Position',[0 0 pos(3) pos(4)]); %------------------------------------------------------------------------- % --- Executes on button press in pushbutton_rescan_images. function pushbutton_rescan_images_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_rescan_images (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) imagepath = handles.files.imagepath; image_file_format = handles.files.image_file_format; image_list_string = []; listbox_ok = 1; % rescale image axes in case image dimension changed set(handles.axes_original_image,'Xlim',[1 handles.data.image_dim(1)]) set(handles.axes_original_image,'Ylim',[1 handles.data.image_dim(2)]) set(handles.axes_zoom_image,'Xlim',[1 handles.data.image_dim(1)]) set(handles.axes_zoom_image,'Ylim',[1 handles.data.image_dim(2)]) % scan image directory or scanlogfile for images switch handles.files.list_scan_files % display all images in image directory case 0 file_list = dir(fullfile(imagepath,handles.files.file_filter)); npoints = length(file_list); handles.data.npoints = npoints; if npoints < 1 image_list_string = sprintf('Could not find any images: %s',... fullfile(imagepath,handles.files.file_filter)); npoints = 1; listbox_ok = 0; errmsg = sprintf('No image files found in directory\n%s',... fullfile(imagepath,handles.files.file_filter)); else for i=1:npoints image_list_string = ... strvcat(image_list_string, file_list(i).name); end end % display only images in scanlog case 1 npoints = handles.data.npoints; imagecol = get(handles.popupmenu_image_column,'Value'); imagenumbers = handles.data.scanlog(:,imagecol); for i=1:npoints imagefilename = sprintf(image_file_format,imagenumbers(i)); % check whether file exists, then add to list. if ~exist(strcat(imagepath,imagefilename),'file') image_list_string = sprintf('Could not find image: %s',... strcat(imagepath,imagefilename)); listbox_ok = 0; errmsg = ... sprintf('Error reading images in scanlog\n%s%s',... handles.files.scanlogpath, handles.files.scanlogfile); else image_list_string = ... strvcat(image_list_string, imagefilename); end end end set(handles.listbox_select_scanimage,'String',... image_list_string); % update handles guidata(handles.figure_imageviewer,handles) % set new listbox value if current one is out of bounds. if get(handles.listbox_select_scanimage,'Value') > npoints set(handles.listbox_select_scanimage,'Value',npoints); end % update navigation tools: set(handles.text_nimages,'String',sprintf('of %d',npoints)); set(handles.edit_nofm,'String',... sprintf('%d',get(handles.listbox_select_scanimage,'Value'))); % display current image if listbox_ok listbox_select_scanimage_Callback(handles.listbox_select_scanimage,... eventdata, handles); else errordlg(errmsg,'Image file error','on'); end %========================================================================= % Additional functions %========================================================================= %------------------------------------------------------------------------- % --- apply changes to the displayed image. function fcn_image_control(hObject, eventdata, handles) % perform auto-scaling if selected auto = [get(handles.checkbox_autoscale_min,'Value'),... get(handles.checkbox_autoscale_max,'Value'),... get(handles.checkbox_autoscale_gamma,'Value')]; if any(auto) fcn_image_autoscale(handles.figure_imageviewer, eventdata, handles) % update handles structure, otherwise the one passed to this function % will be used which does not contain the changes made by % fcn_image_autoscale. handles = guidata(hObject); end gamma = handles.image_control.gamma; int_min = handles.image_control.min; int_max = handles.image_control.max; cmap = handles.image_control.colormap; cmap_dim = size(cmap); cind = ((1:cmap_dim(1))-1)./(cmap_dim(1)-1); cind = cind.^gamma; cind = round(cind.*(cmap_dim(1)-1))+1; cmap = handles.image_control.colormap(cind,:); colormap(cmap); % change caxis of colorbar nticks = length(get(handles.axes_colorbar,'YTick')); ticks = linspace(int_min,int_max,nticks); ticks = ((((ticks-int_min)./(int_max-int_min)).^(1/gamma)).*... (int_max-int_min))+int_min; set(handles.axes_colorbar,'YTickLabel',ticks); % adjust colorbar cmap_dim = size(handles.image_control.colormap); set(handles.axes_colorbar,'YLim',[0 cmap_dim(1)]); cbardata = (0:1:cmap_dim(1))'; cbardata = cbardata.^(1/gamma); set(handles.image_colorbar,'CData',cbardata,'CDataMapping','scaled'); % change caxis of overview image axes(handles.axes_original_image); caxis([int_min int_max]); % change caxis of zoom image axes(handles.axes_zoom_image); caxis([int_min int_max]); % update handles guidata(handles.figure_imageviewer,handles) %------------------------------------------------------------------------- % --- display the entire image. function fcn_image_display(hObject, eventdata, handles) set(handles.image_original_image,'CData',handles.data.filter_image); set(handles.image_zoom_image,'CData',handles.data.filter_image); %------------------------------------------------------------------------- % --- perform autoscaling of image. function fcn_image_autoscale(hObject, eventdata, handles) auto_max = get(handles.checkbox_autoscale_max,'Value'); auto_min = get(handles.checkbox_autoscale_min,'Value'); auto_gamma = get(handles.checkbox_autoscale_gamma,'Value'); int_min = handles.image_control.min; int_max = handles.image_control.max; gamma = handles.image_control.gamma; I = handles.data.filter_image; scale = max(max(I)); I = I./scale; int_lim = stretchlim(I,[0.00005 0.99995]); if auto_min int_min = floor(int_lim(1)*scale); end if auto_max int_max = ceil(int_lim(2)*scale); end if auto_gamma temp_img = imadjust(I,int_lim); [temp_img2,Ty] = histeq(temp_img); Tx = (1:length(Ty))./length(Ty); % fit gamma value to the equalized histogram optimset('Display','off','LargeScale','off','TolFun',1e-4); minfunc = @(g,x,y)sum(((x.^g)-y).^2); gamma = fminsearch(@(g) minfunc(g,Tx,Ty),0.5); % restrict gamma to values between 0.1 and 10 gamma = max([gamma 0.1]); gamma = min([gamma 10]); end %---------------------------------------- % update all slider and edit text values: slider_min = str2double(get(handles.edit_intensity_range_min,'String')); slider_max = str2double(get(handles.edit_intensity_range_max,'String')); % 1. Intensity minimum: % adjust slider ranges if value is out of bounds if int_min < slider_min set(handles.edit_intensity_range_min,'String',int_min) edit_intensity_range_min_Callback(handles.edit_intensity_range_min,... eventdata,handles) elseif int_min > slider_max set(handles.edit_intensity_range_max,'String',int_min) edit_intensity_range_max_Callback(handles.edit_intensity_range_max,... eventdata,handles) end % update string and slider values handles.image_control.min = int_min; set(handles.edit_intensity_min,'String',int_min); set(handles.slider_intensity_min,'Value',int_min); guidata(handles.figure_imageviewer,handles); % 2. Intensity maximum: % adjust slider ranges if value is out of bounds if int_max < slider_min set(handles.edit_intensity_range_min,'String',int_max) edit_intensity_range_min_Callback(handles.edit_intensity_range_min,... eventdata,handles) elseif int_max > slider_max set(handles.edit_intensity_range_max,'String',int_max) edit_intensity_range_max_Callback(handles.edit_intensity_range_max,... eventdata,handles) end % update string and slider value handles.image_control.max = int_max; set(handles.edit_intensity_max,'String',int_max); set(handles.slider_intensity_max,'Value',int_max); guidata(handles.figure_imageviewer,handles); % 3. gamma value: % update string and slider value handles.image_control.gamma = gamma; set(handles.edit_gamma,'String',gamma) set(handles.slider_gamma,'Value',log10(gamma)); guidata(handles.figure_imageviewer,handles); % --- Executes during object creation, after setting all properties. function text_label_intensity_min_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_intensity_min (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_intensity_max_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_intensity_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_gamma_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_gamma (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function checkbox_autoscale_max_CreateFcn(hObject, eventdata, handles) % hObject handle to checkbox_autoscale_max (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_image_info_CreateFcn(hObject, eventdata, handles) % hObject handle to text_image_info (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function uipanel_imagecontrol_CreateFcn(hObject, eventdata, handles) % hObject handle to uipanel_imagecontrol (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function uipanel_zoom_image_CreateFcn(hObject, eventdata, handles) % hObject handle to uipanel_zoom_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function axes_zoom_image_CreateFcn(hObject, eventdata, handles) % hObject handle to axes_zoom_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate axes_zoom_image % --- Executes during object creation, after setting all properties. function axes_colorbar_CreateFcn(hObject, eventdata, handles) % hObject handle to axes_colorbar (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate axes_colorbar % --- Executes during object creation, after setting all properties. function uipanel_original_image_CreateFcn(hObject, eventdata, handles) % hObject handle to uipanel_original_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton_zoom_out_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_zoom_out (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton_zoom_in_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_zoom_in (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_navigation_n_CreateFcn(hObject, eventdata, handles) % hObject handle to text_navigation_n (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_nimages_CreateFcn(hObject, eventdata, handles) % hObject handle to text_nimages (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function uipanel_navigation_CreateFcn(hObject, eventdata, handles) % hObject handle to uipanel_navigation (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_scanlog_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_scanlog (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton_browse_scanlogfile_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_browse_scanlogfile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton_show_scanlog_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_show_scanlog (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_imagepath_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_imagepath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton_browse_imagepath_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_browse_imagepath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_image_file_format_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_image_file_format (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_horiz_size_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_horiz_size (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_vet_size_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_vet_size (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_bit_depth_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_bit_depth (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton_rescan_images_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_rescan_images (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function text_label_imagelist_CreateFcn(hObject, eventdata, handles) % hObject handle to text_label_imagelist (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes on selection change in popupmenu_image_column. function popupmenu_image_column_Callback(hObject, eventdata, handles) % hObject handle to popupmenu_image_column (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu_image_column contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu_image_column % --- Executes during object creation, after setting all properties. function popupmenu_image_column_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu_image_column (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu_select_roi. function popupmenu_select_roi_Callback(hObject, eventdata, handles) % hObject handle to popupmenu_select_roi (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu_select_roi contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu_select_roi contents = get(hObject,'String'); method = contents{get(hObject,'Value')}; switch method case 'none' if isfield(handles,'line_roi') && ishandle(handles.line_roi) delete(handles.line_roi); end if isfield(handles,'line_roi_overview') && ... ishandle(handles.line_roi_overview) delete(handles.line_roi_overview); end otherwise [MaskImage,x,y] = setroi(handles.axes_zoom_image,method); handles.roi.roi = MaskImage; lineColor = handles.roi.roi_color; % draw line in zoom image axes(handles.axes_zoom_image); hold on; if isfield(handles,'line_roi') && ishandle(handles.line_roi) set(handles.line_roi,'xdata',x,'ydata',y); set(handles.line_roi,'Color',lineColor); else handles.line_roi = plot(x,y,'Color',lineColor,'LineWidth',2); end % draw line in overview image axes(handles.axes_original_image); hold on; if isfield(handles,'line_roi_overview') && ... ishandle(handles.line_roi_overview) set(handles.line_roi_overview,'xdata',x,'ydata',y); set(handles.line_roi_overview,'Color',lineColor); else handles.line_roi_overview = plot(x,y,'Color',lineColor,'LineWidth',2); end end % update handles guidata(handles.figure_imageviewer,handles) fcn_update_roi_info(handles.figure_imageviewer, ... eventdata, handles); % --- Executes during object creation, after setting all properties. function popupmenu_select_roi_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu_select_roi (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in pushbutton_roi_color. function pushbutton_roi_color_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_roi_color (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns pushbutton_roi_color contents as cell array % contents{get(hObject,'Value')} returns selected item from pushbutton_roi_color color = uisetcolor(handles.roi.roi_color,'Select ROI color'); if isequal(color,0) return end if isfield(handles,'line_roi') set(handles.line_roi,'Color',color); end if isfield(handles,'line_roi_overview') set(handles.line_roi_overview,'Color',color); end handles.roi.roi_color = color; % update handles guidata(handles.figure_imageviewer,handles) % --- Executes during object creation, after setting all properties. function pushbutton_roi_color_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton_roi_color (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % -------------------------------------------------------------------- function uipanel_files_and_paths_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to uipanel_files_and_paths (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) selected = get(handles.uipanel_files_and_paths,'SelectedObject'); if selected == handles.radiobutton_files_all handles.files.list_scan_files = 0; set(handles.popupmenu_file_filter,'Enable','on'); set(handles.edit_scanlogfile,'Enable','off'); set(handles.pushbutton_browse_scanlogfile,'Enable','off'); set(handles.text_label_image_col,'Enable','off'); set(handles.popupmenu_image_column,'Enable','off'); set(handles.pushbutton_show_scanlog,'Enable','off'); if isdir(handles.files.imagepath) edit_imagepath_Callback(handles.edit_imagepath,... eventdata,handles); end elseif selected == handles.radiobutton_files_scanlog handles.files.list_scan_files = 1; set(handles.popupmenu_file_filter,'Enable','off'); set(handles.edit_scanlogfile,'Enable','on'); set(handles.pushbutton_browse_scanlogfile,'Enable','on'); set(handles.text_label_image_col,'Enable','on'); set(handles.popupmenu_image_column,'Enable','on'); set(handles.pushbutton_show_scanlog,'Enable','on'); if exist(strcat(handles.files.scanlogpath,handles.files.scanlogfile),... 'file') edit_scanlogfile_Callback(handles.edit_scanlogfile,... eventdata,handles); end end % update handles guidata(handles.figure_imageviewer,handles) % --- Executes on selection change in popupmenu_file_filter. function popupmenu_file_filter_Callback(hObject, eventdata, handles) % hObject handle to popupmenu_file_filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu_file_filter contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu_file_filter contents = get(hObject,'String'); handles.files.file_filter = contents{get(hObject,'Value')}; % update handles guidata(handles.figure_imageviewer,handles) pushbutton_rescan_images_Callback(hObject,eventdata, handles) % --- Executes during object creation, after setting all properties. function popupmenu_file_filter_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu_file_filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %------------------------------------------------------------------------- % --- update the image information text upon change of image info file. function fcn_update_image_info(hObject, eventdata, handles) im_image = handles.data.image; im_counts = sum(im_image(:)); im_npix = numel(im_image); [im_min, min_ind] = min(im_image(:)); [im_min_y, im_min_x] = ind2sub(size(im_image), min_ind); [im_max, max_ind] = max(im_image(:)); [im_max_y, im_max_x] = ind2sub(size(im_image), max_ind); im_avg = mean(im_image(:)); [im_cen_x im_cen_y] = centroid(im_image); infoStr1 = sprintf('counts=%.3e',im_counts); infoStr2 = sprintf('#pix=%-7d avg=%.2f',im_npix,im_avg); infoStr3 = sprintf('cen=(%.1f,%.1f)',im_cen_x,im_cen_y); infoStr4 = sprintf('min=%-7d @ (%d,%d)', im_min, im_min_x, im_min_y); infoStr5 = sprintf('max=%-7d @ (%d,%d)', im_max, im_max_x, im_max_y); infoStr = {infoStr1;infoStr2;infoStr3;infoStr4;infoStr5}; set(handles.text_image_info,'String',infoStr) %------------------------------------------------------------------------- % --- update the image information text upon change of image info file. function fcn_update_roi_info(hObject, eventdata, handles) roi_contents = get(handles.popupmenu_select_roi,'String'); roi_method = roi_contents{get(handles.popupmenu_select_roi,'Value')}; switch roi_method case 'none' set(handles.text_image_roi_info,'String',... 'No region of interest defined'); otherwise Mask = handles.roi.roi; ind = find(Mask); im_image = handles.data.image.*Mask; im_counts = sum(im_image(:)); im_npix = sum(Mask(:)); [im_min, min_ind] = min(im_image(ind)); min_ind = ind(min_ind); [im_min_y, im_min_x] = ind2sub(size(im_image), min_ind); [im_max, max_ind] = max(im_image(ind)); max_ind = ind(max_ind); [im_max_y, im_max_x] = ind2sub(size(im_image), max_ind); im_avg = mean(im_image(ind)); [im_cen_x im_cen_y] = centroid(im_image); infoStr1 = sprintf('counts=%.3e',im_counts); infoStr2 = sprintf('#pix=%d avg=%.2f',im_npix,im_avg); infoStr3 = sprintf('cen=(%.1f,%.1f)',im_cen_x,im_cen_y); infoStr4 = sprintf('min=%-7d @ (%d,%d)', ... im_min, im_min_x, im_min_y); infoStr5 = sprintf('max=%-7d @ (%d,%d)', ... im_max, im_max_x, im_max_y); infoStr = {infoStr1;infoStr2;infoStr3;infoStr4;infoStr5}; set(handles.text_image_roi_info,'String',infoStr) end %------------------------------------------------------------------------- % --- calculate the centroid of image data. function [x,y] = centroid(I) [x,y,z] = size(I); % Checking whether the picture is colored or monochromatic, if colored then converting to gray. if ~(z==1) I = rgb2gray(I); end [rows,cols] = size(I); x = ones(rows,1)*(1:cols); % Matrix with each pixel set to its x coordinate y = (1:rows)'*ones(1,cols); % " " " " " " " y " area = sum(I(:)); if area > 0 x = sum(sum(double(I).*x))/area; y = sum(sum(double(I).*y))/area; else x = NaN; y = NaN; end % -------------------------------------------------------------------- function menu_file_Callback(hObject, eventdata, handles) % hObject handle to menu_file (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function menu_help_Callback(hObject, eventdata, handles) % hObject handle to menu_help (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function menu_file_export_Callback(hObject, eventdata, handles) % hObject handle to menu_file_export (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function menu_file_print_Callback(hObject, eventdata, handles) % hObject handle to menu_file_print (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function menu_file_exit_Callback(hObject, eventdata, handles) % hObject handle to menu_file_exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(handles.figure_imageviewer) % -------------------------------------------------------------------- function menu_file_export_overview_Callback(hObject, eventdata, handles) % hObject handle to menu_file_export_overview (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) I = handles.data.filter_image; printfig = fcn_open_print_window(I, [0 0], hObject, eventdata, handles); F = getframe(printfig); [outfile, outpath] = uiputfile({'*.jpg';'*.tif'},... 'Export file'); % don't do anything if user clicked Cancel if isequal(outfile,0) close(printfig) return end filename = fullfile(outpath, outfile); [pathstr, name, ext] = fileparts(fullfile(outpath,outfile)); cmd = 'imwrite(F.cdata,filename'; switch ext case {'.jpg','.jpeg'} cmd = [cmd ',''Quality'',100']; end cmd = [cmd ')']; eval(cmd) close(printfig) % -------------------------------------------------------------------- function menu_file_export_zoom_Callback(hObject, eventdata, handles) % hObject handle to menu_file_export_zoom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) rect = handles.zoom_image_scrollpanel_api.getVisibleImageRect(); ImPrint = imcrop(handles.data.filter_image,rect); printfig = fcn_open_print_window(ImPrint, ... [rect(1) rect(2)], hObject, eventdata, handles); F = getframe(printfig); [outfile, outpath] = uiputfile({'*.jpg';'*.tif'},... 'Export file'); % don't do anything if user clicked Cancel if isequal(outfile,0) close(printfig) return end filename = fullfile(outpath, outfile); [pathstr, name, ext] = fileparts(fullfile(outpath,outfile)); cmd = 'imwrite(F.cdata,filename'; switch ext case {'.jpg','.jpeg'} cmd = [cmd ',''Quality'',100']; end cmd = [cmd ')']; eval(cmd) close(printfig) % -------------------------------------------------------------------- function menu_file_export_window_Callback(hObject, eventdata, handles) % hObject handle to menu_file_export_window (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) F = getframe(handles.figure_imageviewer); [outfile, outpath] = uiputfile({'*.jpg';'*.tif'},... 'Export file'); % don't do anything if user clicked Cancel if isequal(outfile,0) return end filename = fullfile(outpath, outfile); [pathstr, name, ext] = fileparts(fullfile(outpath,outfile)); cmd = 'imwrite(F.cdata,filename'; switch ext case {'.jpg','.jpeg'} cmd = [cmd ',''Quality'',100']; end cmd = [cmd ')']; eval(cmd) % -------------------------------------------------------------------- function menu_file_print_overview_Callback(hObject, eventdata, handles) % hObject handle to menu_file_print_overview (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) I = handles.data.filter_image; printfig = fcn_open_print_window(I, [0 0], hObject, eventdata, handles); try printdlg('-crossplatform',printfig); catch err = lasterror; if (strcmp(computer,'GLNX86') == 0) try F = getframe(printfig); imwrite(F.cdata,'/tmp/imageviewerfig.jpg','Quality',90); unix('chmod 777 /tmp/imageviewerfig.jpg'); unix('lpr /tmp/imageviewerfig.jpg'); catch err2 = lasterror; rethrow(err); rethrow(err2); end else rethrow(err); end end close(printfig) % -------------------------------------------------------------------- function menu_file_print_zoom_Callback(hObject, eventdata, handles) % hObject handle to menu_file_print_zoom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) rect = handles.zoom_image_scrollpanel_api.getVisibleImageRect(); ImPrint = imcrop(handles.data.filter_image,rect); printfig = fcn_open_print_window(ImPrint, ... [rect(1) rect(2)], hObject, eventdata, handles); try printdlg('-crossplatform',printfig); catch err = lasterror; if (strcmp(computer,'GLNX86') == 0) try F = getframe(printfig); imwrite(F.cdata,'/tmp/imageviewerfig.jpg','Quality',90); unix('chmod 777 /tmp/imageviewerfig.jpg'); unix('lpr /tmp/imageviewerfig.jpg'); catch err2 = lasterror; rethrow(err); rethrow(err2); end else rethrow(err); end end close(printfig) % -------------------------------------------------------------------- function menu_file_print_window_Callback(hObject, eventdata, handles) % hObject handle to menu_file_print_window (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try printdlg('-crossplatform',handles.figure_imageviewer); catch err = lasterror; if (strcmp(computer,'GLNX86') == 0) try F = getframe(handles.figure_imageviewer); imwrite(F.cdata,'/tmp/imageviewerfig.jpg','Quality',90); unix('chmod 777 /tmp/imageviewerfig.jpg'); unix('lpr /tmp/imageviewerfig.jpg'); catch err2 = lasterror; rethrow(err); rethrow(err2); end else rethrow(err); end end % -------------------------------------------------------------------- function menu_help_about_Callback(hObject, eventdata, handles) % hObject handle to menu_help_about (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) helpfig = figure('Name','About ImageViewer...','Resize','off'); textfield = uicontrol(helpfig,... 'style','text',... 'Units','normalized',... 'Position',[0 0 1 1],... 'horizontalAlignment','center',... 'FontSize',14,... 'Tag','text_about'); about_string = {' ';... 'IMAGE VIEWER';... '==========';... ' ';... '$Revision: 1.3 $';'$Date: 2006/12/05 16:57:16 $';'$Tag: $';... '$Source: /import/cvs/X/PILATUS/X04SA/App/lib/X_PILATUS_X04SA_Matlab/imageviewer.m,v $'; ' ';... 'Author(s):'; 'C.M. Schlepuetz';... 'Surface Diffraction Station';... 'Materials Science Beamline X04SA';... 'Swiss Light Source (SLS)';... 'Paul Scherrer Institut';... 'CH - 5232 Villigen PSI';... ' '}; [about_string, pos] = textwrap(textfield,about_string); fig_pos = get(helpfig,'Position'); fig_pos(3) = fig_pos(3)*pos(3); fig_pos(4) = fig_pos(4)*pos(4); set(helpfig,'Position',fig_pos); % display scanlogfile in the text field set(textfield,'String',about_string); % -------------------------------------------------------------------- % opens a new figure with image to be printed function printfig = fcn_open_print_window(I, zeroOff, hObject, eventdata, handles) printfig = figure; pos = get(printfig,'Position'); [ydim xdim] = size(I); imagedim = handles.data.image_dim; while (xdim < imagedim(1)) && (ydim < imagedim(2)) xdim = xdim*2; ydim = ydim*2; end set(printfig,'Position',[pos(1) pos(2) xdim ydim]) printaxes = axes('Units','normalized','Position',[0 0 1 1],... 'Parent',printfig); imagesc(I,'Parent',printaxes); cmap = handles.image_control.colormap; cmap_dim = size(cmap); cind = ((1:cmap_dim(1))-1)./(cmap_dim(1)-1); cind = cind.^handles.image_control.gamma; cind = round(cind.*(cmap_dim(1)-1))+1; cmap = handles.image_control.colormap(cind,:); colormap(cmap); caxis([handles.image_control.min handles.image_control.max]) axis equal axis off