Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Eamon Doyle
roiTool
Commits
b5ff028b
Commit
b5ff028b
authored
Mar 20, 2024
by
Eamon Doyle
Browse files
mergeRoiTool nearing useful functionality
parent
e2a2baeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
mergeRoiTool.fig
View file @
b5ff028b
No preview for this file type
mergeRoiTool.m
View file @
b5ff028b
...
@@ -3,33 +3,33 @@ function varargout = mergeRoiTool(varargin)
...
@@ -3,33 +3,33 @@ function varargout = mergeRoiTool(varargin)
% ROITOOL, by itself, creates a new ROITOOL or raises the existing
% ROITOOL, by itself, creates a new ROITOOL or raises the existing
% singleton*.
% 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*.
% the existing singleton*.
%
%
%
ROITOOL
('CALLBACK',hObject,eventData,handles,...) calls the local
%
mergeRoiTool
('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in
ROITOOL
.M with the given input arguments.
% 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
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before
r
oiTool_OpeningFcn gets called. An
% applied to the GUI before
mergeR
oiTool_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to
r
oiTool_OpeningFcn via varargin.
% stop. All inputs are passed to
mergeR
oiTool_OpeningFcn via varargin.
%
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
% instance to run (singleton)".
%
%
% See also: GUIDE, GUIDATA, GUI
HANDLES
% See also: GUIDE, GUIDATA, GUI
% Edit the above text to modify the response to help
r
oiTool
% Edit the above text to modify the response to help
mergeR
oiTool
% Last Modified by GUIDE v2.5 1
2-Dec
-20
1
4
13:48:37
% Last Modified by GUIDE v2.5 1
4-Mar
-20
2
4
07:53:15
% Begin initialization code - DO NOT EDIT
% Begin initialization code - DO NOT EDIT
gui_Singleton
=
1
;
gui_Singleton
=
1
;
gui_State
=
struct
(
'gui_Name'
,
mfilename
,
...
gui_State
=
struct
(
'gui_Name'
,
mfilename
,
...
'gui_Singleton'
,
gui_Singleton
,
...
'gui_Singleton'
,
gui_Singleton
,
...
'gui_OpeningFcn'
,
@
r
oiTool_OpeningFcn
,
...
'gui_OpeningFcn'
,
@
mergeR
oiTool_OpeningFcn
,
...
'gui_OutputFcn'
,
@
r
oiTool_OutputFcn
,
...
'gui_OutputFcn'
,
@
mergeR
oiTool_OutputFcn
,
...
'gui_LayoutFcn'
,
[]
,
...
'gui_LayoutFcn'
,
[]
,
...
'gui_Callback'
,
[]);
'gui_Callback'
,
[]);
if
nargin
&&
ischar
(
varargin
{
1
})
if
nargin
&&
ischar
(
varargin
{
1
})
...
@@ -43,36 +43,37 @@ else
...
@@ -43,36 +43,37 @@ else
end
end
% End initialization code - DO NOT EDIT
% End initialization code - DO NOT EDIT
% --- Executes just before
r
oiTool is made visible.
% --- Executes just before
mergeR
oiTool is made visible.
function
r
oiTool_OpeningFcn
(
hObject
,
eventdata
,
handles
,
varargin
)
function
mergeR
oiTool_OpeningFcn
(
hObject
,
eventdata
,
handles
,
varargin
)
% This function has no output args, see OutputFcn.
% This function has no output args, see OutputFcn.
% hObject handle to figure
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to
r
oiTool (see VARARGIN)
% varargin command line arguments to
mergeR
oiTool (see VARARGIN)
% Choose default command line output for
r
oiTool
% Choose default command line output for
mergeR
oiTool
handles
.
output
=
hObject
;
handles
.
output
=
hObject
;
handles
.
needsReload
=
1
;
handles
.
needsReload
=
1
;
handles
.
roi
=
struct
;
handles
.
roi
=
struct
;
handles
.
roiCoords
=
struct
;
handles
.
roiCoords
=
struct
;
handles
.
lungGridSize
=
-
1
;
% Update handles structure
% Update handles structure
guidata
(
hObject
,
handles
);
guidata
(
hObject
,
handles
);
% This sets up the initial plot - only do when we are invisible
% This sets up the initial plot - only do when we are invisible
% so window can get raised using
r
oiTool.
% so window can get raised using
mergeR
oiTool.
set
(
handles
.
progressAxes
,
'XTick'
,
0
,
'YTick'
,
0
);
set
(
handles
.
progressAxes
,
'XTick'
,
0
,
'YTick'
,
0
);
%{
%{
if
strcmp
(
get
(
hObject
,
'Visible'
),
'off'
)
if
strcmp
(
get
(
hObject
,
'Visible'
),
'off'
)
plot
(
rand
(
5
));
plot
(
rand
(
5
));
end
end
%}
%}
% UIWAIT makes
r
oiTool wait for user response (see UIRESUME)
% UIWAIT makes
mergeR
oiTool wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
% --- Outputs from this function are returned to the command line.
function
varargout
=
r
oiTool_OutputFcn
(
hObject
,
eventdata
,
handles
)
function
varargout
=
mergeR
oiTool_OutputFcn
(
hObject
,
eventdata
,
handles
)
% varargout cell array for returning output args (see VARARGOUT);
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% eventdata reserved - to be defined in a future version of MATLAB
...
@@ -107,8 +108,14 @@ else
...
@@ -107,8 +108,14 @@ else
save
([
savePath
'/liver-'
fname
'.mat'
],
'roi'
,
'roiCoords'
)
save
([
savePath
'/liver-'
fname
'.mat'
],
'roi'
,
'roiCoords'
)
set
(
handles
.
checkbox_saved
,
'Value'
,
1
,
'BackgroundColor'
,
'g'
);
set
(
handles
.
checkbox_saved
,
'Value'
,
1
,
'BackgroundColor'
,
'g'
);
axes
(
handles
.
axes1
);
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
;
handles
.
needsReload
=
1
;
msgbox
(
'ROI Saved Successfully'
)
msgbox
(
'ROI Saved Successfully'
)
catch
catch
h
=
warndlg
(
'Save failed. Nothing saved'
);
h
=
warndlg
(
'Save failed. Nothing saved'
);
...
@@ -151,8 +158,6 @@ function OpenMenuItem_Callback(hObject, eventdata, handles)
...
@@ -151,8 +158,6 @@ function OpenMenuItem_Callback(hObject, eventdata, handles)
% disp('Not a dicom');
% disp('Not a dicom');
%end
%end
axes
(
handles
.
axes1
);
imagesc
([
0
0
;
0
0
]);
if
(
~
isfield
(
handles
,
'path'
)
)
if
(
~
isfield
(
handles
,
'path'
)
)
path
=
uigetdir
();
path
=
uigetdir
();
...
@@ -194,6 +199,18 @@ set(handles.checkbox_musc,'Value',0,'BackgroundColor','r');
...
@@ -194,6 +199,18 @@ set(handles.checkbox_musc,'Value',0,'BackgroundColor','r');
set
(
handles
.
checkbox_saved
,
'Value'
,
0
,
'BackgroundColor'
,
'r'
);
set
(
handles
.
checkbox_saved
,
'Value'
,
0
,
'BackgroundColor'
,
'r'
);
handles
.
dcmlist
=
dcmlist
;
handles
.
dcmlist
=
dcmlist
;
handles
.
needsReload
=
1
;
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
);
guidata
(
hObject
,
handles
);
...
@@ -317,7 +334,15 @@ path = handles.dcmlist(imagenum).path;
...
@@ -317,7 +334,15 @@ path = handles.dcmlist(imagenum).path;
axes
(
handles
.
axes1
);
axes
(
handles
.
axes1
);
images
=
dicomread
(
path
);
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
);
tsize
=
size
(
images
);
display
(
"matrix size"
);
display
(
"matrix size"
);
display
(
tsize
);
display
(
tsize
);
...
@@ -363,20 +388,96 @@ if ~isempty(text)
...
@@ -363,20 +388,96 @@ if ~isempty(text)
end
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.
% --- Executes on slider movement.
function
slider2_Callback
(
hObject
,
eventdata
,
handles
)
function
slider2_Callback
(
hObject
,
eventdata
,
handles
)
% hObject handle to slider2 (see GCBO)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 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
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
if
get
(
handles
.
slider2
,
'Max'
)
~=
1.1
if
get
(
handles
.
slider2
,
'Max'
)
~=
1.1
axes
(
handles
.
axes1
);
axes
(
handles
.
axes1
);
images
=
handles
.
imageMat
;
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
end
guidata
(
hObject
,
handles
);
% --- Executes during object creation, after setting all properties.
% --- Executes during object creation, after setting all properties.
function
slider2_CreateFcn
(
hObject
,
eventdata
,
handles
)
function
slider2_CreateFcn
(
hObject
,
eventdata
,
handles
)
...
@@ -426,3 +527,133 @@ function slider_color_CreateFcn(hObject, eventdata, handles)
...
@@ -426,3 +527,133 @@ function slider_color_CreateFcn(hObject, eventdata, handles)
if
isequal
(
get
(
hObject
,
'BackgroundColor'
),
get
(
0
,
'defaultUicontrolBackgroundColor'
))
if
isequal
(
get
(
hObject
,
'BackgroundColor'
),
get
(
0
,
'defaultUicontrolBackgroundColor'
))
set
(
hObject
,
'BackgroundColor'
,[
.
9
.
9
.
9
]);
set
(
hObject
,
'BackgroundColor'
,[
.
9
.
9
.
9
]);
end
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'
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment