0001 function avw_view(avw),
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 if ~exist('avw','var'),
0033 msg = sprintf('...no input avw - see help avw_view\n');
0034 error(msg);
0035 end
0036
0037
0038
0039 switch double(avw.hdr.dime.bitpix),
0040 case 1,
0041 fprintf('...converting avw.img to uint8\n');
0042 avw.img = uint8(avw.img);
0043 case 8,
0044 fprintf('...converting avw.img to uint8\n');
0045 avw.img = uint8(avw.img);
0046 case 16,
0047 fprintf('...converting avw.img to uint16\n');
0048 avw.img = uint16(avw.img);
0049 case {32,64},
0050 fprintf('...ensuring avw.img is double\n');
0051
0052 avw.img = double(avw.img);
0053 otherwise,
0054
0055 end
0056
0057
0058
0059
0060 GUIwidth = 150;
0061 GUIheight = 50;
0062 if isfield(avw,'fileprefix'),
0063 if isempty(avw.fileprefix),
0064 name = 'AVW View';
0065 else
0066 format = strcat('%+',sprintf('%d',length(avw.fileprefix)+1),'s');
0067 name = strcat('AVW View - ',sprintf(format,avw.fileprefix));
0068 end
0069 else
0070 name = 'AVW View';
0071 end
0072
0073 GUI = figure('Name',name,'Tag','AVWVIEW','units','characters',...
0074 'NumberTitle','off',...
0075 'MenuBar','figure','Position',[1 1 GUIwidth GUIheight]);
0076 movegui(GUI,'center');
0077
0078 AVWVIEW.gui = GUI;
0079
0080
0081 Font.FontName = 'Helvetica';
0082 Font.FontUnits = 'Pixels';
0083 Font.FontSize = 12;
0084 Font.FontWeight = 'normal';
0085 Font.FontAngle = 'normal';
0086
0087
0088 shading flat
0089
0090
0091
0092
0093 xdim = size(avw.img,1);
0094 ydim = size(avw.img,2);
0095 zdim = size(avw.img,3);
0096
0097 SagSlice = 1;
0098 CorSlice = 1;
0099 AxiSlice = 1;
0100 if xdim > 1, SagSlice = floor(xdim/2); end
0101 if ydim > 1, CorSlice = floor(ydim/2); end
0102 if zdim > 1, AxiSlice = floor(zdim/2); end
0103
0104 AVWVIEW.origin = [SagSlice,CorSlice,AxiSlice];
0105 AVWVIEW.scale = double(avw.hdr.dime.pixdim(2:4)) ./ 1000;
0106
0107
0108
0109 G.Ha = 0;
0110 G.Hc = 0;
0111 G.Hs = 0;
0112
0113
0114
0115
0116
0117 if xdim > 1 & ydim > 1,
0118
0119 G.Aa = subplot('position',[0.05 0.56 0.4 0.4]);
0120 colormap('gray');
0121
0122 Saxial = squeeze(avw.img(:,:,AxiSlice));
0123 G.Ha = imagesc([0,xdim],[0,ydim],Saxial');
0124 set(gca,'YDir','normal')
0125
0126 axis square, daspect([1,1,1]);
0127 xlabel('(Left <<) X (>> Right)')
0128 ylabel('Y')
0129 title('Axial')
0130
0131
0132 set(G.Ha,'ButtonDownFcn',...
0133 strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0134 'currentpoint = get(get(AVWVIEW.handles.Ha,''Parent''),''CurrentPoint''); ',...
0135 'SagSlice = round(currentpoint(2,1)); ',...
0136 'CorSlice = round(currentpoint(2,2)); ',...
0137 'AxiSlice = round(str2num(get(AVWVIEW.handles.Taxi,''String''))); ',...
0138 'imgvalue = double(AVWVIEW.avw.img(SagSlice,CorSlice,AxiSlice)); ',...
0139 'set(AVWVIEW.handles.imval,''String'',sprintf(''%8.2f'',imgvalue));',...
0140 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0141 'if ishandle(AVWVIEW.handles.Hs) & AVWVIEW.handles.Hs, ',...
0142 ' Ssag = squeeze(AVWVIEW.avw.img(SagSlice,:,:));',...
0143 ' set(AVWVIEW.handles.Hs,''CData'',Ssag''); ',...
0144 ' set(AVWVIEW.handles.Tsag,''String'',num2str(SagSlice));',...
0145 ' set(AVWVIEW.handles.Ssag,''Value'',SagSlice);',...
0146 ' clear Ssag; ',...
0147 ' set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0148 'end; ',...
0149 'if ishandle(AVWVIEW.handles.Hc) & AVWVIEW.handles.Hc, ',...
0150 ' Scor = squeeze(AVWVIEW.avw.img(:,CorSlice,:));',...
0151 ' set(AVWVIEW.handles.Hc,''CData'',Scor''); ',...
0152 ' set(AVWVIEW.handles.Tcor,''String'',num2str(CorSlice));',...
0153 ' set(AVWVIEW.handles.Scor,''Value'',CorSlice);',...
0154 ' clear Scor; ',...
0155 ' set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0156 'end; ',...
0157 'clear currentpoint imgvalue AxiSlice CorSlice SagSlice AVWVIEW;'));
0158
0159 if zdim > 1,
0160 slider_step(1) = 1/(zdim);
0161 slider_step(2) = 1/(zdim);
0162 G.Saxi = uicontrol('Parent',GUI,'Style','slider','Units','Normalized', Font, ...
0163 'Position',[.45 .56 .03 .40], 'HorizontalAlignment', 'center',...
0164 'BusyAction','queue',...
0165 'Min',1,'Max',zdim,'SliderStep',slider_step,'Value',AxiSlice,...
0166 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0167 'AxiSlice = round(get(AVWVIEW.handles.Saxi,''Value''));',...
0168 'set(AVWVIEW.handles.Saxi,''Value'',AxiSlice);',...
0169 'Saxi = squeeze(AVWVIEW.avw.img(:,:,AxiSlice));',...
0170 'set(AVWVIEW.handles.Ha,''CData'',Saxi''); ',...
0171 'set(AVWVIEW.handles.Taxi,''String'',num2str(AxiSlice));',...
0172 'CorSlice = round(get(AVWVIEW.handles.Scor,''Value''));',...
0173 'SagSlice = round(get(AVWVIEW.handles.Ssag,''Value''));',...
0174 'imgvalue = double(AVWVIEW.avw.img(SagSlice,CorSlice,AxiSlice)); ',...
0175 'set(AVWVIEW.handles.imval,''String'',sprintf(''%8.2f'',imgvalue));',...
0176 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0177 'clear imgvalue Saxi AxiSlice CorSlice SagSlice AVWVIEW;'));
0178 end
0179 G.Taxi = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0180 'Position',[.45 .51 .03 .05], 'HorizontalAlignment', 'center',...
0181 'BusyAction','queue',...
0182 'String',num2str(AxiSlice));
0183 end
0184
0185
0186
0187
0188
0189 if xdim > 1 & zdim > 1,
0190
0191 subplot('position',[0.55 0.56 0.4 0.4])
0192 colormap('gray');
0193
0194 Scor = squeeze(avw.img(:,CorSlice,:));
0195 G.Hc = imagesc([0,ydim],[0,zdim],Scor');
0196 set(gca,'YDir','normal')
0197
0198 axis square, daspect([1,1,1]);
0199 xlabel('(Left <<) X (>> Right)')
0200 ylabel('Z')
0201 title('Coronal')
0202
0203
0204 set(G.Hc,'ButtonDownFcn',...
0205 strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0206 'currentpoint = get(get(AVWVIEW.handles.Hc,''Parent''),''CurrentPoint''); ',...
0207 'SagSlice = round(currentpoint(2,1)); ',...
0208 'AxiSlice = round(currentpoint(2,2)); ',...
0209 'CorSlice = round(str2num(get(AVWVIEW.handles.Tcor,''String''))); ',...
0210 'imgvalue = double(AVWVIEW.avw.img(SagSlice,CorSlice,AxiSlice)); ',...
0211 'set(AVWVIEW.handles.imval,''String'',sprintf(''%8.2f'',imgvalue));',...
0212 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0213 'if ishandle(AVWVIEW.handles.Hs) & AVWVIEW.handles.Hs, ',...
0214 ' Ssag = squeeze(AVWVIEW.avw.img(SagSlice,:,:));',...
0215 ' set(AVWVIEW.handles.Hs,''CData'',Ssag''); ',...
0216 ' set(AVWVIEW.handles.Tsag,''String'',num2str(SagSlice));',...
0217 ' set(AVWVIEW.handles.Ssag,''Value'',SagSlice);',...
0218 ' clear Ssag; ',...
0219 ' set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0220 'end; ',...
0221 'if ishandle(AVWVIEW.handles.Ha) & AVWVIEW.handles.Ha, ',...
0222 ' Saxi = squeeze(AVWVIEW.avw.img(:,:,AxiSlice));',...
0223 ' set(AVWVIEW.handles.Ha,''CData'',Saxi''); ',...
0224 ' set(AVWVIEW.handles.Taxi,''String'',num2str(AxiSlice));',...
0225 ' set(AVWVIEW.handles.Saxi,''Value'',AxiSlice);',...
0226 ' clear Saxi; ',...
0227 ' set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0228 'end; ',...
0229 'clear currentpoint imgvalue AxiSlice CorSlice SagSlice AVWVIEW;'));
0230
0231 if ydim > 1,
0232 slider_step(1) = 1/(ydim);
0233 slider_step(2) = 1/(ydim);
0234 G.Scor = uicontrol('Parent',GUI,'Style','slider','Units','Normalized', Font, ...
0235 'Position',[.95 .56 .03 .40], 'HorizontalAlignment', 'center',...
0236 'BusyAction','queue',...
0237 'Min',1,'Max',ydim,'SliderStep',slider_step,'Value',CorSlice,...
0238 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0239 'CorSlice = round(get(AVWVIEW.handles.Scor,''Value''));',...
0240 'set(AVWVIEW.handles.Scor,''Value'',CorSlice);',...
0241 'Scor = squeeze(AVWVIEW.avw.img(:,CorSlice,:));',...
0242 'set(AVWVIEW.handles.Hc,''CData'',Scor); drawnow;',...
0243 'set(AVWVIEW.handles.Tcor,''String'',num2str(CorSlice));',...
0244 'AxiSlice = round(get(AVWVIEW.handles.Saxi,''Value''));',...
0245 'SagSlice = round(get(AVWVIEW.handles.Ssag,''Value''));',...
0246 'imgvalue = double(AVWVIEW.avw.img(SagSlice,CorSlice,AxiSlice)); ',...
0247 'set(AVWVIEW.handles.imval,''String'',sprintf(''%8.2f'',imgvalue));',...
0248 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0249 'clear imgvalue Scor AxiSlice CorSlice SagSlice AVWVIEW;'));
0250 end
0251 G.Tcor = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0252 'Position',[.95 .51 .03 .05], 'HorizontalAlignment', 'center',...
0253 'BusyAction','queue',...
0254 'String',num2str(CorSlice));
0255 end
0256
0257
0258
0259
0260
0261 if ydim > 1 & ydim > 1,
0262
0263 [y,z] = meshgrid(1:ydim,1:zdim);
0264 Ysag = y'; clear y;
0265 Zsag = z'; clear z;
0266 Xsag = zeros(ydim,zdim);
0267
0268 subplot('position',[0.05 0.06 0.4 0.4])
0269 colormap('gray');
0270
0271 Ssag = squeeze(avw.img(SagSlice,:,:));
0272 G.Hs = imagesc([0,ydim],[0,zdim],Ssag');
0273 set(gca,'YDir','normal')
0274
0275 axis square, daspect([1,1,1]);
0276 xlabel('Y')
0277 ylabel('Z')
0278 title('Sagittal')
0279
0280
0281 set(G.Hs,'ButtonDownFcn',...
0282 strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0283 'currentpoint = get(get(AVWVIEW.handles.Hs,''Parent''),''CurrentPoint''); ',...
0284 'CorSlice = round(currentpoint(1,1)); ',...
0285 'AxiSlice = round(currentpoint(1,2)); ',...
0286 'SagSlice = round(str2num(get(AVWVIEW.handles.Tsag,''String'')));',...
0287 'imgvalue = double(AVWVIEW.avw.img(SagSlice,CorSlice,AxiSlice)); ',...
0288 'set(AVWVIEW.handles.imval,''String'',sprintf(''%8.2f'',imgvalue));',...
0289 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0290 'if ishandle(AVWVIEW.handles.Hc) & AVWVIEW.handles.Hc, ',...
0291 ' Scor = squeeze(AVWVIEW.avw.img(:,CorSlice,:));',...
0292 ' set(AVWVIEW.handles.Hc,''CData'',Scor''); ',...
0293 ' set(AVWVIEW.handles.Tcor,''String'',num2str(CorSlice));',...
0294 ' set(AVWVIEW.handles.Scor,''Value'',CorSlice);',...
0295 ' clear Scor; ',...
0296 ' set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0297 'end; ',...
0298 'if ishandle(AVWVIEW.handles.Ha) & AVWVIEW.handles.Ha, ',...
0299 ' Saxi = squeeze(AVWVIEW.avw.img(:,:,AxiSlice));',...
0300 ' set(AVWVIEW.handles.Ha,''CData'',Saxi''); ',...
0301 ' set(AVWVIEW.handles.Taxi,''String'',num2str(AxiSlice));',...
0302 ' set(AVWVIEW.handles.Saxi,''Value'',AxiSlice);',...
0303 ' clear Saxi; ',...
0304 ' set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0305 'end; ',...
0306 'clear currentpoint imgvalue AxiSlice CorSlice SagSlice AVWVIEW;'));
0307
0308
0309 if xdim > 1,
0310 slider_step(1) = 1/(xdim);
0311 slider_step(2) = 1/(xdim);
0312 G.Ssag = uicontrol('Parent',GUI,'Style','slider','Units','Normalized', Font, ...
0313 'Position',[.45 .06 .03 .4], 'HorizontalAlignment', 'center',...
0314 'BusyAction','queue',...
0315 'Min',1,'Max',xdim,'SliderStep',slider_step,'Value',SagSlice,...
0316 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0317 'SagSlice = round(get(AVWVIEW.handles.Ssag,''Value''));',...
0318 'set(AVWVIEW.handles.Ssag,''Value'',SagSlice);',...
0319 'Ssag = squeeze(AVWVIEW.avw.img(SagSlice,:,:));',...
0320 'set(AVWVIEW.handles.Hs,''CData'',Ssag); drawnow;',...
0321 'set(AVWVIEW.handles.Tsag,''String'',num2str(SagSlice));',...
0322 'AxiSlice = round(get(AVWVIEW.handles.Saxi,''Value''));',...
0323 'CorSlice = round(get(AVWVIEW.handles.Scor,''Value''));',...
0324 'imgvalue = double(AVWVIEW.avw.img(SagSlice,CorSlice,AxiSlice)); ',...
0325 'set(AVWVIEW.handles.imval,''String'',sprintf(''%8.2f'',imgvalue));',...
0326 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0327 'clear imgvalue Ssag AxiSlice CorSlice SagSlice AVWVIEW;'));
0328 end
0329 G.Tsag = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0330 'Position',[.45 .01 .03 .05], 'HorizontalAlignment', 'center',...
0331 'BusyAction','queue',...
0332 'String',num2str(SagSlice));
0333 end
0334
0335
0336
0337
0338
0339
0340 G.Timval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0341 'Position',[.575 .40 .20 .05], 'HorizontalAlignment', 'left',...
0342 'BusyAction','queue',...
0343 'String','Image Intensity');
0344 G.imval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0345 'Position',[.775 .40 .20 .05], 'HorizontalAlignment', 'right',...
0346 'BusyAction','queue',...
0347 'String','x');
0348
0349
0350
0351
0352
0353
0354
0355 G.Tnasion = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0356 'Position',[.575 .35 .20 .04], 'HorizontalAlignment', 'left',...
0357 'BusyAction','queue',...
0358 'TooltipString','Update Nasion - should be toward +Y',...
0359 'String','Fiducial: Nasion',...
0360 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0361 'SagSlice = get(AVWVIEW.handles.Ssag,''Value'');',...
0362 'CorSlice = get(AVWVIEW.handles.Scor,''Value'');',...
0363 'AxiSlice = get(AVWVIEW.handles.Saxi,''Value'');',...
0364 'imgXYZ = [SagSlice,CorSlice,AxiSlice]; ',...
0365 'imgXYZ = (imgXYZ - AVWVIEW.origin) .* AVWVIEW.scale; ',...
0366 'set(AVWVIEW.handles.nasion,''String'',sprintf(''%6.3f %6.3f %6.3f'',imgXYZ));',...
0367 'AVWVIEW.p.mriFID(1,:) = imgXYZ; ',...
0368 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0369 'clear imgXYZ AxiSlice CorSlice SagSlice AVWVIEW;'));
0370 G.nasion = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0371 'Position',[.775 .35 .20 .04], 'HorizontalAlignment', 'right',...
0372 'BusyAction','queue',...
0373 'TooltipString','Should be toward +Y; values in meters, origin translated from center of volume to (0,0,0).',...
0374 'String','x,y,z');
0375
0376
0377 G.Trpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0378 'Position',[.575 .30 .20 .04], 'HorizontalAlignment', 'left',...
0379 'BusyAction','queue',...
0380 'TooltipString','Update Right Preauricular - should be toward +X',...
0381 'String','Fiducial: RPA',...
0382 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0383 'SagSlice = get(AVWVIEW.handles.Ssag,''Value'');',...
0384 'CorSlice = get(AVWVIEW.handles.Scor,''Value'');',...
0385 'AxiSlice = get(AVWVIEW.handles.Saxi,''Value'');',...
0386 'imgXYZ = [SagSlice,CorSlice,AxiSlice]; ',...
0387 'imgXYZ = (imgXYZ - AVWVIEW.origin) .* AVWVIEW.scale; ',...
0388 'set(AVWVIEW.handles.rpa,''String'',sprintf(''%6.3f %6.3f %6.3f'',imgXYZ));',...
0389 'AVWVIEW.p.mriFID(2,:) = imgXYZ; ',...
0390 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0391 'clear imgXYZ AxiSlice CorSlice SagSlice AVWVIEW;'));
0392 G.rpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0393 'Position',[.775 .30 .20 .04], 'HorizontalAlignment', 'right',...
0394 'BusyAction','queue',...
0395 'TooltipString','Should be toward +X; values in meters, origin translated from center of volume to (0,0,0).',...
0396 'String','x,y,z');
0397
0398
0399 G.Tlpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0400 'Position',[.575 .25 .20 .04], 'HorizontalAlignment', 'left',...
0401 'BusyAction','queue',...
0402 'TooltipString','Update Left Preauricular - should be toward -X',...
0403 'String','Fiducial: LPA',...
0404 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0405 'SagSlice = get(AVWVIEW.handles.Ssag,''Value'');',...
0406 'CorSlice = get(AVWVIEW.handles.Scor,''Value'');',...
0407 'AxiSlice = get(AVWVIEW.handles.Saxi,''Value'');',...
0408 'imgXYZ = [SagSlice,CorSlice,AxiSlice]; ',...
0409 'imgXYZ = (imgXYZ - AVWVIEW.origin) .* AVWVIEW.scale; ',...
0410 'set(AVWVIEW.handles.lpa,''String'',sprintf(''%6.3f %6.3f %6.3f'',imgXYZ));',...
0411 'AVWVIEW.p.mriFID(3,:) = imgXYZ; ',...
0412 'set(AVWVIEW.gui,''UserData'',AVWVIEW);',...
0413 'clear imgXYZ AxiSlice CorSlice SagSlice AVWVIEW;'));
0414 G.lpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
0415 'Position',[.775 .25 .20 .04], 'HorizontalAlignment', 'right',...
0416 'BusyAction','queue',...
0417 'TooltipString','Should be toward -X; values in meters, origin translated from center of volume to (0,0,0).',...
0418 'String','x,y,z');
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431 Font.FontWeight = 'bold';
0432
0433
0434 G.Bhdr = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0435 'Position',[.8 .01 .08 .04],...
0436 'String','HDR','BusyAction','queue',...
0437 'TooltipString','Save the hdr parameters.',...
0438 'BackgroundColor',[0.0 0.0 0.5],...
0439 'ForegroundColor',[1 1 1], 'HorizontalAlignment', 'center',...
0440 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0441 'avw_view_hdr(AVWVIEW.avw);',...
0442 'clear AVWVIEW;'));
0443
0444
0445 G.Bquit = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0446 'Position',[.9 .01 .08 .04],...
0447 'String','RETURN','BusyAction','queue',...
0448 'BackgroundColor',[0.75 0.0 0.0],...
0449 'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0450 'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
0451 'if isfield(AVWVIEW,''p''), ',...
0452 ' if isfield(AVWVIEW.p,''mriFID''), ',...
0453 ' if exist(''p'',''var''), ',...
0454 ' p.mriFID = AVWVIEW.p.mriFID; ',...
0455 ' else, ',...
0456 ' mriFID = AVWVIEW.p.mriFID;',...
0457 ' end; ',...
0458 ' end; ',...
0459 'end; ',...
0460 'clear AVWVIEW; close gcbf;'));
0461
0462
0463
0464 AVWVIEW.avw = avw;
0465 AVWVIEW.handles = G;
0466 set(AVWVIEW.gui,'Userdata',AVWVIEW);
0467 set(AVWVIEW.gui,'HandleVisibility','callback');
0468
0469 return