0001 function [ varargout ] = avw_view_ras(avw,parent,command),
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
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 if ~isempty(gcbf),
0054 AVWVIEW = get(gcbf,'Userdata');
0055 end
0056
0057 if ~exist('command','var'), command = 'init'; end
0058
0059 command = lower(command);
0060
0061
0062 if strcmp(command, 'keypress'),
0063
0064 cc = get(AVWVIEW.gui,'CurrentCharacter');
0065 cc = double(cc);
0066 if cc,
0067 switch cc,
0068
0069 case 28, command = 'left';
0070 case 29, command = 'right';
0071 case 30, command = 'up';
0072 case 31, command = 'down';
0073 case 127, command = 'left';
0074 otherwise, return;
0075 end
0076 end
0077 end
0078
0079 switch command,
0080
0081 case 'init',
0082
0083 if ~exist('avw','var'),
0084 avw = avw_read_ras;
0085 end
0086
0087 if nargin == 0,
0088 AVWVIEW = init(avw);
0089 elseif isempty(inputname(1)),
0090 AVWVIEW = init(avw);
0091 else
0092 AVWVIEW = init(avw,inputname(1));
0093 end
0094
0095 AVWVIEW = set_coordinates(AVWVIEW);
0096 AVWVIEW = set_crosshairs(AVWVIEW);
0097
0098
0099
0100
0101 case 'coordinates',
0102
0103 AVWVIEW = set_coordinates(AVWVIEW);
0104
0105
0106
0107
0108 case 'crosshairs',
0109
0110 AVWVIEW = set_crosshairs(AVWVIEW);
0111
0112
0113
0114
0115 case {'axial_image','coronal_image','sagittal_image'},
0116
0117 switch command,
0118 case 'axial_image', AVWVIEW.view = 'axi'; axi_update = 0; cor_update = 1; sag_update = 1;
0119 case 'coronal_image', AVWVIEW.view = 'cor'; axi_update = 1; cor_update = 0; sag_update = 1;
0120 case 'sagittal_image', AVWVIEW.view = 'sag'; axi_update = 1; cor_update = 1; sag_update = 0;
0121 end
0122
0123 AVWVIEW = get_current_position(AVWVIEW);
0124
0125 if axi_update,
0126 axial_update(AVWVIEW);
0127 end
0128 if cor_update,
0129 coronal_update(AVWVIEW);
0130 end;
0131 if sag_update,
0132 sagittal_update(AVWVIEW);
0133 end;
0134
0135 set_display_values(AVWVIEW);
0136
0137 AVWVIEW = set_crosshairs(AVWVIEW);
0138
0139
0140
0141
0142
0143 case {'axial_slider','coronal_slider','sagittal_slider'},
0144
0145 switch command,
0146
0147 case 'axial_slider',
0148 AVWVIEW.view = 'axi';
0149 AVWVIEW = get_slider_position(AVWVIEW);
0150 axial_update(AVWVIEW);
0151
0152 case 'coronal_slider',
0153 AVWVIEW.view = 'cor';
0154 AVWVIEW = get_slider_position(AVWVIEW);
0155 coronal_update(AVWVIEW);
0156
0157 case 'sagittal_slider',
0158 AVWVIEW.view = 'sag';
0159 AVWVIEW = get_slider_position(AVWVIEW);
0160 sagittal_update(AVWVIEW);
0161 end
0162
0163 set_display_values(AVWVIEW);
0164
0165 AVWVIEW = set_crosshairs(AVWVIEW);
0166
0167
0168
0169
0170
0171 case {'left','right','up','down'},
0172
0173 AVWVIEW = get_slider_position(AVWVIEW);
0174
0175
0176 if isequal(gca, AVWVIEW.handles.axial_axes),
0177 switch command,
0178 case 'left',
0179
0180 if AVWVIEW.slices.sag > 1,
0181 AVWVIEW.slices.sag = AVWVIEW.slices.sag - 1;
0182 end
0183 case 'right',
0184
0185 if AVWVIEW.slices.sag < AVWVIEW.xdim,
0186 AVWVIEW.slices.sag = AVWVIEW.slices.sag + 1;
0187 end
0188 case 'up',
0189
0190 if AVWVIEW.slices.cor < AVWVIEW.ydim,
0191 AVWVIEW.slices.cor = AVWVIEW.slices.cor + 1;
0192 end
0193 case 'down',
0194
0195 if AVWVIEW.slices.cor > 1,
0196 AVWVIEW.slices.cor = AVWVIEW.slices.cor - 1;
0197 end
0198 end
0199 switch command,
0200 case {'left','right'}
0201 set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0202 Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0203 set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0204 set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0205 set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0206 case {'up','down'},
0207 set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0208 Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0209 set(AVWVIEW.handles.coronal_image,'CData',Scor');
0210 set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0211 set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0212 end
0213 end
0214
0215 if isequal(gca, AVWVIEW.handles.coronal_axes),
0216 switch command,
0217 case 'left',
0218
0219 if AVWVIEW.slices.sag > 1,
0220 AVWVIEW.slices.sag = AVWVIEW.slices.sag - 1;
0221 end
0222 case 'right',
0223
0224 if AVWVIEW.slices.sag < AVWVIEW.xdim,
0225 AVWVIEW.slices.sag = AVWVIEW.slices.sag + 1;
0226 end
0227 case 'up',
0228
0229 if AVWVIEW.slices.axi < AVWVIEW.zdim,
0230 AVWVIEW.slices.axi = AVWVIEW.slices.axi + 1;
0231 end
0232 case 'down',
0233
0234 if AVWVIEW.slices.axi > 1,
0235 AVWVIEW.slices.axi = AVWVIEW.slices.axi - 1;
0236 end
0237 end
0238 switch command,
0239 case {'left','right'}
0240 set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0241 Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0242 set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0243 set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0244 set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0245 case {'up','down'},
0246 set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0247 Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0248 set(AVWVIEW.handles.axial_image,'CData',Saxi');
0249 set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0250 set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0251 end
0252 end
0253
0254 if isequal(gca, AVWVIEW.handles.sagittal_axes),
0255 switch command,
0256 case 'left',
0257
0258 if AVWVIEW.slices.cor > 1,
0259 AVWVIEW.slices.cor = AVWVIEW.slices.cor - 1;
0260 end
0261 case 'right',
0262
0263 if AVWVIEW.slices.cor < AVWVIEW.ydim,
0264 AVWVIEW.slices.cor = AVWVIEW.slices.cor + 1;
0265 end
0266 case 'up',
0267
0268 if AVWVIEW.slices.axi < AVWVIEW.zdim,
0269 AVWVIEW.slices.axi = AVWVIEW.slices.axi + 1;
0270 end
0271 case 'down',
0272
0273 if AVWVIEW.slices.axi > 1,
0274 AVWVIEW.slices.axi = AVWVIEW.slices.axi - 1;
0275 end
0276 end
0277 switch command,
0278 case {'left','right'}
0279 set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0280 Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0281 set(AVWVIEW.handles.coronal_image,'CData',Scor');
0282 set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0283 set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0284 case {'up','down'},
0285 set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0286 Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0287 set(AVWVIEW.handles.axial_image,'CData',Saxi');
0288 set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0289 set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0290 end
0291 end
0292
0293 AVWVIEW = set_crosshairs(AVWVIEW);
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 case {'roi_9','roi_7','roi_5','roi_3'},
0306
0307 position = [ AVWVIEW.slices.sag, AVWVIEW.slices.cor, AVWVIEW.slices.axi ];
0308
0309 shape.type = 'block';
0310 if findstr(command,'9'), shape.size = [9,9,9]; end
0311 if findstr(command,'7'), shape.size = [7,7,7]; end
0312 if findstr(command,'5'), shape.size = [5,5,5]; end
0313 if findstr(command,'3'), shape.size = [3,3,3]; end
0314
0315 stats.roi = avw_roi(AVWVIEW.avw,position,shape);
0316
0317 AVWVIEW.avw.stats = avw_stats(stats);
0318
0319
0320
0321
0322
0323 case {'nasion','rpa','lpa','ac'},
0324
0325
0326 AVWVIEW = slices2metric(AVWVIEW);
0327
0328 if get(AVWVIEW.handles.coord,'value') == 2,
0329 format = '%7.3f %7.3f %7.3f';
0330 imgXYZ = AVWVIEW.imgXYZ.mm;
0331 string = sprintf('%7.3f %7.3f %7.3f',imgXYZ);
0332 elseif get(AVWVIEW.handles.coord,'value') == 3,
0333 format = '%7.3f %7.3f %7.3f';
0334 imgXYZ = AVWVIEW.imgXYZ.meters;
0335 string = sprintf('%7.3f %7.3f %7.3f',imgXYZ);
0336 else
0337 imgXYZ = AVWVIEW.imgXYZ.voxels;
0338 string = sprintf('%7.0f %7.0f %7.0f',imgXYZ);
0339 end;
0340
0341 switch command,
0342 case 'nasion',
0343 set(AVWVIEW.handles.nasion,'String',string);
0344 AVWVIEW.avw.fiducials.nasion.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0345 AVWVIEW.avw.fiducials.nasion.meters(1,:) = AVWVIEW.imgXYZ.meters;
0346 AVWVIEW.avw.fiducials.nasion.mm(1,:) = AVWVIEW.imgXYZ.mm;
0347 case 'rpa',
0348 set(AVWVIEW.handles.rpa,'String',string);
0349 AVWVIEW.avw.fiducials.rpa.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0350 AVWVIEW.avw.fiducials.rpa.meters(1,:) = AVWVIEW.imgXYZ.meters;
0351 AVWVIEW.avw.fiducials.rpa.mm(1,:) = AVWVIEW.imgXYZ.mm;
0352 case 'lpa',
0353 set(AVWVIEW.handles.lpa,'String',string);
0354 AVWVIEW.avw.fiducials.lpa.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0355 AVWVIEW.avw.fiducials.lpa.meters(1,:) = AVWVIEW.imgXYZ.meters;
0356 AVWVIEW.avw.fiducials.lpa.mm(1,:) = AVWVIEW.imgXYZ.mm;
0357 case 'ac',
0358 set(AVWVIEW.handles.ac,'String',string);
0359 AVWVIEW.avw.ac.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0360 AVWVIEW.avw.ac.meters(1,:) = AVWVIEW.imgXYZ.meters;
0361 AVWVIEW.avw.ac.mm(1,:) = AVWVIEW.imgXYZ.mm;
0362 end
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372 case 'flip',
0373
0374
0375 AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
0376
0377 if isfield(AVWVIEW.handles,'axial_image'),
0378 Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0379 set(AVWVIEW.handles.axial_image,'CData',Saxi');
0380 end;
0381 if isfield(AVWVIEW.handles,'coronal_image'),
0382 Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0383 set(AVWVIEW.handles.coronal_image,'CData',Scor');
0384 end;
0385 if isfield(AVWVIEW.handles,'sagittal_image'),
0386 Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0387 set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0388 end;
0389
0390 flipStatus = get(AVWVIEW.handles.flipStatus,'string');
0391 if strmatch(flipStatus,'R>>L (radiological)'),
0392 flipStatus = 'L>>R (neurological)';
0393 else,
0394 flipStatus = 'R>>L (radiological)';
0395 end;
0396 set(AVWVIEW.handles.flipStatus,'string',flipStatus);
0397
0398
0399
0400
0401
0402
0403
0404
0405 case {'brighter','dimmer','setclimit'},
0406
0407 switch command,
0408 case 'brighter',
0409 AVWVIEW.clim = AVWVIEW.clim .* 0.9;
0410 case 'dimmer',
0411 AVWVIEW.clim = AVWVIEW.clim .* 1.1;
0412 case 'setclimit',
0413 clim = get(AVWVIEW.handles.clim,'string');
0414 AVWVIEW.clim(2) = str2num(clim);
0415 end
0416 climString = sprintf('%05.2f',AVWVIEW.clim(2));
0417 set(AVWVIEW.handles.clim,'string',climString);
0418
0419 if isfield(AVWVIEW.handles,'axial_image'),
0420 set(AVWVIEW.handles.axial_axes,'Clim',AVWVIEW.clim);
0421 end;
0422 if isfield(AVWVIEW.handles,'coronal_image'),
0423 set(AVWVIEW.handles.coronal_axes,'Clim',AVWVIEW.clim);
0424 end;
0425 if isfield(AVWVIEW.handles,'sagittal_image'),
0426 set(AVWVIEW.handles.sagittal_axes,'Clim',AVWVIEW.clim);
0427 end;
0428
0429
0430
0431
0432
0433
0434 case 'contrast'
0435
0436 if isfield(AVWVIEW.handles,'axial_image'),
0437 X = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0438 AVWVIEW.cmap = contrast(X);
0439 colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0440 end;
0441 if isfield(AVWVIEW.handles,'coronal_image'),
0442 X = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0443 AVWVIEW.cmap = contrast(X);
0444 colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0445 end;
0446 if isfield(AVWVIEW.handles,'sagittal_image'),
0447 X = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0448 AVWVIEW.cmap = contrast(X);
0449 colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0450 end;
0451
0452
0453
0454
0455
0456
0457 case 'setcmap'
0458
0459 cmapIndex = get(AVWVIEW.handles.cmap,'value');
0460 cmapString = get(AVWVIEW.handles.cmap,'string');
0461
0462 AVWVIEW.cmapString = cmapString{cmapIndex};
0463
0464 if isfield(AVWVIEW.handles,'axial_image'),
0465 AVWVIEW.cmap = colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmapString);
0466 end;
0467 if isfield(AVWVIEW.handles,'coronal_image'),
0468 AVWVIEW.cmap = colormap(AVWVIEW.handles.coronal_axes,AVWVIEW.cmapString);
0469 end;
0470 if isfield(AVWVIEW.handles,'sagittal_image'),
0471 AVWVIEW.cmap = colormap(AVWVIEW.handles.sagittal_axes,AVWVIEW.cmapString);
0472 end;
0473
0474
0475
0476
0477
0478
0479 case 'histogram',
0480
0481 avw = AVWVIEW.avw;
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495 intensity_min = min(min(min(avw.img)));
0496 intensity_max = max(max(max(avw.img)));
0497
0498 bins = intensity_min:intensity_max;
0499
0500 fprintf('...calculating histogram for %d bins.\n',length(bins));
0501
0502 for i=1:size(avw.img,3),
0503 n = hist(avw.img(:,:,i), bins);
0504 if i == 1,
0505 intensity_volume = sum(n,2);
0506 else
0507 intensity_slice = sum(n,2);
0508 intensity_volume = intensity_volume + intensity_slice;
0509 end
0510 end
0511 figure('name','intensity histogram');
0512 bar(bins,intensity_volume);
0513
0514
0515
0516
0517
0518
0519 case 'zoom'
0520
0521 x = AVWVIEW.slices.sag;
0522 y = AVWVIEW.slices.cor;
0523 z = AVWVIEW.slices.axi;
0524
0525 switch AVWVIEW.view,
0526 case 'axi',
0527 slice = rot90(AVWVIEW.avw.img(:,:,z));
0528 case 'cor',
0529 slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0530 case 'sag',
0531 slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0532 end
0533
0534 figure;
0535 imagesc(slice,AVWVIEW.clim);
0536 colormap(gray); axis off; zoom on;
0537 daspect(AVWVIEW.daspect);
0538
0539
0540
0541
0542
0543
0544 case 'save_image',
0545
0546 [filename, pathname] = uiputfile(...
0547 { '*.png','PNG Files (*.png)'; ...
0548 '*.jpg','JPG Files (*.jpg)'; ...
0549 '*.ppm;*.pgm;*.pbm','Portable Anymap (*.ppm,*.pgm,*.pbm)'; ...
0550 '*.*', 'All Files (*.*)'}, ...
0551 'IMWrite to file');
0552
0553 if filename,
0554
0555 x = AVWVIEW.slices.sag;
0556 y = AVWVIEW.slices.cor;
0557 z = AVWVIEW.slices.axi;
0558
0559 pixelsPerMM = 1 ./ double(AVWVIEW.avw.hdr.dime.pixdim(2:4));
0560 pixelsPerMeter = pixelsPerMM .* 1000;
0561
0562 switch AVWVIEW.view,
0563 case 'axi',
0564 slice = rot90(AVWVIEW.avw.img(:,:,z));
0565 xresolution = pixelsPerMeter(1);
0566 yresolution = pixelsPerMeter(2);
0567 case 'cor',
0568 slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0569 xresolution = pixelsPerMeter(1);
0570 yresolution = pixelsPerMeter(3);
0571 case 'sag',
0572 slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0573 xresolution = pixelsPerMeter(2);
0574 yresolution = pixelsPerMeter(3);
0575 end
0576
0577
0578
0579
0580
0581
0582 scaledSlice = slice ./ AVWVIEW.clim(2);
0583
0584
0585
0586
0587 file = [pathname,filename];
0588 fprintf('saving to:...%s\n',file);
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598 [pathname,filename,ext] = fileparts([pathname,filename]);
0599
0600 switch ext,
0601
0602 case '.png',
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613 format = 'png';
0614 imwrite(scaledSlice,file,format,...
0615 'BitDepth',16,'ResolutionUnit','meter',...
0616 'XResolution',xresolution,...
0617 'YResolution',yresolution);
0618
0619 case '.jpg',
0620 format = 'jpg';
0621 imwrite(scaledSlice,file,format);
0622 case {'.ppm','.pgm','.pbm'},
0623 format = ext(2:end);
0624 imwrite(scaledSlice,file,format);
0625 otherwise
0626 fprintf('...cannot write %s image files\n',ext);
0627 end
0628 end
0629
0630
0631
0632
0633
0634
0635
0636 case 'save',
0637
0638 if ~isempty(AVWVIEW.invarname),
0639 fprintf('...returning data to base workspace struct ''%s''\n',AVWVIEW.invarname);
0640 assignin('base',AVWVIEW.invarname,AVWVIEW.avw);
0641 elseif evalin('base','exist(''mri'',''var'')'),
0642 fprintf('...returning data to base workspace struct ''mri''\n');
0643 string = ['AVWVIEW = get(', num2str(AVWVIEW.gui),...
0644 ',''Userdata''); mri.data = AVWVIEW.avw; clear AVWVIEW;'];
0645 evalin('base',string);
0646 else
0647 fprintf('...returning data into base workspace struct ''avw''\n');
0648 assignin('base','avw',AVWVIEW.avw);
0649 end
0650
0651 [filename, pathname] = uiputfile('*.mat','Save fiducials');
0652 if isequal(filename,0) | isequal(pathname,0)
0653 disp('filename not specified.')
0654 else
0655 fiducials = AVWVIEW.avw.fiducials;
0656 vb_fsave([fullfile(pathname, filename)], 'fiducials');
0657 end
0658
0659
0660
0661
0662
0663 case 'close',
0664 fprintf('...returning data into base workspace struct ''avw''\n');
0665 assignin('base','avw',AVWVIEW.avw);
0666 close gcbf;
0667
0668 otherwise,
0669 end
0670
0671 switch command,
0672 case 'save',
0673 case 'close',
0674 otherwise,
0675 set(AVWVIEW.gui,'UserData',AVWVIEW);
0676 end
0677
0678 if nargout > 0,
0679 varargout{1} = AVWVIEW.avw;
0680 end
0681
0682 return
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701 function axial_update(AVWVIEW)
0702
0703 if isfield(AVWVIEW.handles,'axial_image'),
0704 Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0705 set(AVWVIEW.handles.axial_image,'CData',Saxi');
0706 end
0707 if isfield(AVWVIEW.handles,'axial_sliderN'),
0708 set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0709 set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0710 end
0711 if isfield(AVWVIEW.handles,'axial_slider'),
0712 set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0713 end;
0714
0715 return
0716
0717
0718
0719 function coronal_update(AVWVIEW)
0720
0721 if isfield(AVWVIEW.handles,'coronal_image'),
0722 Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0723 set(AVWVIEW.handles.coronal_image,'CData',Scor');
0724 end
0725 if isfield(AVWVIEW.handles,'coronal_sliderN'),
0726 set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0727 set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0728 end
0729 if isfield(AVWVIEW.handles,'coronal_slider'),
0730 set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0731 end;
0732
0733 return
0734
0735
0736
0737 function sagittal_update(AVWVIEW)
0738
0739 if isfield(AVWVIEW.handles,'sagittal_image'),
0740 Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0741 set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0742 end
0743 if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0744 set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0745 set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0746 end
0747 if isfield(AVWVIEW.handles,'sagittal_slider'),
0748 set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0749 end;
0750
0751 return
0752
0753
0754
0755 function AVWVIEW = set_crosshairs(AVWVIEW)
0756
0757 fig = figure(AVWVIEW.gui);
0758 current_axes = get(fig, 'CurrentAxes');
0759
0760 [AVWVIEW, metric] = slices2metric(AVWVIEW);
0761
0762 if isfield(AVWVIEW.handles,'axial_axes'),
0763 set(fig, 'CurrentAxes', AVWVIEW.handles.axial_axes);
0764
0765 x_value = [metric.sag metric.sag];
0766 y_value = [metric.cor metric.cor];
0767
0768 AVWVIEW.handles.axial_xlim = get(AVWVIEW.handles.axial_axes,'Xlim');
0769 AVWVIEW.handles.axial_ylim = get(AVWVIEW.handles.axial_axes,'Ylim');
0770 set(AVWVIEW.handles.axial_xline, 'Xdata', x_value,'Ydata',AVWVIEW.handles.axial_ylim);
0771 set(AVWVIEW.handles.axial_yline, 'Ydata', y_value,'Xdata',AVWVIEW.handles.axial_xlim);
0772 set(AVWVIEW.handles.axial_xline,'Color','y','Tag','XLINE');
0773 set(AVWVIEW.handles.axial_yline,'Color','y','Tag','YLINE');
0774
0775 if get(AVWVIEW.handles.crosshairs,'value'),
0776 set(AVWVIEW.handles.axial_xline,'visible','on');
0777 set(AVWVIEW.handles.axial_yline,'visible','on');
0778 else
0779 set(AVWVIEW.handles.axial_xline,'visible','off');
0780 set(AVWVIEW.handles.axial_yline,'visible','off');
0781 end
0782
0783 end
0784
0785 if isfield(AVWVIEW.handles,'coronal_axes'),
0786 set(fig, 'CurrentAxes', AVWVIEW.handles.coronal_axes);
0787
0788 x_value = [metric.sag metric.sag];
0789 y_value = [metric.axi metric.axi];
0790
0791 AVWVIEW.handles.coronal_xlim = get(AVWVIEW.handles.coronal_axes,'Xlim');
0792 AVWVIEW.handles.coronal_ylim = get(AVWVIEW.handles.coronal_axes,'Ylim');
0793 set(AVWVIEW.handles.coronal_xline, 'Xdata',x_value,'Ydata',AVWVIEW.handles.coronal_ylim);
0794 set(AVWVIEW.handles.coronal_yline, 'Ydata',y_value,'Xdata',AVWVIEW.handles.coronal_xlim);
0795 set(AVWVIEW.handles.coronal_xline,'Color','y','Tag','XLINE');
0796 set(AVWVIEW.handles.coronal_yline,'Color','y','Tag','YLINE');
0797
0798
0799 if get(AVWVIEW.handles.crosshairs,'value'),
0800 set(AVWVIEW.handles.coronal_xline,'visible','on');
0801 set(AVWVIEW.handles.coronal_yline,'visible','on');
0802 else
0803 set(AVWVIEW.handles.coronal_xline,'visible','off');
0804 set(AVWVIEW.handles.coronal_yline,'visible','off');
0805 end
0806
0807 end
0808
0809 if isfield(AVWVIEW.handles,'sagittal_axes'),
0810 set(fig, 'CurrentAxes', AVWVIEW.handles.sagittal_axes);
0811
0812 x_value = [metric.cor metric.cor];
0813 y_value = [metric.axi metric.axi];
0814
0815 AVWVIEW.handles.sagittal_xlim = get(AVWVIEW.handles.sagittal_axes,'Xlim');
0816 AVWVIEW.handles.sagittal_ylim = get(AVWVIEW.handles.sagittal_axes,'Ylim');
0817 set(AVWVIEW.handles.sagittal_xline, 'Xdata',x_value,'Ydata',AVWVIEW.handles.sagittal_ylim);
0818 set(AVWVIEW.handles.sagittal_yline, 'Ydata',y_value,'Xdata',AVWVIEW.handles.sagittal_xlim);
0819 set(AVWVIEW.handles.sagittal_xline,'Color','y','Tag','XLINE');
0820 set(AVWVIEW.handles.sagittal_yline,'Color','y','Tag','YLINE');
0821
0822 if get(AVWVIEW.handles.crosshairs,'value'),
0823 set(AVWVIEW.handles.sagittal_xline,'visible','on');
0824 set(AVWVIEW.handles.sagittal_yline,'visible','on');
0825 else
0826 set(AVWVIEW.handles.sagittal_xline,'visible','off');
0827 set(AVWVIEW.handles.sagittal_yline,'visible','off');
0828 end
0829
0830 end
0831
0832 set(fig, 'CurrentAxes', current_axes);
0833
0834 return
0835
0836
0837 function AVWVIEW = set_coordinates(AVWVIEW)
0838
0839
0840
0841 s = size(AVWVIEW.avw.img);
0842 if length(s) > 0, xdim = s(1); else xdim = 1; end
0843 if length(s) > 1, ydim = s(2); else ydim = 1; end
0844 if length(s) > 2, zdim = s(3); else zdim = 1; end
0845
0846
0847 xpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(2));
0848 ypixdim = double(AVWVIEW.avw.hdr.dime.pixdim(3));
0849 zpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(4));
0850 xdata = [0 xdim];
0851 ydata = [0 ydim];
0852 zdata = [0 zdim];
0853
0854 aspect = 1./AVWVIEW.daspect;
0855
0856
0857 if get(AVWVIEW.handles.coord,'value') == 2,
0858 xdata = xdata .* xpixdim;
0859 ydata = ydata .* ypixdim;
0860 zdata = zdata .* zpixdim;
0861 aspect = [1 1 1];
0862 end
0863
0864 if get(AVWVIEW.handles.coord,'value') == 3,
0865 xpixdim = xpixdim / 1000;
0866 ypixdim = ypixdim / 1000;
0867 zpixdim = zpixdim / 1000;
0868 xdata = xdata .* xpixdim;
0869 ydata = ydata .* ypixdim;
0870 zdata = zdata .* zpixdim;
0871 aspect = [1 1 1];
0872 end
0873
0874
0875 if isfield(AVWVIEW.handles,'axial_image'),
0876 set(AVWVIEW.handles.axial_axes,'Xlim',xdata);
0877 set(AVWVIEW.handles.axial_axes,'Ylim',ydata);
0878 set(AVWVIEW.handles.axial_axes,'Zlim',zdata);
0879 set(AVWVIEW.handles.axial_image,'Xdata',xdata);
0880 set(AVWVIEW.handles.axial_image,'Ydata',ydata);
0881 daspect(AVWVIEW.handles.axial_axes,aspect([1 2 3]));
0882 end;
0883 if isfield(AVWVIEW.handles,'coronal_image'),
0884 set(AVWVIEW.handles.coronal_axes,'Xlim',xdata);
0885 set(AVWVIEW.handles.coronal_axes,'Ylim',zdata);
0886 set(AVWVIEW.handles.coronal_axes,'Zlim',ydata);
0887 set(AVWVIEW.handles.coronal_image,'Xdata',xdata);
0888 set(AVWVIEW.handles.coronal_image,'Ydata',zdata);
0889 daspect(AVWVIEW.handles.coronal_axes,aspect([1 3 2]));
0890 end;
0891 if isfield(AVWVIEW.handles,'sagittal_image'),
0892 set(AVWVIEW.handles.sagittal_axes,'Xlim',ydata);
0893 set(AVWVIEW.handles.sagittal_axes,'Ylim',zdata);
0894 set(AVWVIEW.handles.sagittal_axes,'Zlim',xdata);
0895 set(AVWVIEW.handles.sagittal_image,'Xdata',ydata);
0896 set(AVWVIEW.handles.sagittal_image,'Ydata',zdata);
0897 daspect(AVWVIEW.handles.sagittal_axes,aspect([2 3 1]));
0898 end;
0899
0900 set_display_values(AVWVIEW);
0901 set_crosshairs(AVWVIEW);
0902
0903 return
0904
0905
0906
0907
0908
0909 function AVWVIEW = get_current_position(AVWVIEW),
0910
0911
0912
0913 if get(AVWVIEW.handles.coord,'value') == 3
0914 devide = 1000;
0915 else
0916 devide = 1;
0917 end
0918
0919 switch AVWVIEW.view,
0920 case 'sag',
0921 currentpoint = get(get(AVWVIEW.handles.sagittal_image,'Parent'),'CurrentPoint');
0922 metric.cor = currentpoint(1,1);
0923 metric.axi = currentpoint(1,2);
0924 metric.sag = get(AVWVIEW.handles.sagittal_slider,'Value') / devide;
0925 case 'cor',
0926 currentpoint = get(get(AVWVIEW.handles.coronal_image,'Parent'),'CurrentPoint');
0927 metric.sag = currentpoint(2,1);
0928 metric.axi = currentpoint(2,2);
0929 metric.cor = get(AVWVIEW.handles.coronal_slider,'Value') / devide;
0930 case 'axi',
0931 currentpoint = get(get(AVWVIEW.handles.axial_image,'Parent'),'CurrentPoint');
0932 metric.sag = currentpoint(2,1);
0933 metric.cor = currentpoint(2,2);
0934 metric.axi = get(AVWVIEW.handles.axial_slider,'Value') / devide;
0935 end
0936
0937 AVWVIEW = metric2slices(AVWVIEW,metric);
0938 AVWVIEW = check_slices(AVWVIEW);
0939
0940 return
0941
0942
0943
0944
0945
0946 function AVWVIEW = get_slider_position(AVWVIEW),
0947
0948 [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi] = deal(0);
0949
0950 if isfield(AVWVIEW.handles,'sagittal_slider'),
0951 if ishandle(AVWVIEW.handles.sagittal_slider),
0952 AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_slider,'Value'));
0953 end
0954 end
0955 if AVWVIEW.slices.sag == 0,
0956 if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0957 if ishandle(AVWVIEW.handles.sagittal_sliderN),
0958 AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_sliderN,'Value'));
0959 end
0960 end
0961 end
0962
0963 if isfield(AVWVIEW.handles,'coronal_slider'),
0964 if ishandle(AVWVIEW.handles.coronal_slider),
0965 AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_slider,'Value'));
0966 end
0967 end
0968 if AVWVIEW.slices.cor == 0,
0969 if isfield(AVWVIEW.handles,'coronal_sliderN'),
0970 if ishandle(AVWVIEW.handles.coronal_sliderN),
0971 AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_sliderN,'Value'));
0972 end
0973 end
0974 end
0975
0976 if isfield(AVWVIEW.handles,'axial_slider'),
0977 if ishandle(AVWVIEW.handles.axial_slider),
0978 AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_slider,'Value'));
0979 end
0980 end
0981 if AVWVIEW.slices.axi == 0,
0982 if isfield(AVWVIEW.handles,'axial_sliderN'),
0983 if ishandle(AVWVIEW.handles.axial_sliderN),
0984 AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_sliderN,'Value'));
0985 end
0986 end
0987 end
0988
0989 AVWVIEW = check_slices(AVWVIEW);
0990
0991 return
0992
0993
0994
0995 function AVWVIEW = check_slices(AVWVIEW),
0996
0997 adjust = 0;
0998
0999 [ SagSize, CorSize, AxiSize ] = size(AVWVIEW.avw.img);
1000
1001 if AVWVIEW.slices.sag > SagSize,
1002 AVWVIEW.slices.sag = SagSize;
1003 adjust = 1;
1004 end;
1005 if AVWVIEW.slices.sag < 1,
1006 AVWVIEW.slices.sag = 1;
1007 adjust = 1;
1008 end;
1009 if AVWVIEW.slices.cor > CorSize,
1010 AVWVIEW.slices.cor = CorSize;
1011 adjust = 1;
1012 end;
1013 if AVWVIEW.slices.cor < 1,
1014 AVWVIEW.slices.cor = 1;
1015 adjust = 1;
1016 end;
1017 if AVWVIEW.slices.axi > AxiSize,
1018 AVWVIEW.slices.axi = AxiSize;
1019 adjust = 1;
1020 end;
1021 if AVWVIEW.slices.axi < 1,
1022 AVWVIEW.slices.axi = 1;
1023 adjust = 1;
1024 end;
1025
1026 if adjust,
1027 AVWVIEW = slices2metric(AVWVIEW);
1028 end
1029
1030 return
1031
1032
1033
1034 function set_display_values(AVWVIEW),
1035
1036
1037
1038 sag = AVWVIEW.slices.sag;
1039 cor = AVWVIEW.slices.cor;
1040 axi = AVWVIEW.slices.axi;
1041
1042 imgvalue = AVWVIEW.avw.img(sag,cor,axi);
1043
1044 set(AVWVIEW.handles.imval,'String',sprintf('%7.2f',imgvalue));
1045 set(AVWVIEW.handles.imval,'Value',imgvalue);
1046
1047
1048
1049 [AVWVIEW, metric] = slices2metric(AVWVIEW);
1050 sag = metric.sag;
1051 cor = metric.cor;
1052 axi = metric.axi;
1053
1054 string = sprintf('%7.3f %7.3f %7.3f',sag,cor,axi);
1055
1056 set(AVWVIEW.handles.impos,'String',string);
1057 set(AVWVIEW.handles.impos,'Value',[sag,cor,axi]);
1058
1059 return
1060
1061
1062
1063 function [AVWVIEW,metric] = slices2metric(AVWVIEW),
1064
1065 AVWVIEW.imgXYZ.voxels = [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi];
1066 AVWVIEW.imgXYZ.meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1067 AVWVIEW.imgXYZ.mm = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1068
1069 coord_value = get(AVWVIEW.handles.coord,'value');
1070
1071 if coord_value == 2,
1072
1073 img_mm = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1074 metric.axi = img_mm(3);
1075 metric.cor = img_mm(2);
1076 metric.sag = img_mm(1);
1077 elseif coord_value == 3,
1078
1079 img_meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1080 metric.axi = img_meters(3);
1081 metric.cor = img_meters(2);
1082 metric.sag = img_meters(1);
1083 else
1084
1085 metric.axi = AVWVIEW.slices.axi;
1086 metric.cor = AVWVIEW.slices.cor;
1087 metric.sag = AVWVIEW.slices.sag;
1088 end;
1089
1090 return
1091
1092
1093
1094 function AVWVIEW = metric2slices(AVWVIEW,metric),
1095
1096 coord_value = get(AVWVIEW.handles.coord,'value');
1097
1098 if coord_value == 2,
1099
1100 xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2));
1101 ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3));
1102 zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4));
1103 AVWVIEW.slices.axi = round(metric.axi / zpix);
1104 AVWVIEW.slices.cor = round(metric.cor / ypix);
1105 AVWVIEW.slices.sag = round(metric.sag / xpix);
1106 elseif coord_value == 3,
1107
1108 xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2)) / 1000;
1109 ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3)) / 1000;
1110 zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4)) / 1000;
1111 AVWVIEW.slices.axi = round(metric.axi / zpix);
1112 AVWVIEW.slices.cor = round(metric.cor / ypix);
1113 AVWVIEW.slices.sag = round(metric.sag / xpix);
1114 else
1115
1116 AVWVIEW.slices.axi = round(metric.axi);
1117 AVWVIEW.slices.cor = round(metric.cor);
1118 AVWVIEW.slices.sag = round(metric.sag);
1119 end;
1120
1121 return
1122
1123
1124
1125
1126
1127
1128 function AVWVIEW = init(avw,invarname),
1129
1130
1131 if exist('invarname','var'),
1132 if ~isempty(invarname),
1133 AVWVIEW.invarname = invarname;
1134 else
1135 AVWVIEW.invarname = '';
1136 end
1137 else
1138 AVWVIEW.invarname = '';
1139 end
1140
1141
1142 GUIwidth = 1;
1143 GUIheight = 1/3;
1144
1145 version = '[$Revision: 2025 $]';
1146 name = sprintf('AVW View [v%s]',version(12:16));
1147
1148 if isfield(avw,'fileprefix'),
1149 if ~isempty(avw.fileprefix),
1150 format = strcat('%+',sprintf('%d',length(avw.fileprefix)+1),'s');
1151 name = strcat(name,' - ',sprintf(format,avw.fileprefix));
1152 end
1153 end
1154
1155
1156 GUI = figure('Name',name,'Tag','AVWVIEW','units','Normalized',...
1157 'BackingStore','off',...
1158 'NumberTitle','off','color',[0 0 0],...
1159 'MenuBar','figure','Position',[0 0.1 1.0 0.8],...
1160 'Renderer','zbuffer');
1161
1162 movegui(GUI,'center');
1163
1164 set(GUI,'KeyPressFcn','avw_view_ras([],[],''keypress'');');
1165
1166 AVWVIEW.gui = GUI;
1167
1168 Font.FontName = 'Helvetica';
1169 Font.FontUnits = 'Pixels';
1170 Font.FontSize = 15;
1171 Font.FontWeight = 'normal';
1172 Font.FontAngle = 'normal';
1173
1174
1175 AVWVIEW.shading = 'flat';
1176 shading(AVWVIEW.shading)
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200 intensityMean = mean(mean(mean(avw.img)));
1201 intensityMeanRobust = mean(mean(mean(avw.img(find(avw.img)))));
1202 intensityStdev = std(std(std(avw.img)));
1203
1204 intensityMax = max(max(max(avw.img)));
1205
1206
1207 if intensityMax > 255,
1208
1209 adjust = 0.5;
1210 else
1211 adjust = 0.9;
1212 end
1213
1214 AVWVIEW.clim = [0 (intensityMax * adjust)];
1215
1216
1217
1218 AVWVIEW.xdim = size(avw.img,1);
1219 AVWVIEW.ydim = size(avw.img,2);
1220 AVWVIEW.zdim = size(avw.img,3);
1221
1222 AVWVIEW.slices.sag = 1;
1223 AVWVIEW.slices.cor = 1;
1224 AVWVIEW.slices.axi = 1;
1225 if AVWVIEW.xdim > 1, AVWVIEW.slices.sag = floor(AVWVIEW.xdim/2); end
1226 if AVWVIEW.ydim > 1, AVWVIEW.slices.cor = floor(AVWVIEW.ydim/2); end
1227 if AVWVIEW.zdim > 1, AVWVIEW.slices.axi = floor(AVWVIEW.zdim/2); end
1228
1229
1230
1231 center = avw_center(avw);
1232 AVWVIEW.center = center.abs.voxels;
1233
1234
1235 AVWVIEW.origin = AVWVIEW.center;
1236
1237 AVWVIEW.pixdim = double(avw.hdr.dime.pixdim(2:4));
1238
1239 AVWVIEW.scale2mm = AVWVIEW.pixdim;
1240 AVWVIEW.scale2meters = AVWVIEW.pixdim ./ 1000;
1241 AVWVIEW.daspect = AVWVIEW.pixdim ./ min(AVWVIEW.pixdim);
1242
1243 xPlotSize = 0.38;
1244 yPlotSize = 0.38;
1245
1246 AVWVIEW.cmapString = 'gray';
1247
1248 AVWVIEW.cmap = colormap(AVWVIEW.cmapString);
1249
1250
1251
1252
1253 if AVWVIEW.xdim > 1 & AVWVIEW.ydim > 1,
1254
1255 handles.axial_subplot = subplot('position',[0.075 0.075 xPlotSize yPlotSize]);
1256
1257
1258
1259
1260 Saxial = squeeze(avw.img(:,:,AVWVIEW.slices.axi));
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273 handles.axial_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.ydim],Saxial',AVWVIEW.clim);
1274
1275 handles.axial_axes = gca;
1276 set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1277 'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1278
1279 title('Axial','Color',[1 1 1])
1280 ylabel('Y')
1281 xlabel('Left ----- X ----- Right')
1282
1283
1284
1285
1286 set(handles.axial_image,'ButtonDownFcn','avw_view_ras([],[],''axial_image'');');
1287
1288 GUIheight = 0.46;
1289
1290 if AVWVIEW.zdim > 1,
1291 slider_step(1) = 1/(AVWVIEW.zdim);
1292 slider_step(2) = 1/(AVWVIEW.zdim);
1293 handles.axial_slider = uicontrol('Parent',GUI,'Style','slider',...
1294 'Units','Normalized', Font, ...
1295 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1296 'BusyAction','queue',...
1297 'TooltipString','Axial slice navigation',...
1298 'Min',1,'Max',AVWVIEW.zdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.axi,...
1299 'Callback','avw_view_ras([],[],''axial_slider'');');
1300 end
1301 handles.axial_sliderN = uicontrol('Parent',GUI,'Style','text',...
1302 'Units','Normalized', Font, ...
1303 'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1304 'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1305 'BusyAction','queue',...
1306 'TooltipString','Axial slice number',...
1307 'String',num2str(AVWVIEW.slices.axi),'Value',AVWVIEW.slices.axi);
1308 handles.axial_sliderT = uicontrol('Parent',GUI,'Style','text',...
1309 'Units','Normalized', Font, ...
1310 'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1311 'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1312 'BusyAction','queue',...
1313 'TooltipString','Axial slice navigation',...
1314 'String','Axial');
1315
1316 handles.axial_xlim = get(handles.axial_axes,'Xlim');
1317 handles.axial_ylim = get(handles.axial_axes,'Ylim');
1318 handles.axial_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag], ...
1319 'Ydata',handles.axial_ylim, ...
1320 'ButtonDownFcn','avw_view_ras([],[],''axial_image'');');
1321 handles.axial_yline = line('Ydata',[AVWVIEW.slices.cor AVWVIEW.slices.cor], ...
1322 'Xdata',handles.axial_xlim, ...
1323 'ButtonDownFcn','avw_view_ras([],[],''axial_image'');');
1324 set(handles.axial_xline,'Color','y','Tag','XLINE', 'Visible', 'off');
1325 set(handles.axial_yline,'Color','y','Tag','YLINE', 'Visible', 'off');
1326
1327 end
1328
1329
1330
1331
1332 if AVWVIEW.xdim > 1 & AVWVIEW.zdim > 1,
1333
1334 handles.coronal_subplot = subplot('position',[0.075 0.575 xPlotSize yPlotSize]);
1335
1336 Scor = squeeze(avw.img(:,AVWVIEW.slices.cor,:));
1337 handles.coronal_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.zdim],Scor',AVWVIEW.clim);
1338 handles.coronal_axes = gca;
1339 set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1340 'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1341
1342
1343
1344 xlabel('Left ----- X ----- Right')
1345 ylabel('Z')
1346 title('Coronal','Color',[1 1 1])
1347
1348
1349 set(handles.coronal_image,'ButtonDownFcn','avw_view_ras([],[],''coronal_image'');');
1350
1351 GUIheight = GUIheight - 0.04;
1352
1353 if AVWVIEW.ydim > 1,
1354 slider_step(1) = 1/(AVWVIEW.ydim);
1355 slider_step(2) = 1/(AVWVIEW.ydim);
1356 handles.coronal_slider = uicontrol('Parent',GUI,'Style','slider',...
1357 'Units','Normalized', Font, ...
1358 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1359 'BusyAction','queue',...
1360 'TooltipString','Coronal slice navigation',...
1361 'Min',1,'Max',AVWVIEW.ydim,'SliderStep',slider_step,'Value',AVWVIEW.slices.cor,...
1362 'Callback','avw_view_ras([],[],''coronal_slider'');');
1363 end
1364 handles.coronal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1365 'Units','Normalized', Font, ...
1366 'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1367 'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1368 'BusyAction','queue',...
1369 'TooltipString','Coronal slice number',...
1370 'String',num2str(AVWVIEW.slices.cor),'Value',AVWVIEW.slices.cor);
1371 handles.coronal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1372 'Units','Normalized', Font, ...
1373 'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1374 'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1375 'BusyAction','queue',...
1376 'TooltipString','Coronal slice navigation',...
1377 'String','Coronal');
1378
1379 handles.coronal_xlim = get(handles.coronal_axes,'Xlim');
1380 handles.coronal_ylim = get(handles.coronal_axes,'Ylim');
1381 handles.coronal_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],...
1382 'Ydata',handles.coronal_ylim, ...
1383 'ButtonDownFcn','avw_view_ras([],[],''coronal_image'');');
1384 handles.coronal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi], ...
1385 'Xdata',handles.coronal_xlim, ...
1386 'ButtonDownFcn','avw_view_ras([],[],''coronal_image'');');
1387 set(handles.coronal_xline,'Color','y','Tag','XLINE', 'Visible', 'off');
1388 set(handles.coronal_yline,'Color','y','Tag','YLINE', 'Visible', 'off');
1389
1390 end
1391
1392
1393
1394
1395 if AVWVIEW.ydim > 1 & AVWVIEW.zdim > 1,
1396
1397 handles.sagittal_subplot = subplot('position',[0.575 0.575 xPlotSize yPlotSize]);
1398
1399 Ssag = squeeze(avw.img(AVWVIEW.slices.sag,:,:));
1400 handles.sagittal_image = imagesc([0,AVWVIEW.ydim],[0,AVWVIEW.zdim],Ssag',AVWVIEW.clim);
1401
1402 handles.sagittal_axes = gca;
1403 set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1404 'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1405
1406 xlabel('Y')
1407 ylabel('Z')
1408 title('Sagittal','Color',[1 1 1])
1409
1410
1411 set(handles.sagittal_image,'ButtonDownFcn','avw_view_ras([],[],''sagittal_image'');');
1412
1413 GUIheight = GUIheight - 0.04;
1414
1415 if AVWVIEW.xdim > 1,
1416 slider_step(1) = 1/(AVWVIEW.xdim);
1417 slider_step(2) = 1/(AVWVIEW.xdim);
1418 handles.sagittal_slider = uicontrol('Parent',GUI,'Style','slider',...
1419 'Units','Normalized', Font, ...
1420 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1421 'BusyAction','queue',...
1422 'TooltipString','Sagittal slice navigation',...
1423 'Min',1,'Max',AVWVIEW.xdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.sag,...
1424 'Callback','avw_view_ras([],[],''sagittal_slider'');');
1425 end
1426 handles.sagittal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1427 'Units','Normalized', Font, ...
1428 'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1429 'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1430 'BusyAction','queue',...
1431 'TooltipString','Sagittal slice number',...
1432 'String',num2str(AVWVIEW.slices.sag),'Value',AVWVIEW.slices.sag);
1433 handles.sagittal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1434 'Units','Normalized', Font, ...
1435 'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1436 'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1437 'BusyAction','queue',...
1438 'TooltipString','Sagittal slice navigation',...
1439 'String','Sagittal');
1440
1441 handles.sagittal_xlim = get(handles.sagittal_axes,'Xlim');
1442 handles.sagittal_ylim = get(handles.sagittal_axes,'Ylim');
1443 handles.sagittal_xline = line('Xdata',[AVWVIEW.slices.cor AVWVIEW.slices.cor], ...
1444 'Ydata',handles.sagittal_ylim, ...
1445 'ButtonDownFcn','avw_view_ras([],[],''sagittal_image'');');
1446 handles.sagittal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi], ...
1447 'Xdata',handles.sagittal_xlim, ...
1448 'ButtonDownFcn','avw_view_ras([],[],''sagittal_image'');');
1449 set(handles.sagittal_xline,'Color','y','Tag','XLINE', 'Visible', 'off');
1450 set(handles.sagittal_yline,'Color','y','Tag','YLINE', 'Visible', 'off');
1451
1452 end
1453
1454
1455
1456
1457
1458
1459
1460 menu=uicontextmenu;
1461
1462
1463 roi = uimenu(menu,'Label','ROI');
1464 uimenu(roi,'Label','ROI (9x9x9 block)','Callback','avw_view_ras([],[],''roi_9'');');
1465 uimenu(roi,'Label','ROI (7x7x7 block)','Callback','avw_view_ras([],[],''roi_7'');');
1466 uimenu(roi,'Label','ROI (5x5x5 block)','Callback','avw_view_ras([],[],''roi_5'');');
1467 uimenu(roi,'Label','ROI (3x3x3 block)','Callback','avw_view_ras([],[],''roi_3'');');
1468
1469
1470 uimenu(menu,'Label','Save Image','Callback','avw_view_ras([],[],''save_image'');');
1471
1472
1473 uimenu(menu,'Label','Zoom Image','Callback','avw_view_ras([],[],''zoom'');');
1474
1475 if isfield(handles,'axial_image'),
1476 if isempty(get(handles.axial_image,'uicontextmenu')),
1477 set(handles.axial_image,'uicontextmenu',menu);
1478 end
1479 end
1480 if isfield(handles,'coronal_image'),
1481 if isempty(get(handles.coronal_image,'uicontextmenu')),
1482 set(handles.coronal_image,'uicontextmenu',menu);
1483 end
1484 end
1485 if isfield(handles,'sagittal_image'),
1486 if isempty(get(handles.sagittal_image,'uicontextmenu')),
1487 set(handles.sagittal_image,'uicontextmenu',menu);
1488 end
1489 end
1490
1491
1492
1493
1494
1495
1496
1497 GUIheight = GUIheight - 0.04;
1498
1499 handles.Timval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1500 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1501 'BackgroundColor', [0 0 0],...
1502 'ForegroundColor', [1 1 1],...
1503 'BusyAction','queue',...
1504 'String','Image Intensity');
1505 handles.imval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1506 'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1507 'BackgroundColor', [0 0 0],...
1508 'ForegroundColor', [1 1 1],...
1509 'BusyAction','queue',...
1510 'String','x','Value',0);
1511
1512
1513
1514 GUIheight = GUIheight - 0.04;
1515
1516 handles.Timpos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1517 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1518 'BackgroundColor', [0 0 0],...
1519 'ForegroundColor', [1 1 1],...
1520 'BusyAction','queue',...
1521 'String','Image Position');
1522 handles.impos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1523 'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1524 'BackgroundColor', [0 0 0],...
1525 'ForegroundColor', [1 1 1],...
1526 'BusyAction','queue',...
1527 'String','xyz','Value',[0 0 0]);
1528
1529
1530
1531
1532
1533 GUIheight = GUIheight - 0.04;
1534
1535
1536
1537
1538
1539
1540
1541
1542 handles.flipStatus = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1543 'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1544 'BackgroundColor', [0 0 0],...
1545 'ForegroundColor', [1 1 1],...
1546 'BusyAction','queue',...
1547 'TooltipString','Flipped Status',...
1548 'String','L>>R (neurological)');
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576 GUIheight = GUIheight - 0.04;
1577
1578 handles.Tnasion = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1579 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1580 'BackgroundColor', [.3 .3 .3],...
1581 'ForegroundColor', [0 0 0],...
1582 'BusyAction','queue',...
1583 'TooltipString','Update Nasion - should be toward +Y',...
1584 'String','Fiducial: Nasion',...
1585 'Callback','avw_view_ras([],[],''nasion'');');
1586 handles.nasion = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1587 'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1588 'BackgroundColor', [0 0 0],...
1589 'ForegroundColor', [1 1 1],...
1590 'BusyAction','queue',...
1591 'TooltipString','These values are offset from volume center, should be toward +Y',...
1592 'String','x,y,z');
1593
1594
1595
1596 GUIheight = GUIheight - 0.04;
1597
1598 handles.Trpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1599 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1600 'BackgroundColor', [.3 .3 .3],...
1601 'ForegroundColor', [0 0 0],...
1602 'BusyAction','queue',...
1603 'TooltipString','Update Right Preauricular - should be toward +X',...
1604 'String','Fiducial: RPA',...
1605 'Callback','avw_view_ras([],[],''rpa'');');
1606 handles.rpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1607 'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1608 'BackgroundColor', [0 0 0],...
1609 'ForegroundColor', [1 1 1],...
1610 'BusyAction','queue',...
1611 'TooltipString','These values are offset from volume center, should be toward +X',...
1612 'String','x,y,z');
1613
1614
1615
1616 GUIheight = GUIheight - 0.04;
1617
1618 handles.Tlpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1619 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1620 'BackgroundColor', [.3 .3 .3],...
1621 'ForegroundColor', [0 0 0],...
1622 'BusyAction','queue',...
1623 'TooltipString','Update Left Preauricular - should be toward -X',...
1624 'String','Fiducial: LPA',...
1625 'Callback','avw_view_ras([],[],''lpa'');');
1626 handles.lpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1627 'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1628 'BackgroundColor', [0 0 0],...
1629 'ForegroundColor', [1 1 1],...
1630 'BusyAction','queue',...
1631 'TooltipString','These values are offset from volume center, should be toward -X',...
1632 'String','x,y,z');
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651 GUIheight = GUIheight - 0.04;
1652
1653 handles.dimmer = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1654 'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1655 'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1656 'BusyAction','queue',...
1657 'TooltipString','Dim by 1%',...
1658 'String','Dimmer',...
1659 'Callback','avw_view_ras([],[],''dimmer'');');
1660
1661 handles.brighter = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1662 'Position',[.65 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1663 'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1664 'BusyAction','queue',...
1665 'TooltipString','Brighten by 1%',...
1666 'String','Brighter',...
1667 'Callback','avw_view_ras([],[],''brighter'');');
1668
1669 handles.clim = uicontrol('Parent',GUI,'Style','edit','Units','Normalized', Font, ...
1670 'Position',[.75 GUIheight .06 .03], 'HorizontalAlignment', 'right',...
1671 'BackgroundColor', [0 0 0],...
1672 'ForegroundColor', [1 1 1],...
1673 'BusyAction','queue',...
1674 'TooltipString','Image intensity Climit (inverse brightness)',...
1675 'String',num2str(AVWVIEW.clim(2)),...
1676 'Callback','avw_view_ras([],[],''setClimit'');');
1677
1678 handles.cmap = uicontrol('Parent',GUI,'Style','popup','Units','Normalized', Font, ...
1679 'Position',[.82 GUIheight .06 .03], 'HorizontalAlignment', 'left',...
1680 'BackgroundColor', [0 0 0],...
1681 'ForegroundColor', [1 1 1],...
1682 'BusyAction','queue',...
1683 'TooltipString','Color Map',...
1684 'String',{'gray','bone','copper','hot','cool','spring','summer','autumn','winter','hsv','jet'},...
1685 'Callback','avw_view_ras([],[],''setCmap'');');
1686
1687
1688
1689
1690 GUIheight = 0.46;
1691
1692 handles.crosshairs = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
1693 'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1694 'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1695 'BusyAction','queue',...
1696 'TooltipString','Toggle Crosshairs on/off',...
1697 'String','Crosshairs','Value',1,...
1698 'Callback','avw_view_ras([],[],''crosshairs'');');
1699
1700
1701
1702
1703 GUIheight = GUIheight - 0.04;
1704
1705 handles.histogram = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1706 'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1707 'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1708 'BusyAction','queue',...
1709 'TooltipString','Histogram of Volume Intensity',...
1710 'String','Histogram',...
1711 'Callback','avw_view_ras([],[],''histogram'');');
1712
1713
1714
1715
1716
1717 GUIheight = GUIheight - 0.04;
1718
1719 handles.coord = uicontrol('Parent',GUI,'Style','popupmenu','Units','Normalized', Font, ...
1720 'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1721 'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1722 'BusyAction','queue',...
1723 'TooltipString','Voxel or Mensurated Axis Coordinates',...
1724 'String',{'Voxels','mm','meters'},...
1725 'Callback','avw_view_ras([],[],''coordinates'');');
1726
1727
1728
1729
1730 Font.FontWeight = 'bold';
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744 handles.Bquit = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1745 'Position',[.70 .01 .15 .05],...
1746 'String','Save fiducials','BusyAction','queue',...
1747 'BackgroundColor',[0.0 0.5 0.0],...
1748 'ForegroundColor', [0 0 0], 'HorizontalAlignment', 'center',...
1749 'Callback','avw_view_ras([],[],''save'');');
1750
1751
1752 handles.Bclose = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1753 'Position',[.88 .01 .10 .05],...
1754 'String','Close','BusyAction','queue',...
1755 'BackgroundColor',[0.0 0.5 0.0],...
1756 'ForegroundColor', [0 0 0], 'HorizontalAlignment', 'center',...
1757 'Callback','avw_view_ras([],[],''close'');');
1758
1759
1760 if exist('parent','var'), AVWVIEW.parent.gui = parent; end
1761 AVWVIEW.avw = avw;
1762 AVWVIEW.handles = handles;
1763 set(AVWVIEW.gui,'Userdata',AVWVIEW);
1764 set(AVWVIEW.gui,'HandleVisibility','callback');
1765
1766 return
1767
1768
1769
1770 function slice_img(avw),
1771
1772 figure
1773 xslice = 128;
1774 slice = squeeze( avw.img(xslice,:,:) );
1775 imagesc(slice); axis image; colormap('gray')
1776 figure
1777 yslice = 128;
1778 slice = squeeze( avw.img(:,yslice,:) );
1779 imagesc(slice); axis image; colormap('gray')
1780 figure
1781 zslice = 128;
1782 slice = squeeze( avw.img(:,:,zslice) );
1783 imagesc(slice); axis image; colormap('gray')
1784
1785 return