-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsliceview.m
139 lines (116 loc) · 4.28 KB
/
sliceview.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function sliceview(inp, titlename,sc)
%function sliceview(inp, titlename,sc)
%------------------------------------------------------
% Displays slices of volumetric image set. It is memory friendly
% This "v3.0" version works on both cell arrays and ct objects
% inp, can be an 3D array, a CT object of cell array or matrix
% It enables a slider to change the current slice view,
% titlename, is optional adds the filename as the title
% sc, is optional CLIM = [CLOW, CHIGH] to scale image values for display
% default behaviour of the display will scale between min and max of the slice.
% version: 1.0
% date: 06.05.08
% updated 20.05.08 added sc parameter
% sc is CLIM = [CLOW, CHIGH] to use in imagescale to scale values for
% desired interval.
% written: B. Tek
%
% version: 2.0
% date : 30.05.08
% desired interval.
% written: B. Tek
% version: 3.0
% date : 09.05.08
% changing default behaviour of the display. It will scale with scan max
% and min the all slices.
% B.Tek
% Copyright 2008-2013 F. Boray Tek.
% All rights reserved.
%
% This file is part of CT class.
%
% CT class is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% CT class is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with CT class. If not, see <http://www.gnu.org/licenses/>.
switch nargin
case 0
disp('function "sliceview" displayes an image formed of slices..')
disp('usage: sliceview(inp, titlename*)')
return
case 1
titlename = 'Unknown';
sc = 0 ;
case 2
sc = 0;
end
if (isa(inp, 'CT'))
[nrows, ncols,nslice] = size(inp); % take size
if (sc==0)
sc(1)= min(inp);
sc(2)= max(inp);
end
elseif (iscell(inp))
nslice = length(inp);
[nrows, ncols] = size(inp{1}); % take size
% convert to 3-d array. It is not the best.
else
% else do this
[nrows, ncols, nslice] = size(inp); % take size
if ( islogical(inp))
inp = uint8(inp);
else
if (sc==0)
sc(1)= min(inp(:));
sc(2)= max(inp(:));
end
end
end
disp(strcat('Displaying set of: ', int2str(nslice),' slices')); %Display what you read
fg_hnd = figure('Visible','off','Position',[0,0,650,650]); % create a figure, f is the handle
ax_hnd = axes('Units','Pixels','Position',[70,70,512,512]); % create an axes
st_hnd = uicontrol(fg_hnd,'Style','text','String','Data Set name','Units','Pixels','Position',[20 620 500 30]); % create and static textbox for filename
slice_txt_hnd = uicontrol(fg_hnd,'Style','text','String','Data Set name','Units','Pixels','Position',[50 600 500 30]); % create a static textbox for slice number
sld_hnd = uicontrol(fg_hnd,'Style','slider','Max',nslice,'Min',1,'Value',1,'SliderStep',...
[1/(nslice-1) 1/(nslice-1)*20],'Position',[250 20 100 20],'Callback',{@SliceNumberChange_Callback,inp,ax_hnd,slice_txt_hnd,nslice,sc}); %create a slider for the slice manuplation.
% put a name
set(fg_hnd,'Name','Slice View');
% write the name of the file
if(~isempty(titlename))
set(st_hnd,'String',titlename);
end
% Move the GUI to the center of the screen.
movegui(fg_hnd,'center');
% Make the GUI visible.
set(fg_hnd,'Visible','on');
SliceNumberChange_Callback(sld_hnd,0,inp,ax_hnd,slice_txt_hnd,nslice,sc);
% Slider callback..
function SliceNumberChange_Callback(hObject,eventdata,inpt_img,ax_hndle,txt_hndl, n_slice,clim)
axes(ax_hndle);
s = get(hObject,'value'); % get slider value
s = fix(s);
if ( (s > n_slice) || (s<1) )
return;
end
set(txt_hndl,'String',strcat(' Slice: ',int2str(s))); % set the textbox filename with slice no;
if (isa(inpt_img, 'CT'))
slice = getslice(inpt_img,s);
elseif (iscell(inpt_img))
slice = inpt_img{s};
elseif (isnumeric(inpt_img))
slice = inpt_img(:,:,s);
end
if (clim ==0 )
image(slice,'Parent',ax_hndle); %
else
image(slice,'CDataMapping','scaled', 'Parent',ax_hndle); %
set(ax_hndle,'CLim',clim);
end
%impixelinfo(ax_hndle);