Commit e2a2baeb authored by Eamon Doyle's avatar Eamon Doyle
Browse files

add merge tool update

parent 54947a43
function varargout = mergeRoiTool(varargin)
% ROITOOL MATLAB code for mergeRoiTool.fig
% ROITOOL, by itself, creates a new ROITOOL or raises the existing
% singleton*.
%
% H = ROITOOL returns the handle to a new ROITOOL or the handle to
% the existing singleton*.
%
% ROITOOL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ROITOOL.M with the given input arguments.
%
% ROITOOL('Property','Value',...) creates a new ROITOOL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before roiTool_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to roiTool_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 roiTool
% Last Modified by GUIDE v2.5 12-Dec-2014 13:48:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @roiTool_OpeningFcn, ...
'gui_OutputFcn', @roiTool_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 roiTool is made visible.
function roiTool_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 roiTool (see VARARGIN)
% Choose default command line output for roiTool
handles.output = hObject;
handles.needsReload = 1;
handles.roi = struct;
handles.roiCoords = struct;
% Update handles structure
guidata(hObject, handles);
% This sets up the initial plot - only do when we are invisible
% so window can get raised using roiTool.
set(handles.progressAxes,'XTick',0,'YTick',0);
%{
if strcmp(get(hObject,'Visible'),'off')
plot(rand(5));
end
%}
% UIWAIT makes roiTool wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = roiTool_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;
% --- Executes on button press in pushbutton_save.
function pushbutton_save_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
roi = handles.roi;
roiCoords = handles.roiCoords;
if (~checkReload(hObject,handles))
elseif (max(roi.liver(:)) == 0 ...
|| max(roi.muscle(:)) == 0 ...
|| get(handles.checkbox_liver,'Value') == 0 ...
|| get(handles.checkbox_musc,'Value') == 0 )
h = warndlg('One of the ROIs is all zero or hasn''t been performed. Nothing saved');
else
savePath = [handles.path '/ROI'];
fname = handles.curName;
if exist(savePath,'dir') ~= 7
mkdir(savePath);
end
try
save([savePath '/liver-' fname '.mat'],'roi','roiCoords')
set(handles.checkbox_saved,'Value',1,'BackgroundColor','g');
axes(handles.axes1);
imagesc([0 0; 0 0]);
handles.needsReload = 1;
msgbox('ROI Saved Successfully')
catch
h = warndlg('Save failed. Nothing saved');
end
end
guidata(hObject, handles);
%popup_sel_index = get(handles.popupmenu1, 'Value');
%{
switch popup_sel_index
case 1
plot(rand(5));
case 2
plot(sin(1:0.01:25.99));
case 3
bar(1:.5:10);
case 4
plot(membrane);
case 5
surf(peaks);
end
%}
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject handle to FileMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to OpenMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%[file, path] = uigetfile('*');
%try
% img = dicomread([path file]);
% nfo = dicominfo([path file]);
%catch
% disp('Not a dicom');
%end
axes(handles.axes1);
imagesc([0 0; 0 0]);
if( ~isfield(handles, 'path') )
path = uigetdir();
else
path = uigetdir(handles.path);
end
handles.path = path;
handles.needsReload = 1;
files = dir(path);
dcmlist = struct;
setProgress(hObject, eventdata, handles,0,'Loading...')
for n=3:length(files);
fp = [path '/' files(n).name];
if ~files(n).isdir && isdicom(fp) && (isempty(strfind(files(n).name,'XX')) && isempty(strfind(files(n).name,'PS')))
nfo=dicominfo(fp);
dcmlist(end+1).path = fp;
dcmlist(end).fname = files(n).name;
dcmlist(end).protocol = nfo.ProtocolName;
end
setProgress(hObject, eventdata, handles,n/length(files),[])
end
setProgress(hObject, eventdata, handles,1,'Finished')
if length(dcmlist) < 1
error('no dicoms found');
else
dcmlist = dcmlist(2:end);
end
% prep the listbox
for n=1:length(dcmlist)
fileStrings{n} = dcmlist(n).protocol;
end
set(handles.listbox1,'String',fileStrings);
handles.roi.liver = 0;
handles.roi.muscle = 0;
set(handles.checkbox_liver,'Value',0,'BackgroundColor','r');
set(handles.checkbox_musc,'Value',0,'BackgroundColor','r');
set(handles.checkbox_saved,'Value',0,'BackgroundColor','r');
handles.dcmlist = dcmlist;
handles.needsReload = 1;
guidata(hObject,handles);
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to PrintMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to CloseMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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
set(hObject, 'String', {'plot(rand(5))', 'plot(sin(1:0.01:25))', 'bar(1:.5:10)', 'plot(membrane)', 'surf(peaks)'});
% --- Executes on button press in buttonLiverROI.
function buttonLiverROI_Callback(hObject, eventdata, handles)
% hObject handle to buttonLiverROI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if checkReload(hObject,handles)
[a x y] = roipoly();
imageNum = get(handles.slider2,'Value');
handles.roi.liver(:,:,imageNum) = a;
handles.roiCoords.liver(imageNum).x = x;
handles.roiCoords.liver(imageNum).y = y;
guidata(hObject,handles);
set(handles.checkbox_liver,'Value',1,'BackgroundColor','g');
end
% --- Executes on button press in buttonLiverROI.
function buttonMuscROI_Callback(hObject, eventdata, handles)
% hObject handle to buttonLiverROI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if checkReload(hObject,handles)
[a x y] = roipoly();
imageNum = get(handles.slider2,'Value');
handles.roi.muscle(:,:,imageNum) = a;
handles.roiCoords.muscle(imageNum).x = x;
handles.roiCoords.muscle(imageNum).y = y;
guidata(hObject,handles);
set(handles.checkbox_musc,'Value',1,'BackgroundColor','g');
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over buttonLiverROI.
function buttonLiverROI_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to buttonLiverROI (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 listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (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
% --- Executes on button press in buttonLoad.
function buttonLoad_Callback(hObject, eventdata, handles)
% hObject handle to buttonLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.checkbox_liver,'Value',0,'BackgroundColor','r');
set(handles.checkbox_musc,'Value',0,'BackgroundColor','r');
set(handles.checkbox_saved,'Value',0,'BackgroundColor','r');
imagenum = get(handles.listbox1,'Value');
path = handles.dcmlist(imagenum).path;
axes(handles.axes1);
images = dicomread(path);
imagesc(images(:,:,1,1));
tsize = size(images);
display("matrix size");
display(tsize);
if max(size(tsize)) > 2
tsize = tsize([1:2 4]);
end
roi = zeros(tsize);
if size(images,4) > 1
sliderVal = size(images,4);
sH = handles.slider2;
set(sH, 'SliderStep',[1/(sliderVal-1) 1], 'Min', 1, 'Max', sliderVal, 'Value', 1);
else
sH = handles.slider2;
set(sH, 'SliderStep',[.1 1], 'Min', 1, 'Max', 1.1, 'Value', 1);
end
handles.curName = handles.dcmlist(imagenum).fname;
handles.roiCoords = struct;
handles.roi.liver = roi;
handles.roi.muscle = roi;
handles.imageMat = images;
handles.needsReload = 0;
handles.climval = get(handles.axes1,'CLim');
set(handles.slider_color,'Value',1);
guidata(hObject,handles);
function setProgress(hObject, eventdata, handles,value,text)
if ~isempty(value)
axes(handles.progressAxes);
vxlow=0;
vxhigh = value;
vylow = 0;
vyhigh = 1;
fillhandle = fill([vxlow,vxlow,vxhigh,vxhigh], [vyhigh,vylow,vylow,vyhigh],[.3,.4,0]); %creates the plot of a box. If you reverse the order of one of the sets of points, you get an hourglass shape
set(fillhandle,'FaceAlpha',.2,'EdgeAlpha',.2);%set edge color
set(gca,'Ylim',[0,1],'Xlim',[0,1],'XTick',0,'YTick',0);
end
if ~isempty(text)
set(handles.progressText,'String',text);
end
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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
if get(handles.slider2,'Max') ~= 1.1
axes(handles.axes1);
images = handles.imageMat;
imagesc(images(:,:,1,get(handles.slider2,'Value')));
end
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (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_color_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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
%handles.climval
%get(handles.slider_color,'Value')
set(handles.axes1,'CLim',handles.climval .* [1 get(handles.slider_color,'Value')]);
function out = checkReload(hObject,handles)
if handles.needsReload ~= 0
warndlg('Please load an image');
out = 0;
else
out = 1;
end
% --- Executes during object creation, after setting all properties.
function slider_color_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_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: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment