-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstackViewTool.m
More file actions
132 lines (113 loc) · 5.24 KB
/
stackViewTool.m
File metadata and controls
132 lines (113 loc) · 5.24 KB
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
classdef stackViewTool < handle
properties
Figure
FigureContext
Axis
PlaneHandle
PlaneIndex
NPlanes
Volume
Dialog
LowerThreshold
UpperThreshold
LowerThresholdSlider
UpperThresholdSlider
FigurePlot
AxisPlotPosition
Data
end
methods
function tool = stackViewTool(V,varargin)
% stackViewTool(V)
% A tool to visualize a stack of planes
% V should be m by n by z 'double' and in the range [0,1]
% z is the number of frames
%
% example:
% load mri
% V = double(squeeze(D))/255;
% stackViewTool(V)
%
% optional arguments allow a per-plane plot alongside the stack view:
% stackViewTool(V,squeeze(sum(sum(V,1),2)),'sum of pixel intensities');
tool.Volume = V;
tool.NPlanes = size(V,3);
tool.PlaneIndex = 1;
tool.LowerThreshold = 0;
tool.UpperThreshold = 1;
% z
tool.Figure = figure('Name','Frame','NumberTitle','off','CloseRequestFcn',@tool.closeTool);
tool.Axis = axes('Parent',tool.Figure,'Position',[0 0 1 1]);
I = tool.Volume(:,:,tool.PlaneIndex);
tool.PlaneHandle = imshow(tool.applyThresholds(I));
tool.Axis.Title.String = sprintf('frame %d', tool.PlaneIndex);
dwidth = 1000;%300;
dborder = 10;
cwidth = dwidth-2*dborder;
cheight = 20;
tool.Dialog = dialog('WindowStyle', 'normal', 'Resize', 'on',...
'Name', 'StackViewTool',...
'CloseRequestFcn', @tool.closeTool,...
'Position',[100 100 dwidth 4*dborder+4*cheight]);
% z slider
uicontrol('Parent',tool.Dialog,'Style','text','String','f','Position',[dborder 3*dborder+3*cheight 20 cheight]);
slider = uicontrol('Parent',tool.Dialog,'Style','slider','Min',1,'Max',tool.NPlanes,'Value',tool.PlaneIndex,'Position',[dborder+20 3*dborder+3*cheight cwidth-20 cheight],'Tag','zs');
addlistener(slider,'Value','PostSet',@tool.continuousSliderManage);
% lower threshold slider
uicontrol('Parent',tool.Dialog,'Style','text','String','_t','Position',[dborder 2*dborder+cheight 20 cheight]);
tool.LowerThresholdSlider = uicontrol('Parent',tool.Dialog,'Style','slider','Min',0,'Max',1,'Value',tool.LowerThreshold,'Position',[dborder+20 2*dborder+cheight cwidth-20 cheight],'Tag','lts');
addlistener(tool.LowerThresholdSlider,'Value','PostSet',@tool.continuousSliderManage);
% upper threshold slider
uicontrol('Parent',tool.Dialog,'Style','text','String','^t','Position',[dborder dborder 20 cheight]);
tool.UpperThresholdSlider = uicontrol('Parent',tool.Dialog,'Style','slider','Min',0,'Max',1,'Value',tool.UpperThreshold,'Position',[dborder+20 dborder cwidth-20 cheight],'Tag','uts');
addlistener(tool.UpperThresholdSlider,'Value','PostSet',@tool.continuousSliderManage);
if nargin > 1
tfp = tool.Figure.Position;
tfp(1) = tfp(1)+tfp(3)+20;
tool.FigurePlot = figure('Name','Data','NumberTitle','off','CloseRequestFcn',@tool.closeTool,'Position',tfp);
tool.Data = varargin{1};
plot(1:length(tool.Data),tool.Data)
hold on
tool.AxisPlotPosition = plot(tool.PlaneIndex,tool.Data(tool.PlaneIndex),'o');
hold off
axis tight
title(varargin{2})
end
% uiwait(tool.Dialog)
end
function continuousSliderManage(tool,~,callbackdata)
tag = callbackdata.AffectedObject.Tag;
value = callbackdata.AffectedObject.Value;
if strcmp(tag,'uts') || strcmp(tag,'lts')
if strcmp(tag,'uts')
tool.UpperThreshold = value;
elseif strcmp(tag,'lts')
tool.LowerThreshold = value;
end
I = tool.Volume(:,:,tool.PlaneIndex);
tool.PlaneHandle.CData = tool.applyThresholds(I);
elseif strcmp(tag,'zs')
tool.PlaneIndex = round(value);
I = tool.Volume(:,:,tool.PlaneIndex);
tool.PlaneHandle.CData = tool.applyThresholds(I);
tool.Axis.Title.String = sprintf('frame %d', tool.PlaneIndex);
if ~isempty(tool.FigurePlot)
tool.AxisPlotPosition.XData = tool.PlaneIndex;
tool.AxisPlotPosition.YData = tool.Data(tool.PlaneIndex);
end
end
end
function T = applyThresholds(tool,I)
T = I;
T(T < tool.LowerThreshold) = tool.LowerThreshold;
T(T > tool.UpperThreshold) = tool.UpperThreshold;
T = T-min(T(:));
T = T/max(T(:));
end
function closeTool(tool,~,~)
delete(tool.Figure)
delete(tool.FigurePlot);
delete(tool.Dialog);
end
end
end