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
| function test(I)
if nargin==0
r = 25;
c = 30;
n = 10;
I = rand(r,c,n);
else
[r, c, n] = size(I);
end
fig = figure('doublebuffer', 'on', ...
'windowscrollwheelfcn', @wswfcn);
colormap(jet);
ax = axes('units', 'normalized', ...
'position', [.1 .15 .8 .8], ...
'tag', 'ImageAxes', ...
'xlim',[.5 c+.5], ...
'ylim',[.5 r+.5], ...
'dataaspectratio', [1 1 1], ...
'xtick', [], ...
'ytick', []);
title(ax, sprintf('Image %d/%d', 1, n));
imagesc('cdata',I(:,:,1), ...
'parent', ax, ...
'tag', 'Image')
uicontrol('style', 'edit', ...
'units', 'normalized', ...
'position', [.8 .05 .1 .05], ...
'tag', 'SliceEdit', ...
'string', '1', ...
'callback', @sliceCall);
uicontrol('style', 'slider', ...
'units', 'normalized', ...
'position', [.1 .05 .6 .05], ...
'tag', 'Slicebar', ...
'min', 1, ...
'max', n, ...
'sliderstep', [1 1]/(n-1), ...
'value', 1, ...
'callback', @sliceCall);
handles = guihandles(fig);
handles.s3 = 1;
handles.s = n;
handles.ImX = I;
guidata(fig,handles);
function sliceCall(obj, event)
handles = guidata(gcbf);
switch get(obj, 'tag')
case 'Slicebar'
handles.s3 = round(get(obj,'value'));
case 'SliceEdit'
ns = str2double(get(obj,'string'));
ns = round(ns);
if ns>0 && ns<=handles.s
handles.s3 = ns;
end
end
update_uis(handles);
guidata(gcbf,handles);
function wswfcn(obj,event)
handles = guidata(gcbf);
r = event.VerticalScrollCount;
r = r/abs(r);
if (handles.s3+r)<1 || (handles.s3+r)>handles.s
return
end
handles.s3 = handles.s3+r;
update_uis(handles);
guidata(gcbf,handles);
function update_uis(h)
set(h.SliceEdit, 'string', num2str(h.s3));
set(h.Slicebar, 'value', h.s3);
set(h.Image, 'cdata', h.ImX(:,:,h.s3));
title(h.ImageAxes, sprintf('Image %d/%d', h.s3, h.s)); |
Partager