GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — MATLAB/view_nii.m at master · mdqyy/MATLAB Expand file tree/ Copy pathview_nii.mMore file actions executable file ·4901 lines (3819 loc) · 143 KB / Copy pathview_nii.mFile metadata and controlsexecutable file ·4901 lines (3819 loc) · 143 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 % VIEW_NII: Create or update a 3-View (Front, Top, Side) of the % brain data that is specified by nii structure % % Usage: status = view_nii([h], nii, [option]) or % status = view_nii(h, [option]) % % Where, h is the figure on which the 3-View will be plotted; % nii is the brain data in NIFTI format; % option is a struct that configures the view plotted, can be: % % option.command = 'init' % option.command = 'update' % option.command = 'clearnii' % option.command = 'updatenii' % option.command = 'updateimg' (nii is nii.img here) % % option.usecolorbar = 0 | [1] % option.usepanel = 0 | [1] % option.usecrosshair = 0 | [1] % option.usestretch = 0 | [1] % option.useimagesc = 0 | [1] % option.useinterp = [0] | 1 % % option.setarea = [x y w h] | [0.05 0.05 0.9 0.9] % option.setunit = ['vox'] | 'mm' % option.setviewpoint = [x y z] | [origin] % option.setscanid = [t] | [1] % option.setcrosshaircolor = [r g b] | [1 0 0] % option.setcolorindex = From 1 to 9 (default is 2 or 3) % option.setcolormap = (Mx3 matrix, 0 <= val <= 1) % option.setcolorlevel = No more than 256 (default 256) % option.sethighcolor = [] % option.setcbarminmax = [] % option.setvalue = [] % option.glblocminmax = [] % option.setbuttondown = '' % option.setcomplex = [0] | 1 | 2 % % Options description in detail: % ============================== % % 1. command: A char string that can control program. % % init: If option.command='init', the program will display % a 3-View plot on the figure specified by figure h % or on a new figure. If there is already a 3-View % plot on the figure, please use option.command = % 'updatenii' (see detail below); otherwise, the % new 3-View plot will superimpose on the old one. % If there is no option provided, the program will % assume that this is an initial plot. If the figure % handle is omitted, the program knows that it is % an initial plot. % % update: If there is no command specified, and a figure % handle of the existing 3-View plot is provided, % the program will choose option.command='update' % to update the 3-View plot with some new option % items. % % clearnii: Clear 3-View plot on specific figure % % updatenii: If a new nii is going to be loaded on a fig % that has already 3-View plot on it, use this % command to clear existing 3-View plot, and then % display with new nii. So, the new nii will not % superimpose on the existing one. All options % for 'init' can be used for 'updatenii'. % % updateimg: If a new 3D matrix with the same dimension % is going to be loaded, option.command='updateimg' % can be used as a light-weighted 'updatenii, since % it only updates the 3 slices with new values. % inputing argument nii should be a 3D matrix % (nii.img) instead of nii struct. No other option % should be used together with 'updateimg' to keep % this command as simple as possible. % % % 2. usecolorbar: If specified and usecolorbar=0, the program % will not include the colorbar in plot area; otherwise, % a colorbar will be included in plot area. % % 3. usepanel: If specified and usepanel=0, the control panel % at lower right cornor will be invisible; otherwise, % it will be visible. % % 4. usecrosshair: If specified and usecrosshair=0, the crosshair % will be invisible; otherwise, it will be visible. % % 5. usestretch: If specified and usestretch=0, the 3 slices will % not be stretched, and will be displayed according to % the actual voxel size; otherwise, the 3 slices will be % stretched to the edge. % % 6. useimagesc: If specified and useimagesc=0, images data will % be used directly to match the colormap (like 'image' % command); otherwise, image data will be scaled to full % colormap with 'imagesc' command in Matlab. % % 7. useinterp: If specified and useinterp=1, the image will be % displayed using interpolation. Otherwise, it will be % displayed like mosaic, and each tile stands for a % pixel. This option does not apply to 'setvalue' option % is set. % % % 8. setarea: 3-View plot will be displayed on this specific % region. If it is not specified, program will set the % plot area to [0.05 0.05 0.9 0.9]. % % 9. setunit: It can be specified to setunit='voxel' or 'mm' % and the view will change the axes unit of [X Y Z] % accordingly. % % 10. setviewpoint: If specified, [X Y Z] values will be used % to set the viewpoint of 3-View plot. % % 11. setscanid: If specified, [t] value will be used to display % the specified image scan in NIFTI data. % % 12. setcrosshaircolor: If specified, [r g b] value will be used % for Crosshair Color. Otherwise, red will be the default. % % 13. setcolorindex: If specified, the 3-View will choose the % following colormap: 2 - Bipolar; 3 - Gray; 4 - Jet; % 5 - Cool; 6 - Bone; 7 - Hot; 8 - Copper; 9 - Pink; % If not specified, it will choose 3 - Gray if all data % values are not less than 0; otherwise, it will choose % 2 - Bipolar if there is value less than 0. (Contrast % control can only apply to 3 - Gray colormap. % % 14. setcolormap: 3-View plot will use it as a customized colormap. % It is a 3-column matrix with value between 0 and 1. If % using MS-Windows version of Matlab, the number of rows % can not be more than 256, because of Matlab limitation. % When colormap is used, setcolorlevel option will be % disabled automatically. % % 15. setcolorlevel: If specified (must be no more than 256, and % cannot be used for customized colormap), row number of % colormap will be squeezed down to this level; otherwise, % it will assume that setcolorlevel=256. % % 16. sethighcolor: If specified, program will squeeze down the % colormap, and allocate sethighcolor (an Mx3 matrix) % to high-end portion of the colormap. The sum of M and % setcolorlevel should be less than 256. If setcolormap % option is used, sethighcolor will be inserted on top % of the setcolormap, and the setcolorlevel option will % be disabled automatically. % % 17. setcbarminmax: if specified, the [min max] will be used to % set the min and max of the colorbar, which does not % include any data for highcolor. % % 18. setvalue: If specified, setvalue.val (with the same size as % the source data on solution points) in the source area % setvalue.idx will be superimposed on the current nii % image. So, the size of setvalue.val should be equal to % the size of setvalue.idx. To use this feature, it needs % single or double nii structure for background image. % % 19. glblocminmax: If specified, pgm will use glblocminmax to % calculate the colormap, instead of minmax of image. % % 20. setbuttondown: If specified, pgm will evaluate the command % after a click or slide action is invoked to the new % view point. % % 21. setcomplex: This option will decide how complex data to be % displayed: 0 - Real part of complex data; 1 - Imaginary % part of complex data; 2 - Modulus (magnitude) of complex % data; If not specified, it will be set to 0 (Real part % of complex data as default option. This option only apply % when option.command is set to 'init or 'updatenii'. % % % Additional Options for 'update' command: % ======================================= % % option.enablecursormove = [1] | 0 % option.enableviewpoint = 0 | [1] % option.enableorigin = 0 | [1] % option.enableunit = 0 | [1] % option.enablecrosshair = 0 | [1] % option.enablehistogram = 0 | [1] % option.enablecolormap = 0 | [1] % option.enablecontrast = 0 | [1] % option.enablebrightness = 0 | [1] % option.enableslider = 0 | [1] % option.enabledirlabel = 0 | [1] % % % e.g.: % nii = load_nii('T1'); % T1.img/hdr % view_nii(nii); % % or % % h = figure('unit','normal','pos', [0.18 0.08 0.64 0.85]); % opt.setarea = [0.05 0.05 0.9 0.9]; % view_nii(h, nii, opt); % % % Part of this file is copied and modified from: % http://www.mathworks.com/matlabcentral/fileexchange/1878-mri-analyze-tools % % NIFTI data format can be found on: http://nifti.nimh.nih.gov % % - Jimmy Shen ([email protected]) % function status = view_nii(varargin) if nargin < 1 error('Please check inputs using ''help view_nii'''); end; nii = ''; opt = ''; command = ''; usecolorbar = []; usepanel = []; usecrosshair = ''; usestretch = []; useimagesc = []; useinterp = []; setarea = []; setunit = ''; setviewpoint = []; setscanid = []; setcrosshaircolor = []; setcolorindex = ''; setcolormap = 'NA'; setcolorlevel = []; sethighcolor = 'NA'; setcbarminmax = []; setvalue = []; glblocminmax = []; setbuttondown = ''; setcomplex = 0; status = []; if ishandle(varargin{1}) % plot on top of this figure fig = varargin{1}; if nargin < 2 command = 'update'; % just to get 3-View status end if nargin == 2 if ~isstruct(varargin{2}) error('2nd parameter should be either nii struct or option struct'); end opt = varargin{2}; if isfield(opt,'hdr') & isfield(opt,'img') nii = opt; elseif isfield(opt, 'command') & (strcmpi(opt.command,'init') ... | strcmpi(opt.command,'updatenii') ... | strcmpi(opt.command,'updateimg') ) error('Option here cannot contain "init", "updatenii", or "updateimg" comand'); end end if nargin == 3 nii = varargin{2}; opt = varargin{3}; if ~isstruct(opt) error('3rd parameter should be option struct'); end if ~isfield(opt,'command') | ~strcmpi(opt.command,'updateimg') if ~isstruct(nii) | ~isfield(nii,'hdr') | ~isfield(nii,'img') error('2nd parameter should be nii struct'); end if isfield(nii,'untouch') & nii.untouch == 1 error('Usage: please use ''load_nii.m'' to load the structure.'); end end end set(fig, 'menubar', 'none'); elseif ischar(varargin{1}) % call back by event command = lower(varargin{1}); fig = gcbf; else % start nii with a new figure nii = varargin{1}; if ~isstruct(nii) | ~isfield(nii,'hdr') | ~isfield(nii,'img') error('1st parameter should be either a figure handle or nii struct'); end if isfield(nii,'untouch') & nii.untouch == 1 error('Usage: please use ''load_nii.m'' to load the structure.'); end if nargin > 1 opt = varargin{2}; if isfield(opt, 'command') & ~strcmpi(opt.command,'init') error('Option here must use "init" comand'); end end command = 'init'; fig = figure('unit','normal','position',[0.15 0.08 0.70 0.85]); view_nii_menu(fig); rri_file_menu(fig); end if ~isempty(opt) if isfield(opt,'command') command = lower(opt.command); end if isempty(command) command = 'update'; end if isfield(opt,'usecolorbar') usecolorbar = opt.usecolorbar; end if isfield(opt,'usepanel') usepanel = opt.usepanel; end if isfield(opt,'usecrosshair') usecrosshair = opt.usecrosshair; end if isfield(opt,'usestretch') usestretch = opt.usestretch; end if isfield(opt,'useimagesc') useimagesc = opt.useimagesc; end if isfield(opt,'useinterp') useinterp = opt.useinterp; end if isfield(opt,'setarea') setarea = opt.setarea; end if isfield(opt,'setunit') setunit = opt.setunit; end if isfield(opt,'setviewpoint') setviewpoint = opt.setviewpoint; end if isfield(opt,'setscanid') setscanid = opt.setscanid; end if isfield(opt,'setcrosshaircolor') setcrosshaircolor = opt.setcrosshaircolor; if ~isempty(setcrosshaircolor) & (~isnumeric(setcrosshaircolor) | ~isequal(size(setcrosshaircolor),[1 3]) | min(setcrosshaircolor(:))<0 | max(setcrosshaircolor(:))>1) error('Crosshair Color should be a 1x3 matrix with value between 0 and 1'); end end if isfield(opt,'setcolorindex') setcolorindex = round(opt.setcolorindex); if ~isnumeric(setcolorindex) | setcolorindex < 1 | setcolorindex > 9 error('Colorindex should be a number between 1 and 9'); end end if isfield(opt,'setcolormap') setcolormap = opt.setcolormap; if ~isempty(setcolormap) & (~isnumeric(setcolormap) | size(setcolormap,2) ~= 3 | min(setcolormap(:))<0 | max(setcolormap(:))>1) error('Colormap should be a Mx3 matrix with value between 0 and 1'); end end if isfield(opt,'setcolorlevel') setcolorlevel = round(opt.setcolorlevel); if ~isnumeric(setcolorlevel) | setcolorlevel > 256 | setcolorlevel < 1 error('Colorlevel should be a number between 1 and 256'); end end if isfield(opt,'sethighcolor') sethighcolor = opt.sethighcolor; if ~isempty(sethighcolor) & (~isnumeric(sethighcolor) | size(sethighcolor,2) ~= 3 | min(sethighcolor(:))<0 | max(sethighcolor(:))>1) error('Highcolor should be a Mx3 matrix with value between 0 and 1'); end end if isfield(opt,'setcbarminmax') setcbarminmax = opt.setcbarminmax; if isempty(setcbarminmax) | ~isnumeric(setcbarminmax) | length(setcbarminmax) ~= 2 error('Colorbar MinMax should contain 2 values: [min max]'); end end if isfield(opt,'setvalue') setvalue = opt.setvalue; if isempty(setvalue) | ~isstruct(setvalue) | ... ~isfield(opt.setvalue,'idx') | ~isfield(opt.setvalue,'val') error('setvalue should be a struct contains idx and val'); end if length(opt.setvalue.idx(:)) ~= length(opt.setvalue.val(:)) error('length of idx and val fields should be the same'); end if ~strcmpi(class(opt.setvalue.idx),'single') opt.setvalue.idx = single(opt.setvalue.idx); end if ~strcmpi(class(opt.setvalue.val),'single') opt.setvalue.val = single(opt.setvalue.val); end end if isfield(opt,'glblocminmax') glblocminmax = opt.glblocminmax; end if isfield(opt,'setbuttondown') setbuttondown = opt.setbuttondown; end if isfield(opt,'setcomplex') setcomplex = opt.setcomplex; end end switch command case {'init'} set(fig, 'InvertHardcopy','off'); set(fig, 'PaperPositionMode','auto'); fig = init(nii, fig, setarea, setunit, setviewpoint, setscanid, setbuttondown, ... setcolorindex, setcolormap, setcolorlevel, sethighcolor, setcbarminmax, ... usecolorbar, usepanel, usecrosshair, usestretch, useimagesc, useinterp, ... setvalue, glblocminmax, setcrosshaircolor, setcomplex); % get status % status = get_status(fig); case {'update'} nii_view = getappdata(fig,'nii_view'); h = fig; if isempty(nii_view) error('The figure should already contain a 3-View plot.'); end if ~isempty(opt) % Order of the following update matters. % update_shape(h, setarea, usecolorbar, usestretch, useimagesc); update_useinterp(h, useinterp); update_useimagesc(h, useimagesc); update_usepanel(h, usepanel); update_colorindex(h, setcolorindex); update_colormap(h, setcolormap); update_highcolor(h, sethighcolor, setcolorlevel); update_cbarminmax(h, setcbarminmax); update_unit(h, setunit); update_viewpoint(h, setviewpoint); update_scanid(h, setscanid); update_buttondown(h, setbuttondown); update_crosshaircolor(h, setcrosshaircolor); update_usecrosshair(h, usecrosshair); % Enable/Disable object % update_enable(h, opt); end % get status % status = get_status(h); case {'updateimg'} if ~exist('nii','var') msg = sprintf('Please input a 3D matrix brain data'); error(msg); end % Note: nii is not nii, nii should be a 3D matrix here % if ~isnumeric(nii) msg = sprintf('2nd parameter should be a 3D matrix, not nii struct'); error(msg); end nii_view = getappdata(fig,'nii_view'); if isempty(nii_view) error('The figure should already contain a 3-View plot.'); end img = nii; update_img(img, fig, opt); % get status % status = get_status(fig); case {'updatenii'} nii_view = getappdata(fig,'nii_view'); if isempty(nii_view) error('The figure should already contain a 3-View plot.'); end if ~isstruct(nii) | ~isfield(nii,'hdr') | ~isfield(nii,'img') error('2nd parameter should be nii struct'); end if isfield(nii,'untouch') & nii.untouch == 1 error('Usage: please use ''load_nii.m'' to load the structure.'); end opt.command = 'clearnii'; view_nii(fig, opt); opt.command = 'init'; view_nii(fig, nii, opt); % get status % status = get_status(fig); case {'clearnii'} nii_view = getappdata(fig,'nii_view'); handles = struct2cell(nii_view.handles); for i=1:length(handles) if ishandle(handles{i}) % in case already del by parent delete(handles{i}); end end rmappdata(fig,'nii_view'); buttonmotion = get(fig,'windowbuttonmotion'); mymotion = '; view_nii(''move_cursor'');'; buttonmotion = strrep(buttonmotion, mymotion, ''); set(fig, 'windowbuttonmotion', buttonmotion); case {'axial_image','coronal_image','sagittal_image'} switch command case 'axial_image', view = 'axi'; axi = 0; cor = 1; sag = 1; case 'coronal_image', view = 'cor'; axi = 1; cor = 0; sag = 1; case 'sagittal_image', view = 'sag'; axi = 1; cor = 1; sag = 0; end nii_view = getappdata(fig,'nii_view'); nii_view = get_slice_position(nii_view,view); if isfield(nii_view, 'disp') img = nii_view.disp; else img = nii_view.nii.img; end % CData must be double() for Matlab 6.5 for Windows % if axi, if isfield(nii_view.handles,'axial_bg') & ~isempty(nii_view.handles.axial_bg) & nii_view.useinterp Saxi = squeeze(nii_view.bgimg(:,:,nii_view.slices.axi)); if ~strcmp(class(Saxi),'uint8'), Saxi = double(Saxi); end; set(nii_view.handles.axial_bg,'CData',Saxi'); end if isfield(nii_view.handles,'axial_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Saxi = squeeze(img(:,:,nii_view.slices.axi,:,nii_view.scanid)); Saxi = permute(Saxi, [2 1 3]); else Saxi = squeeze(img(:,:,nii_view.slices.axi,nii_view.scanid)); Saxi = Saxi'; end if ~strcmp(class(Saxi),'uint8'), Saxi = double(Saxi); end; set(nii_view.handles.axial_image,'CData',Saxi); end if isfield(nii_view.handles,'axial_slider'), set(nii_view.handles.axial_slider,'Value',nii_view.slices.axi); end; end if cor, if isfield(nii_view.handles,'coronal_bg') & ~isempty(nii_view.handles.coronal_bg) & nii_view.useinterp Scor = squeeze(nii_view.bgimg(:,nii_view.slices.cor,:)); if ~strcmp(class(Scor),'uint8'), Scor = double(Scor); end; set(nii_view.handles.coronal_bg,'CData',Scor'); end if isfield(nii_view.handles,'coronal_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Scor = squeeze(img(:,nii_view.slices.cor,:,:,nii_view.scanid)); Scor = permute(Scor, [2 1 3]); else Scor = squeeze(img(:,nii_view.slices.cor,:,nii_view.scanid)); Scor = Scor'; end if ~strcmp(class(Scor),'uint8'), Scor = double(Scor); end; set(nii_view.handles.coronal_image,'CData',Scor); end if isfield(nii_view.handles,'coronal_slider'), slider_val = nii_view.dims(2) - nii_view.slices.cor + 1; set(nii_view.handles.coronal_slider,'Value',slider_val); end; end; if sag, if isfield(nii_view.handles,'sagittal_bg') & ~isempty(nii_view.handles.sagittal_bg) & nii_view.useinterp Ssag = squeeze(nii_view.bgimg(nii_view.slices.sag,:,:)); if ~strcmp(class(Ssag),'uint8'), Ssag = double(Ssag); end; set(nii_view.handles.sagittal_bg,'CData',Ssag'); end if isfield(nii_view.handles,'sagittal_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Ssag = squeeze(img(nii_view.slices.sag,:,:,:,nii_view.scanid)); Ssag = permute(Ssag, [2 1 3]); else Ssag = squeeze(img(nii_view.slices.sag,:,:,nii_view.scanid)); Ssag = Ssag'; end if ~strcmp(class(Ssag),'uint8'), Ssag = double(Ssag); end; set(nii_view.handles.sagittal_image,'CData',Ssag); end if isfield(nii_view.handles,'sagittal_slider'), set(nii_view.handles.sagittal_slider,'Value',nii_view.slices.sag); end; end; update_nii_view(nii_view); if ~isempty(nii_view.buttondown) eval(nii_view.buttondown); end case {'axial_slider','coronal_slider','sagittal_slider'}, switch command case 'axial_slider', view = 'axi'; axi = 1; cor = 0; sag = 0; case 'coronal_slider', view = 'cor'; axi = 0; cor = 1; sag = 0; case 'sagittal_slider', view = 'sag'; axi = 0; cor = 0; sag = 1; end nii_view = getappdata(fig,'nii_view'); nii_view = get_slider_position(nii_view); if isfield(nii_view, 'disp') img = nii_view.disp; else img = nii_view.nii.img; end if axi, if isfield(nii_view.handles,'axial_bg') & ~isempty(nii_view.handles.axial_bg) & nii_view.useinterp Saxi = squeeze(nii_view.bgimg(:,:,nii_view.slices.axi)); if ~strcmp(class(Saxi),'uint8'), Saxi = double(Saxi); end; set(nii_view.handles.axial_bg,'CData',Saxi'); end if isfield(nii_view.handles,'axial_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Saxi = squeeze(img(:,:,nii_view.slices.axi,:,nii_view.scanid)); Saxi = permute(Saxi, [2 1 3]); else Saxi = squeeze(img(:,:,nii_view.slices.axi,nii_view.scanid)); Saxi = Saxi'; end if ~strcmp(class(Saxi),'uint8'), Saxi = double(Saxi); end; set(nii_view.handles.axial_image,'CData',Saxi); end if isfield(nii_view.handles,'axial_slider'), set(nii_view.handles.axial_slider,'Value',nii_view.slices.axi); end end if cor, if isfield(nii_view.handles,'coronal_bg') & ~isempty(nii_view.handles.coronal_bg) & nii_view.useinterp Scor = squeeze(nii_view.bgimg(:,nii_view.slices.cor,:)); if ~strcmp(class(Scor),'uint8'), Scor = double(Scor); end; set(nii_view.handles.coronal_bg,'CData',Scor'); end if isfield(nii_view.handles,'coronal_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Scor = squeeze(img(:,nii_view.slices.cor,:,:,nii_view.scanid)); Scor = permute(Scor, [2 1 3]); else Scor = squeeze(img(:,nii_view.slices.cor,:,nii_view.scanid)); Scor = Scor'; end if ~strcmp(class(Scor),'uint8'), Scor = double(Scor); end; set(nii_view.handles.coronal_image,'CData',Scor); end if isfield(nii_view.handles,'coronal_slider'), slider_val = nii_view.dims(2) - nii_view.slices.cor + 1; set(nii_view.handles.coronal_slider,'Value',slider_val); end end if sag, if isfield(nii_view.handles,'sagittal_bg') & ~isempty(nii_view.handles.sagittal_bg) & nii_view.useinterp Ssag = squeeze(nii_view.bgimg(nii_view.slices.sag,:,:)); if ~strcmp(class(Ssag),'uint8'), Ssag = double(Ssag); end; set(nii_view.handles.sagittal_bg,'CData',Ssag'); end if isfield(nii_view.handles,'sagittal_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Ssag = squeeze(img(nii_view.slices.sag,:,:,:,nii_view.scanid)); Ssag = permute(Ssag, [2 1 3]); else Ssag = squeeze(img(nii_view.slices.sag,:,:,nii_view.scanid)); Ssag = Ssag'; end if ~strcmp(class(Ssag),'uint8'), Ssag = double(Ssag); end; set(nii_view.handles.sagittal_image,'CData',Ssag); end if isfield(nii_view.handles,'sagittal_slider'), set(nii_view.handles.sagittal_slider,'Value',nii_view.slices.sag); end end update_nii_view(nii_view); if ~isempty(nii_view.buttondown) eval(nii_view.buttondown); end case {'impos_edit'} nii_view = getappdata(fig,'nii_view'); impos = str2num(get(nii_view.handles.impos,'string')); if isfield(nii_view, 'disp') img = nii_view.disp; else img = nii_view.nii.img; end if isempty(impos) | ~all(size(impos) == [1 3]) msg = 'Please use 3 numbers to represent X,Y and Z'; msgbox(msg,'Error'); return; end slices.sag = round(impos(1)); slices.cor = round(impos(2)); slices.axi = round(impos(3)); nii_view = convert2voxel(nii_view,slices); nii_view = check_slices(nii_view); impos(1) = nii_view.slices.sag; impos(2) = nii_view.dims(2) - nii_view.slices.cor + 1; impos(3) = nii_view.slices.axi; if isfield(nii_view.handles,'sagittal_slider'), set(nii_view.handles.sagittal_slider,'Value',impos(1)); end if isfield(nii_view.handles,'coronal_slider'), set(nii_view.handles.coronal_slider,'Value',impos(2)); end if isfield(nii_view.handles,'axial_slider'), set(nii_view.handles.axial_slider,'Value',impos(3)); end nii_view = get_slider_position(nii_view); update_nii_view(nii_view); if isfield(nii_view.handles,'axial_bg') & ~isempty(nii_view.handles.axial_bg) & nii_view.useinterp Saxi = squeeze(nii_view.bgimg(:,:,nii_view.slices.axi)); if ~strcmp(class(Saxi),'uint8'), Saxi = double(Saxi); end; set(nii_view.handles.axial_bg,'CData',Saxi'); end if isfield(nii_view.handles,'axial_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Saxi = squeeze(img(:,:,nii_view.slices.axi,:,nii_view.scanid)); Saxi = permute(Saxi, [2 1 3]); else Saxi = squeeze(img(:,:,nii_view.slices.axi,nii_view.scanid)); Saxi = Saxi'; end if ~strcmp(class(Saxi),'uint8'), Saxi = double(Saxi); end; set(nii_view.handles.axial_image,'CData',Saxi); end if isfield(nii_view.handles,'axial_slider'), set(nii_view.handles.axial_slider,'Value',nii_view.slices.axi); end if isfield(nii_view.handles,'coronal_bg') & ~isempty(nii_view.handles.coronal_bg) & nii_view.useinterp Scor = squeeze(nii_view.bgimg(:,nii_view.slices.cor,:)); if ~strcmp(class(Scor),'uint8'), Scor = double(Scor); end; set(nii_view.handles.coronal_bg,'CData',Scor'); end if isfield(nii_view.handles,'coronal_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Scor = squeeze(img(:,nii_view.slices.cor,:,:,nii_view.scanid)); Scor = permute(Scor, [2 1 3]); else Scor = squeeze(img(:,nii_view.slices.cor,:,nii_view.scanid)); Scor = Scor'; end if ~strcmp(class(Scor),'uint8'), Scor = double(Scor); end; set(nii_view.handles.coronal_image,'CData',Scor); end if isfield(nii_view.handles,'coronal_slider'), slider_val = nii_view.dims(2) - nii_view.slices.cor + 1; set(nii_view.handles.coronal_slider,'Value',slider_val); end if isfield(nii_view.handles,'sagittal_bg') & ~isempty(nii_view.handles.sagittal_bg) & nii_view.useinterp Ssag = squeeze(nii_view.bgimg(nii_view.slices.sag,:,:)); if ~strcmp(class(Ssag),'uint8'), Ssag = double(Ssag); end; set(nii_view.handles.sagittal_bg,'CData',Ssag'); end if isfield(nii_view.handles,'sagittal_image'), if nii_view.nii.hdr.dime.datatype == 128 | nii_view.nii.hdr.dime.datatype == 511 Ssag = squeeze(img(nii_view.slices.sag,:,:,:,nii_view.scanid)); Ssag = permute(Ssag, [2 1 3]); else Ssag = squeeze(img(nii_view.slices.sag,:,:,nii_view.scanid)); Ssag = Ssag'; end if ~strcmp(class(Ssag),'uint8'), Ssag = double(Ssag); end; set(nii_view.handles.sagittal_image,'CData',Ssag); end if isfield(nii_view.handles,'sagittal_slider'), set(nii_view.handles.sagittal_slider,'Value',nii_view.slices.sag); end axes(nii_view.handles.axial_axes); axes(nii_view.handles.coronal_axes); axes(nii_view.handles.sagittal_axes); if ~isempty(nii_view.buttondown) eval(nii_view.buttondown); end case 'coordinates', nii_view = getappdata(fig,'nii_view'); set_image_value(nii_view); case 'crosshair', nii_view = getappdata(fig,'nii_view'); if get(nii_view.handles.xhair,'value') == 2 % off set(nii_view.axi_xhair.lx,'visible','off'); set(nii_view.axi_xhair.ly,'visible','off'); set(nii_view.cor_xhair.lx,'visible','off'); set(nii_view.cor_xhair.ly,'visible','off'); set(nii_view.sag_xhair.lx,'visible','off'); set(nii_view.sag_xhair.ly,'visible','off'); else set(nii_view.axi_xhair.lx,'visible','on'); set(nii_view.axi_xhair.ly,'visible','on'); set(nii_view.cor_xhair.lx,'visible','on'); set(nii_view.cor_xhair.ly,'visible','on'); set(nii_view.sag_xhair.lx,'visible','on'); set(nii_view.sag_xhair.ly,'visible','on'); set(nii_view.handles.axial_axes,'selected','on'); set(nii_view.handles.axial_axes,'selected','off'); set(nii_view.handles.coronal_axes,'selected','on'); set(nii_view.handles.coronal_axes,'selected','off'); set(nii_view.handles.sagittal_axes,'selected','on'); set(nii_view.handles.sagittal_axes,'selected','off'); end case 'xhair_color', old_color = get(gcbo,'user'); new_color = uisetcolor(old_color); update_crosshaircolor(fig, new_color); case {'color','contrast_def'} nii_view = getappdata(fig,'nii_view'); if nii_view.numscan == 1 if get(nii_view.handles.colorindex,'value') == 2 set(nii_view.handles.contrast,'value',128); elseif get(nii_view.handles.colorindex,'value') == 3 set(nii_view.handles.contrast,'value',1); end end [custom_color_map, custom_colorindex] = change_colormap(fig); if strcmpi(command, 'color') setcolorlevel = nii_view.colorlevel; if ~isempty(custom_color_map) % isfield(nii_view, 'color_map') setcolormap = custom_color_map; % nii_view.color_map; else setcolormap = []; end if isfield(nii_view, 'highcolor') sethighcolor = nii_view.highcolor; else sethighcolor = []; end redraw_cbar(fig, setcolorlevel, setcolormap, sethighcolor); if nii_view.numscan == 1 & ... (custom_colorindex < 2 | custom_colorindex > 3) contrastopt.enablecontrast = 0; else contrastopt.enablecontrast = 1; end update_enable(fig, contrastopt); end case {'neg_color','brightness','contrast'} change_colormap(fig); case {'brightness_def'} nii_view = getappdata(fig,'nii_view'); set(nii_view.handles.brightness,'value',0); change_colormap(fig); case 'hist_plot' hist_plot(fig); case 'hist_eq' |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |