%--------------------------------------------------------------------%
% Alison Chaiken, sole author and maintainer %
% ------------------------------------------------------ %
% GUI-based Matlab and FEMLAB data analysis, instrument %
% control, statistical analysis, finite-element modelling, %
% image acquisition and analysis %
% ------------------------------------------------------- %
% alchaiken@gmail.com %
% http://www.exerciseforthereader.org/ %
% (001)650-279-5600 %
%--------------------------------------------------------------------%
function varargout = ImageSectionGenerator(varargin)
% Main file for Image Section Generator application
% IMAGESECTIONGENERATOR M-file for ImageSectionGenerator.fig
% IMAGESECTIONGENERATOR, by itself, creates a new IMAGESECTIONGENERATOR or raises the existing
% singleton*.
%
% H = IMAGESECTIONGENERATOR returns the handle to a new IMAGESECTIONGENERATOR or the handle to
% the existing singleton*.
%
% IMAGESECTIONGENERATOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGESECTIONGENERATOR.M with the given input arguments.
%
% IMAGESECTIONGENERATOR('Property','Value',...) creates a new IMAGESECTIONGENERATOR or raises
% the existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ImageSectionGenerator_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ImageSectionGenerator_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ImageSectionGenerator
% Last Modified by GUIDE v2.5 27-May-2009 18:25:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ImageSectionGenerator_OpeningFcn, ...
'gui_OutputFcn', @ImageSectionGenerator_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 ImageSectionGenerator is made visible.
function ImageSectionGenerator_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 ImageSectionGenerator (see VARARGIN)
% Choose default command line output for ImageSectionGenerator
handles.output = hObject;
%these statements must be in the opening function to create the new handles
handles.ImageSectionGenerator = hObject;
handles.ImageWidth = -1;
handles.ImageHeight = -1;
handles.ScaleMax = -1;
handles.ImageType = 'none';
handles.rcflag='h';
handles.ScaleFactor=-1;
handles.Image = -1;
handles.SectionPlot = -1;
%the color that buttons have when they aren't highlighted
global DEFAULT_BACKGROUND_COLOR;
DEFAULT_BACKGROUND_COLOR = [0.8706 0.9216 0.9804];
global GRAY;
GRAY=[0.9 0.9 0.9];
initialize_gui(hObject, handles, false);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ImageSectionGenerator wait for user response (see UIRESUME)
% uiwait(handles.ImageSectionGenerator);
% --- Outputs from this function are returned to the command line.
function varargout = ImageSectionGenerator_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;
% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the QuitButton flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to QuitButton the data.
%if isfield(handles, 'metricdata') && ~isreset
% return;
%end
set(gcf,'Name','Section-plot generator for TIFF and JPEG images')
set(handles.SelectionMethodGroup, 'SelectedObject', handles.RowColumnChoiceButton);
set(handles.SectionOrientationGroup, 'SelectedObject', handles.HorizontalButton);
set(handles.HorizontalPresets,'Visible','on')
set(handles.VerticalPresets,'Visible','off')
set(handles.ImageFileName,'string','')
set(handles.NumericSectionLocation,'value',-1);
set(handles.Magnification,'value',20);
set(handles.Magnification,'string',20);
set(handles.DisplayScaleBar,'value',0);
set(fig_handle,'UserData',[])
% user start-up cues
%global GRAY
set(handles.LoadNewImageButton,'BackgroundColor','green')
%set(handles.DisplayImage,'ForegroundColor',GRAY)
%set(handles.MakeSectionPlot, 'ForegroundColor',GRAY)
CenterCurrentWindow
% Update handles structure
guidata(fig_handle,handles)
% --- Executes on button press in HorizontalButton.
function HorizontalButton_Callback(hObject, eventdata, handles)
% hObject handle to HorizontalButton (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 HorizontalButton
SectionOrientationGroup_SelectionChangeFcn(hObject, eventdata, handles)
% --- Executes on button press in HorizontalButton.
function VerticalButton_Callback(hObject, eventdata, handles)
% hObject handle to VerticalButton (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 HorizontalButton
SectionOrientationGroup_SelectionChangeFcn(hObject, eventdata, handles)
% --- Executes on button press in LoadNewImageButton.
function LoadNewImageButton_Callback(hObject, eventdata, handles)
% hObject handle to LoadNewImageButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR;
set(handles.LoadNewImageButton,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SaveSectionDataButton,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.MakeSectionPlot,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'Shadow','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'Shadow','black')
%both lbox2 and ReloadImageButton_Callback change handle values
lbox2('ImageSectionGenerator',handles.ImageSectionGenerator);
if (~isempty(get(handles.ImageFileName,'string')))
ReloadImageButton_Callback(hObject, eventdata, handles)
else
%errordlg('Empty filename','Empty filename')
end
% --- Executes on button press in SaveSectionDataButton.
function SaveSectionDataButton_Callback(hObject, eventdata, handles)
% hObject handle to SaveSectionDataButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SaveSectionData
function NumericSectionLocation_Callback(hObject, eventdata, handles)
% hObject handle to NumericSectionLocation (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 NumericSectionLocation as text
% str2double(get(hObject,'String')) returns contents of NumericSectionLocation as a double
global DEFAULT_BACKGROUND_COLOR;
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'ShadowColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
location = str2double(get(handles.NumericSectionLocation,'string'));
%location is empty if the string contains non-numeric characters
if (isempty(location) || ~isfinite(location))
set(handles.NumericSectionLocation,'string','')
set(handles.NumericSectionLocation,'value',-1)
else
set(handles.NumericSectionLocation,'value',location)
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function NumericSectionLocation_CreateFcn(hObject, eventdata, handles)
% hObject handle to NumericSectionLocation (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 SetCenterButton.
function SetCenterButton_Callback(hObject, eventdata, handles)
% hObject handle to SetCenterButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'ShadowColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
set(handles.NumericSectionLocation,'value',.5*handles.ImageHeight)
set(handles.NumericSectionLocation,'string',num2str(0.5*handles.ImageHeight))
guidata(hObject,handles)
% --- Executes on button press in SetBottomButton.
function SetBottomButton_Callback(hObject, eventdata, handles)
% hObject handle to SetBottomButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'ShadowColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
set(handles.NumericSectionLocation,'value',handles.ImageHeight)
set(handles.NumericSectionLocation,'string',num2str(handles.ImageHeight))
guidata(hObject,handles)
% --- Executes on button press in SetTopButton.
function SetTopButton_Callback(hObject, eventdata, handles)
% hObject handle to SetTopButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'ShadowColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
set(handles.NumericSectionLocation,'value',1)
set(handles.NumericSectionLocation,'string',num2str(1));
guidata(hObject,handles)
% --- Executes when selected object is changed in SectionOrientationGroup.
function SectionOrientationGroup_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in SectionOrientationGroup
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (get(handles.VerticalButton,'Value') == 1.0)
set(handles.HorizontalPresets,'Visible','off')
set(handles.VerticalPresets,'Visible','on')
handles.rcflag = 'v';
else
set(handles.HorizontalPresets,'Visible','on')
set(handles.VerticalPresets,'Visible','off')
handles.rcflag = 'h';
end
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'Fontweight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
if ((~(get(handles.NumericSectionLocation,'value'))) > 0)
set(handles.NumericSectionLocation,'BackgroundColor','green')
end
% Update handles structure
guidata(hObject,handles)
% --- Executes when selected object is changed in SelectionMethodGroup.
function SelectionMethodGroup_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in SectionOrientationGroup
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (get(handles.RowColumnChoiceButton,'Value') == 1.0)
set(handles.NumericControlsPanel,'Visible','on')
else
set(handles.NumericControlsPanel,'Visible','off')
end
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SelectionMethodGroup, 'Shadow','black')
set(handles.SectionOrientationGroup,'ForegroundColor','green')
set(handles.SectionOrientationGroup,'Fontweight','bold')
% Update handles structure
guidata(hObject,handles)
% --- Executes on button press in SetLeftButton.
function SetLeftButton_Callback(hObject, eventdata, handles)
% hObject handle to SetLeftButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'ShadowColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
set(handles.NumericSectionLocation, 'value',1)
set(handles.NumericSectionLocation,'string',num2str(1))
guidata(hObject,handles)
% --- Executes on button press in SetMiddleButton.
function SetMiddleButton_Callback(hObject, eventdata, handles)
% hObject handle to SetMiddleButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'ShadowColor','black')
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ForegroundColor','black')
set(handles.SectionOrientationGroup,'FontWeight','normal')
set(handles.SectionOrientationGroup,'ShadowColor','black')
middle = 0.5*handles.ImageWidth;
set(handles.NumericSectionLocation, 'value',middle)
set(handles.NumericSectionLocation,'string',num2str(middle))
guidata(hObject,handles)
% --- Executes on button press in SetRightButton.
function SetRightButton_Callback(hObject, eventdata, handles)
% hObject handle to SetRightButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.NumericSectionLocation, 'value',handles.ImageWidth)
set(handles.NumericSectionLocation,'string',num2str(handles.ImageWidth))
guidata(hObject,handles)
% --- Executes on button press in DisplayImage.
function DisplayImage_Callback(hObject, eventdata, handles)
% hObject handle to DisplayImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%show image with selected linescan
tiffarray = [];
tiffarray = get(handles.ImageSectionGenerator,'UserData');
if (~isempty(tiffarray))
handles.Image = figure;
UpperRightCurrentWindow
lineshow=axes();
imshow(tiffarray,'Parent',lineshow)
if (get(handles.DisplayScaleBar,'value'))
DrawScaleBar
end
BetterWindowTitle
else
errordlg('No image data. Load a new image first.')
set(handles.LoadNewImageButton,'BackgroundColor','green')
guidata(hObject,handles)
end
function Magnification_Callback(hObject, eventdata, handles)
% hObject handle to Magnification (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 Magnification as text
% str2double(get(hObject,'String')) returns contents of Magnification as a double
%Image is 200 microns high for 20x and 640x480
%SCALEFACTOR=(20*200)/(imageheight*Magnification);
%for better agreement with image of ruler
%SCALEFACTOR=1.163*(20*200)/(imageheight*Magnification);
%1.2011 comes analysis of gaertner4x.tif, a calibrated scale
%SCALEFACTOR=1.2011*(20*200)/(imageheight*Magnification);
%For 37x SEM image, 210 pixels = 1 mm = 1000 microns
%SCALEFACTOR=(1000*double(imagewidth)*37)/(double(Magnification)*210)
global DEFAULT_BACKGROUND_COLOR
magn = str2double(get(handles.Magnification,'string'));
%magnification is empty if the string contains non-numeric characters
if (isempty(magn) || ~isfinite(magn))
set(handles.Magnification,'string','')
set(handles.Magnification,'BackgroundColor','green')
else
set(handles.Magnification,'value',magn)
set(handles.Magnification,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'ForegroundColor','green')
set(handles.SelectionMethodGroup,'FontWeight','bold')
set(handles.SelectionMethodGroup, 'Shadow','green')
end
handles.ScaleFactor=37000.0/(magn*210);
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Magnification_CreateFcn(hObject, eventdata, handles)
% hObject handle to Magnification (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 ReloadImageButton.
function ReloadImageButton_Callback(hObject, eventdata, handles)
% hObject handle to ReloadImageButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename=get(handles.ImageFileName,'string');
if isempty(filename)
errordlg('Empty filename','Empty filename')
set(handles.LoadNewImageButton,'BackgroundColor','green')
guidata(hObject,handles)
else
%retrieve path name stored by lbox2 'Done' button in ImageFileName's
%appdata
filepath=getappdata(handles.ImageFileName,'ImageFileDirectory');
ImageFileName=fullfile(filepath,filename);
set(handles.ImageSectionGenerator,'UserData', []);
tiffarray = [];
if ((~isempty(findstr('tif',ImageFileName))) || (~isempty(findstr('TIF',ImageFileName))))
tiffarray = imread(ImageFileName,'tiff');
elseif ((~isempty(findstr('jpg',ImageFileName))) || (~isempty(findstr('JPG',ImageFileName) >0)))
tiffarray = imread(ImageFileName,'jpg');
else errordlg('Please load a TIFF or JPEG file.','Input file selection error.')
end
if size(tiffarray)
set(handles.ImageSectionGenerator,'UserData',tiffarray)
[handles.ImageHeight,handles.ImageWidth,imagecolored]=size(tiffarray);
imagedepth=get_image_depth(tiffarray);
switch (imagecolored)
case 3
handles.ImageType='color';
set(handles.ForceGray,'Visible','on')
case 1
handles.ImageType='grayscale';
set(handles.ForceGray,'Visible','off')
otherwise
error('Unknown image type.')
end
handles.ScaleMax=2^imagedepth;
%paramstring=sprintf('%d-bit %s image of size %dx%d.',imagedepth,handles.ImageType,handles.ImageHeight,handles.ImageWidth);
%disp(paramstring);
set(handles.Magnification,'BackgroundColor','green')
%set(handles.DisplayImage,'ForegroundColor','black')
%set(handles.MakeSectionPlot, 'ForegroundColor','black')
end
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function VerticalButton_CreateFcn(hObject, eventdata, handles)
% hObject handle to VerticalButton (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 QuitButton_CreateFcn(hObject, eventdata, handles)
% hObject handle to QuitButton (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 ReloadImageButton_CreateFcn(hObject, eventdata, handles)
% hObject handle to ReloadImageButton (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 LoadNewImageButton_CreateFcn(hObject, eventdata, handles)
% hObject handle to LoadNewImageButton (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 button press in RowColumnChoiceButton.
function RowColumnChoiceButton_Callback(hObject, eventdata, handles)
% hObject handle to RowColumnChoiceButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SelectionMethodGroup_SelectionChangeFcn(hObject, eventdata, handles)
% --- Executes on button press in MakeSectionPlot.
function MakeSectionPlot_Callback(hObject, eventdata, handles)
% hObject handle to MakeSectionPlot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR;
set(handles.MakeSectionPlot,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SelectionMethodGroup,'FontWeight','normal')
set(handles.SelectionMethodGroup,'ForegroundColor','black')
set(handles.SelectionMethodGroup,'Shadow','black')
Magnification_Callback(hObject, eventdata, handles)
%handles is changed in Magnification_Callback, so we must reread them
%Without this statement, the changes in Magnification_Callback don't get
%passed along to MakeSectionPlot
handles=guidata(hObject);
if isempty(get(handles.ImageFileName,'string'))
set(handles.LoadNewImageButton,'BackgroundColor','green')
errordlg('Please designate an image file and a section location before creating a plot.')
elseif ((get(handles.RowColumnChoiceButton,'value')==1)&& ...
(get(handles.NumericSectionLocation,'value') == -1))
set(handles.NumericSectionLocation,'BackgroundColor','green')
errordlg('Please designate a section location before creating a plot.')
else
MakeSectionPlot
%only turn SaveSectionData button green if data to save is available in
%the handles of the figures. Numeric-choice data needs only the
%section plot; cursor-drawn data needs both the section plot and the
%image window.
if (ishandle(handles.SectionPlot))
if (get(handles.RowColumnChoiceButton,'value')==1)
set(handles.SaveSectionDataButton,'BackgroundColor','green')
% if(get(handles.CursorChoiceButton,'value)==1)
elseif (ishandle(handles.Image))
set(handles.SaveSectionDataButton,'BackgroundColor','green')
end
end
end
% --- Executes on key press with focus on NumericSectionLocation and no controls selected.
function NumericSectionLocation_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to NumericSectionLocation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%I had hoped that this function would prevent non-numeric characters from
%appearing in the text box as they are typed, but non-numeric characters
%are only cleared by loss of focus through NumericSectionLocation_Callback.
%This function never appears to be invoked, probably because the textboxes
%properties aren't updated until focus is transferred.
%location = str2num(get(handles.NumericSectionLocation,'string'));
%if isempty(location)
% set(handles.NumericSectionLocation,'string','')
%end
%guidata(hObject,handles)
% --- Executes on button press in QuitButton.
function QuitButton_Callback(hObject, eventdata, handles)
% hObject handle to QuitButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ImageSectionGenerator_CloseRequestFcn(handles.ImageSectionGenerator, eventdata, handles)
% --- Executes when user attempts to close main figure.
function ImageSectionGenerator_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to main figure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);
% --- Executes on button press in ForceGray.
function ForceGray_Callback(hObject, eventdata, handles)
% hObject handle to ForceGray (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 ForceGray
% --- Executes on button press in CursorChoiceButton.
function CursorChoiceButton_Callback(hObject, eventdata, handles)
% hObject handle to CursorChoiceButton (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 CursorChoiceButton
set(handles.RowColumnChoiceButton,'ForegroundColor','black')
set(handles.CursorChoiceButton,'ForegroundColor','black')
set(handles.RowColumnChoiceButton,'FontWeight','normal')
set(handles.CursorChoiceButton,'FontWeight','normal')
set(handles.MakeSectionPlot,'BackgroundColor','green')
guidata(hObject,handles)
SelectionMethodGroup_SelectionChangeFcn(hObject, eventdata, handles)
% --- Executes on button press in DisplayScaleBar.
function DisplayScaleBar_Callback(hObject, eventdata, handles)
% hObject handle to DisplayScaleBar (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 DisplayScaleBar
if (get(handles.DisplayScaleBar,'value') == 1)
DrawScaleBar
else %redisplay image without scalebar by closing current image and then opening a new one
% close(handles.Image)
% DisplayImage_Callback(hObject, eventdata, handles)
% This re-display works, but it prevents the user from later saving the
% data in a file.
end
% --- Executes on button press in HelpButton.
function HelpButton_Callback(hObject, eventdata, handles)
% hObject handle to HelpButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
web('http://www.exerciseforthereader.org/ISGdocs/index.html','-browser')
% --- Executes on button press in DemoButton.
function DemoButton_Callback(hObject, eventdata, handles)
% hObject handle to DemoButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global DEFAULT_BACKGROUND_COLOR
%initialize_gui(handles.ImageSectionGenerator,handles,false)
set(handles.ImageFileName,'string','TestImage.jpg')
guidata(hObject,handles)
ReloadImageButton_Callback(hObject,eventdata,handles)
%handles is changed in ReloadImageButton_Callback, so we must reread them
%Without this statement, the changes in ReloadImageButton_Callback don't get
%passed along to MakeSectionPlot
handles=guidata(hObject);
%DisplayImage_Callback(hObject,eventdata,handles)
SetCenterButton_Callback(hObject, eventdata, handles)
set(handles.LoadNewImageButton,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.Magnification,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.NumericSectionLocation,'BackgroundColor',DEFAULT_BACKGROUND_COLOR)
set(handles.SaveSectionDataButton, 'BackgroundColor','green')
guidata(hObject,handles)
MakeSectionPlot