⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avw_view.m

📁 mri_toolbox是一个工具用来MRI. 来自于SourceForge, 我上传这个软件,希望能结识对医疗软件感兴趣的兄弟.
💻 M
📖 第 1 页 / 共 5 页
字号:
        set(AVWVIEW.handles.nasion,'String',string);
        AVWVIEW.avw.fiducials.nasion.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
        AVWVIEW.avw.fiducials.nasion.meters(1,:) = AVWVIEW.imgXYZ.meters;
        AVWVIEW.avw.fiducials.nasion.mm(1,:)     = AVWVIEW.imgXYZ.mm;
      case 'rpa',
        set(AVWVIEW.handles.rpa,'String',string);
        AVWVIEW.avw.fiducials.rpa.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
        AVWVIEW.avw.fiducials.rpa.meters(1,:) = AVWVIEW.imgXYZ.meters;
        AVWVIEW.avw.fiducials.rpa.mm(1,:)     = AVWVIEW.imgXYZ.mm;
      case 'lpa',
        set(AVWVIEW.handles.lpa,'String',string);
        AVWVIEW.avw.fiducials.lpa.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
        AVWVIEW.avw.fiducials.lpa.meters(1,:) = AVWVIEW.imgXYZ.meters;
        AVWVIEW.avw.fiducials.lpa.mm(1,:)     = AVWVIEW.imgXYZ.mm;
      case 'ac',
        set(AVWVIEW.handles.ac,'String',string);
        AVWVIEW.avw.ac.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
        AVWVIEW.avw.ac.meters(1,:) = AVWVIEW.imgXYZ.meters;
        AVWVIEW.avw.ac.mm(1,:) = AVWVIEW.imgXYZ.mm;
    end
    
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'flip',
    
    % flip X dim here...
    AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
    
    if isfield(AVWVIEW.handles,'axial_image'),
      Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
      set(AVWVIEW.handles.axial_image,'CData',Saxi');
    end;
    if isfield(AVWVIEW.handles,'coronal_image'),
      Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
      set(AVWVIEW.handles.coronal_image,'CData',Scor');
    end;
    if isfield(AVWVIEW.handles,'sagittal_image'),
      Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
      set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
    end;
    
    flipStatus = get(AVWVIEW.handles.flipStatus,'string');
    if strmatch(flipStatus,'R>>L (radiological)'),
      flipStatus = 'L>>R (neurological)';
    else,
      flipStatus = 'R>>L (radiological)';
    end;
    set(AVWVIEW.handles.flipStatus,'string',flipStatus);
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case {'brighter','dimmer','setclimit'},
    
    switch command,
      case 'brighter',
        AVWVIEW.clim = AVWVIEW.clim .* 0.9;
      case 'dimmer',
        AVWVIEW.clim = AVWVIEW.clim .* 1.1;
      case 'setclimit',
        clim = get(AVWVIEW.handles.clim,'string');
        AVWVIEW.clim(2) = str2num(clim);
    end
    climString = sprintf('%05.2f',AVWVIEW.clim(2));
    set(AVWVIEW.handles.clim,'string',climString);
    
    if isfield(AVWVIEW.handles,'axial_image'),
      set(AVWVIEW.handles.axial_axes,'Clim',AVWVIEW.clim);
    end;
    if isfield(AVWVIEW.handles,'coronal_image'),
      set(AVWVIEW.handles.coronal_axes,'Clim',AVWVIEW.clim);
    end;
    if isfield(AVWVIEW.handles,'sagittal_image'),
      set(AVWVIEW.handles.sagittal_axes,'Clim',AVWVIEW.clim);
    end;
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'contrast'
    
    if isfield(AVWVIEW.handles,'axial_image'),
      X = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
      AVWVIEW.cmap = contrast(X);
      colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
    end;
    if isfield(AVWVIEW.handles,'coronal_image'),
      X = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
      AVWVIEW.cmap = contrast(X);
      colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
    end;
    if isfield(AVWVIEW.handles,'sagittal_image'),
      X = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
      AVWVIEW.cmap = contrast(X);
      colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
    end;
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'setcmap'
    
    cmapIndex = get(AVWVIEW.handles.cmap,'value');
    cmapString = get(AVWVIEW.handles.cmap,'string');
    
    AVWVIEW.cmapString = cmapString{cmapIndex};
    
    if isfield(AVWVIEW.handles,'axial_image'),
      AVWVIEW.cmap = colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmapString);
    end;
    if isfield(AVWVIEW.handles,'coronal_image'),
      AVWVIEW.cmap = colormap(AVWVIEW.handles.coronal_axes,AVWVIEW.cmapString);
    end;
    if isfield(AVWVIEW.handles,'sagittal_image'),
      AVWVIEW.cmap = colormap(AVWVIEW.handles.sagittal_axes,AVWVIEW.cmapString);
    end;
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'histogram',
    
    avw = AVWVIEW.avw;
    
    % would be nice to use bins that reflect
    % the bits per pixel, but it seems to take
    % forever for a 16 bit image, otherwise
    % use this code:
    %     %check the bits per pixel of avw
    %     bitpix = avw.hdr.dime.bitpix;
    %     % set the bins according to the data type
    %     if bitpix <= 8, bins = 0:255; end
    %     if bitpix > 8,  bins = 0:65535; end
    
    %bins = linspace(0,intensity_max,255);
    
    intensity_min = min(min(min(avw.img)));
    intensity_max = max(max(max(avw.img)));
    
    bins = intensity_min:intensity_max;
    
    fprintf('...calculating histogram for %d bins.\n',length(bins));
    
    for i=1:size(avw.img,3),
      n = hist(avw.img(:,:,i), bins);
      if i == 1,
        intensity_volume = sum(n,2);
      else
        intensity_slice = sum(n,2);
        intensity_volume = intensity_volume + intensity_slice;
      end
    end
    figure('name','intensity histogram');
    bar(bins,intensity_volume);
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'zoom'
    
    x = AVWVIEW.slices.sag;
    y = AVWVIEW.slices.cor;
    z = AVWVIEW.slices.axi;
    
    switch AVWVIEW.view,
      case 'axi',
        slice = rot90(AVWVIEW.avw.img(:,:,z));
      case 'cor',
        slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
      case 'sag',
        slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
    end
    
    figure;
    imagesc(slice,AVWVIEW.clim); 
    colormap(gray); axis off; zoom on;
    daspect(AVWVIEW.daspect);
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'save_image',
    
    [filename, pathname] = uiputfile(...
      { '*.png','PNG Files (*.png)'; ...
        '*.jpg','JPG Files (*.jpg)'; ...
        '*.ppm;*.pgm;*.pbm','Portable Anymap (*.ppm,*.pgm,*.pbm)'; ...
        '*.*',  'All Files (*.*)'}, ...
      'IMWrite to file');
    
    if filename,
      
      x = AVWVIEW.slices.sag;
      y = AVWVIEW.slices.cor;
      z = AVWVIEW.slices.axi;
      
      pixelsPerMM = 1 ./ double(AVWVIEW.avw.hdr.dime.pixdim(2:4));
      pixelsPerMeter = pixelsPerMM .* 1000;
      
      switch AVWVIEW.view,
        case 'axi',
          slice = rot90(AVWVIEW.avw.img(:,:,z));
          xresolution = pixelsPerMeter(1);
          yresolution = pixelsPerMeter(2);
        case 'cor',
          slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
          xresolution = pixelsPerMeter(1);
          yresolution = pixelsPerMeter(3);
        case 'sag',
          slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
          xresolution = pixelsPerMeter(2);
          yresolution = pixelsPerMeter(3);
      end
      
      % scale the image values to between 0-1 for imwrite
      % (initially used max of slice, but actually want to
      % use the scaled intensity from the gui).
      %maxValue = max(max(slice));
      %scaledSlice = slice ./ maxValue;
      scaledSlice = slice ./ AVWVIEW.clim(2);
      
      % RGB = ind2rgb(X,map) converts the matrix X and corresponding 
      % colormap map to RGB (truecolor) 
      
      file = [pathname,filename];
      fprintf('saving to:...%s\n',file);
      
      %Most of the supported image file formats store uint8 data. 
      %PNG and TIFF formats additionally support uint16 data. For 
      %grayscale and RGB images, if the data array is double, the 
      %assumed dynamic range is [0,1]. The data array is automatically 
      %scaled by 255 before being written as uint8. If the data array 
      %is uint8 or uint16, it is written without scaling as uint8 or 
      %uint16, respectively. 
      
      [pathname,filename,ext] = fileparts([pathname,filename]);
      
      switch ext,
      
        case '.png',
          %imwrite(uint8(image),colormap,file,format);
          %imwrite(slice,colormap(gray),file,format,...
          
          %     'XResolution'  A scalar indicating the number of
          %                    pixels/unit in the horizontal direction
          %  
          %     'YResolution'  A scalar indicating the number of
          %                    pixels/unit in the vertical direction
          %  
          %     'ResolutionUnit' Either 'unknown' or 'meter'
          format = 'png';
          imwrite(scaledSlice,file,format,...
            'BitDepth',16,'ResolutionUnit','meter',...
            'XResolution',xresolution,...
            'YResolution',yresolution);
          
        case '.jpg',
          format = 'jpg';
          imwrite(scaledSlice,file,format);
        case {'.ppm','.pgm','.pbm'},
          format = ext(2:end);
          imwrite(scaledSlice,file,format);
        otherwise
          fprintf('...cannot write %s image files\n',ext);
      end
    end
    
    
    
    
    
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'quit',
    
    flipStatus = get(AVWVIEW.handles.flipStatus,'string');
    if strmatch(flipStatus,'L>>R (neurological)'),
      fprintf('...returning avw.img to radiological orientation;\n');
      fprintf('...use avw_flip to permanently change the orientation.\n');
      AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
    end;
    
    % try to assign back into the input struct
    if ~isempty(AVWVIEW.invarname),
      fprintf('...returning data to base workspace struct ''%s''\n',AVWVIEW.invarname);
      assignin('base',AVWVIEW.invarname,AVWVIEW.avw);
    elseif evalin('base','exist(''mri'',''var'')'),
      fprintf('...returning data to base workspace struct ''mri''\n');
      string = ['AVWVIEW = get(', num2str(AVWVIEW.gui),...
          ',''Userdata''); mri.data = AVWVIEW.avw; clear AVWVIEW;'];
      evalin('base',string);
    else
      fprintf('...returning data into base workspace struct ''avw''\n');
      assignin('base','avw',AVWVIEW.avw);
    end
    close gcbf;
    
  otherwise,
    
end


switch command,
  case 'quit',
  otherwise,
    set(AVWVIEW.gui,'UserData',AVWVIEW);
end

if nargout > 0,
  varargout{1} = AVWVIEW.avw;
end


return









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTIONS






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function axial_update(AVWVIEW)

if isfield(AVWVIEW.handles,'axial_image'),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -