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

mergeRoiTool nearing useful functionality

parent e2a2baeb
No preview for this file type
......@@ -3,33 +3,33 @@ function varargout = mergeRoiTool(varargin)
% 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
% H = mergeRoiTool returns the handle to a new mergeRoiTool 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.
% mergeRoiTool('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in mergeRoiTool.M with the given input arguments.
%
% ROITOOL('Property','Value',...) creates a new ROITOOL or raises the
% mergeRoiTool('Property','Value',...) creates a new mergeRoiTool or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before roiTool_OpeningFcn gets called. An
% applied to the GUI before mergeRoiTool_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to roiTool_OpeningFcn via varargin.
% stop. All inputs are passed to mergeRoiTool_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
% See also: GUIDE, GUIDATA, GUI
% Edit the above text to modify the response to help roiTool
% Edit the above text to modify the response to help mergeRoiTool
% Last Modified by GUIDE v2.5 12-Dec-2014 13:48:37
% Last Modified by GUIDE v2.5 14-Mar-2024 07:53:15
% 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_OpeningFcn', @mergeRoiTool_OpeningFcn, ...
'gui_OutputFcn', @mergeRoiTool_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
......@@ -43,36 +43,37 @@ else
end
% End initialization code - DO NOT EDIT
% --- Executes just before roiTool is made visible.
function roiTool_OpeningFcn(hObject, eventdata, handles, varargin)
% --- Executes just before mergeRoiTool is made visible.
function mergeRoiTool_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)
% varargin command line arguments to mergeRoiTool (see VARARGIN)
% Choose default command line output for roiTool
% Choose default command line output for mergeRoiTool
handles.output = hObject;
handles.needsReload = 1;
handles.roi = struct;
handles.roiCoords = struct;
handles.lungGridSize = -1;
% 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.
% so window can get raised using mergeRoiTool.
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 makes mergeRoiTool 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)
function varargout = mergeRoiTool_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
......@@ -107,8 +108,14 @@ else
save([savePath '/liver-' fname '.mat'],'roi','roiCoords')
set(handles.checkbox_saved,'Value',1,'BackgroundColor','g');
axes(handles.axes1);
imagesc([0 0; 0 0]);
warn('here')
h = imagesc([0 0; 0 0])
%set(h,'HitTest','off')
get(h)
%set(h,'ButtonDownFcn',@axes1_ButtonDownFcn)
handles.needsReload = 1;
msgbox('ROI Saved Successfully')
catch
h = warndlg('Save failed. Nothing saved');
......@@ -151,8 +158,6 @@ function OpenMenuItem_Callback(hObject, eventdata, handles)
% disp('Not a dicom');
%end
axes(handles.axes1);
imagesc([0 0; 0 0]);
if( ~isfield(handles, 'path') )
path = uigetdir();
......@@ -194,6 +199,18 @@ set(handles.checkbox_musc,'Value',0,'BackgroundColor','r');
set(handles.checkbox_saved,'Value',0,'BackgroundColor','r');
handles.dcmlist = dcmlist;
handles.needsReload = 1;
%ha = axes(handles.axes1);
ha = handles.axes1;
h = imagesc(ha,zeros(330));
colormap('gray');
%get(h)
set(h,'HitTest','off')
set(h,'PickableParts','none')
get(ha)
set(ha,'ButtonDownFcn',@axes1_ButtonDownFcn)
handles.imageHandle = h;
guidata(hObject,handles);
......@@ -317,7 +334,15 @@ path = handles.dcmlist(imagenum).path;
axes(handles.axes1);
images = dicomread(path);
imagesc(images(:,:,1,1));
%h = imagesc(images(:,:,1,1),'HitTest','off');
set(handles.imageHandle,'CData',images(:,:,1,1))
%h = imagesc(images(:,:,1,1));
set(handles.sliceCount,'String',sprintf('/ %i',size(images,4)));
%get(gca,'HitTest')
%get(gca,'Children')
%get(h)
%set(h,'HitTest','off')
%set(h,'ButtonDownFcn',@axes1_ButtonDownFcn)
tsize = size(images);
display("matrix size");
display(tsize);
......@@ -363,20 +388,96 @@ if ~isempty(text)
end
function redrawImage(hObject, eventdata, handles)
axes(handles.axes1);
images = handles.imageMat;
%h = imagesc(images(:,:,1,1),'HitTest','off');
cs = handles.currentSlice;
gridsize = handles.lungGridSize;
newim = repmat(images(:,:,1,cs),1,1,3);
newim = double(newim);
newim = newim ./ max(newim(:));
lms = handles.lungGridSize;
imsize = size(images);
overlay = zeros(size(newim));
if lms > -1
for n=1:size(handles.lungMatrix,1)-1
for m=1:size(handles.lungMatrix,2)-1
xx = n*lms;
yy = m*lms;
switch handles.lungMatrix(n,m,1,handles.currentSlice)
case 1
cd = [0.2, 0.2, 0.0];
case 2
cd = [0.4,0,0];
case 3
cd = [0,0.4,0];
case 4
cd = [0.1,0.1,0.5];
otherwise
cd = [0 0 0];
end
overlay(yy:yy+lms, xx:xx+lms,1)=cd(1);
overlay(yy:yy+lms, xx:xx+lms,2)=cd(2);
overlay(yy:yy+lms, xx:xx+lms,3)=cd(3);
end
end
end
%size(newim)
%size(overlay)
newim = newim + overlay;
%set(handles.imageHandle,'CData',newim)
h = imagesc(newim);
set(h,'HitTest','off')
set(h,'PickableParts','none')
set(handles.sliceCount,'String',sprintf('/ %i',size(images,4)));
if lms > -1
hold on; for n=0:gridsize:imsize(1);
h = plot([n,n],[0,imsize(2)],'g');
set(h,'HitTest','off')
set(h,'PickableParts','none')
%set(h,'ButtonDownFcn',@axes1_ButtonDownFcn)
end
for n=0:gridsize:imsize(2);
h = plot([0,imsize(1)],[n,n],'g');
set(h,'HitTest','off')
set(h,'PickableParts','none')
%set(h,'ButtonDownFcn',@axes1_ButtonDownFcn)
end
%handles
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)
sv = round(get(handles.slider2,'Value'));
set(handles.slider2,'Value',sv);
handles.currentSlice = sv;
% 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')));
h = imagesc(images(:,:,1,get(handles.slider2,'Value')));
colormap('gray')
set(h,'ButtonDownFcn',@axes1_ButtonDownFcn);
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
......@@ -426,3 +527,133 @@ function slider_color_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in buttonSelectAirway.
function buttonSelectAirway_Callback(hObject, eventdata, handles)
% hObject handle to buttonSelectAirway (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
[x_coord, y_coord]=ginput(2);
gridsize = sqrt((x_coord(2)-x_coord(1)).^2 + (y_coord(2)-y_coord(1)).^2);
gridsize = ceil(gridsize);
imsize = size(handles.imageMat);
lungMatrix = zeros(ceil(imsize(1)./gridsize),ceil(imsize(2)./gridsize),imsize(3),imsize(4));
handles.lungMatrix = lungMatrix;
handles.lungGridSize = gridsize;
hold on; for n=0:gridsize:imsize(1);
h = plot([n,n],[0,imsize(2)],'g');
%set(h,'HitTest','off')
set(h,'ButtonDownFcn',@axes1_ButtonDownFcn)
end
for n=0:gridsize:imsize(2);
h = plot([0,imsize(1)],[n,n],'g');
set(h,'HitTest','off')
set(h,'ButtonDownFcn',@axes1_ButtonDownFcn)
end
%handles
guidata(hObject,handles);
%set(gca, 'ButtonDownFcn', @axes1_ButtonDownFcn);
%ax = gca;
%im.PickableParts = 'none';
%ax.ButtonDownFcn = @mouseClick;
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%gca;
drawnow
handles = guidata(hObject);
%colormap('gray');
disp('yes it ran')
datetime
currentPoint = get(gca, 'currentpoint')
currentBox = currentPoint(1,1:2)
handles
%handles2 = guihandles(hObject)
%handles2
%size(handles.lungMatrix)
lungGridSize = handles.lungGridSize;
lungGridMatSize = size(handles.lungMatrix)
lungMatLoc = floor(currentBox)
lmy = floor(lungMatLoc(1)./size(handles.imageMat,2)*lungGridMatSize(2))
lmx = floor(lungMatLoc(2)./size(handles.imageMat,1)*lungGridMatSize(1))
currentSlice = get(handles.slider2,'Value');
handles.lungMatrix(lmy,lmx,1,currentSlice) = mod(handles.lungMatrix(lmy,lmx,1,currentSlice)+1,5);
handles.lungMatrix(:,:,1,currentSlice);
guidata(hObject, handles)
redrawImage(hObject, eventdata, handles);
%r = rectangle('Position',[lungMatLoc.*lungGridSize lungMatLoc.*lungGridSize+[lungGridSize,lungGridSize]],'FaceColor',[0.5 0.5 0.5] )
%SliderLocation = round(get(handles.slider1,'Value'));
%[xlist ylist]=ginput(5);
%tableData = {xlist(1),ylist(1),SliderLocation};
%set(handles.CoordinateTable,'Data',tableData)
% Update handles structure
guidata(hObject, handles)
function mouseClick(~,~)
disp('yep')
get(gca,'CurrentPoint')
function clicker(h,~)
get(h, 'selectiontype')
% 'normal' for left moue button
% 'alt' for right mouse button
% 'extend' for middle mouse button
% 'open' on double click
get(h, 'currentpoint')
% Current mouse location, in pixels from the lower left.
% When the units of the figure are 'normalized', the
% coordinates will be [0 0] inb lower left, and [1 1] in
% the upper right.
function sliceNum_Callback(hObject, eventdata, handles)
% hObject handle to sliceNum (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 sliceNum as text
% str2double(get(hObject,'String')) returns contents of sliceNum as a double
% --- Executes during object creation, after setting all properties.
function sliceNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to sliceNum (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 key press with focus on sliceNum and none of its controls.
function sliceNum_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to sliceNum (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
set(handles.slider2,'Value',get(handles.sliceNum,'Value'));
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