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

📄 imlook3d.m

📁 CT等医学图像的分割及其三维重建的MATLAB源代码
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = imlook3d(varargin)
% IMLOOK3D M-file for imlook3d.fig
%      IMLOOK3D, by itself, creates a new IMLOOK3D or raises the existing
%      singleton*.
%
%      H = IMLOOK3D returns the handle to a new IMLOOK3D or the handle to
%      the existing singleton*.
%
%      IMLOOK3D('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMLOOK3D.M with the given input arguments.
%
%      IMLOOK3D('Property','Value',...) creates a new IMLOOK3D or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before imlook3d_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to imlook3d_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% EXAMPLE:
%  Let us first load the mri image in Matlab using
%  >load mri;
%  and then run imlook3d
%  >imlook3d(squeeze(D)); % squeeze removes singleton dimensions
%
% Descriptions of Menus
% 
% ImFile:
% 
% -READ FROM WORKSPACE: Reads or displays images existing in the 
%  workspace(base).
% 
% -READ A STACK (DISK): Reads (displays)slices of images into a 3D array creating
%  a 3D image. It reads them from the disk. A file browser pups up and 
%  allows the user to pick up the first file in the series. It reads all
%  the files in the directory that has similar names except a suffix 
%  changing for each file. 
% 
%  For example: slice01.tif, slice01.tif,...,slice0N.tif 
% 
% -READ DICOM SERIES: 
%  Reads/displays series of DICOM images into a 3D array. A file browser 
%  pups up and allows users to select the first file in the series. 
%  It reads all the files in the directory that has similar names 
%  except a suffix changing for each file. 

% -SAVE SLICE AS TIFF:
%  Saves the current slice as a tiff image.

% -SAVE INTO WORKSPACE: This saves displayed 3D image into workspace as
%  a 3D variable. This may be useful to save the 3D image that is 
%  read by "read a stack (disk)".
%
% ImTools:
% 
% -PIXVAL: Allows looking at pixel intensities.
% -HISTOGRAM: Displays the histogram of the current image (slice).
% -PROFILE: Allows plotting intensity profiles across the image in an
%  interactive manner.
% -ADJUST INTENSITY RANGE: Allows adjusting the intensity range for 
%  the current slice. 
% -GLOBAL INTENSITY WINDOWING:
%  If not checked,not global, the intensity limits are set to [min(currentslice)
%  max(currentslice)]
%  
% VIEW MENU:
% 
%  This pup-up menu allows users to change the view of the image 
%  from transverse to sagittal or coronal views. It assumes that
%  original image is in transverse mode. 
%

% Copyright(c) Omer Demirkaya
% Last Modified by GUIDE v2.5 22-May-2007 21:27:00
% Begin initialization code - DO NOT EDIT

% This entire code or part of it could be modified and used if the due 
% credit to the original author is given.
%------------------------------------------------------------------

gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @imlook3d_OpeningFcn, ...
    'gui_OutputFcn',  @imlook3d_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
if isempty(varargin)
    disp('There was no image to display');
    disp('USAGE: >>imlook3d(img) or use ImFile menu to load an image');
    varargin{1,1} = zeros(32,32);
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before imlook3d is made visible.
function imlook3d_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for imlook3d
if isempty(varargin{:})
    return;
end
handles.output = hObject;
Std.Interruptible = 'off';
Std.BusyAction = 'queue';
Ax       = Std; 
Ax.Units = 'Pixels'; 
Ax.ydir  = 'reverse';
Ax.XLim  = [.5 128.5]; 
Ax.YLim  = [.5 128.5]; 
Ax.XTick = []; 
Ax.YTick = [];
Ax.CLimMode = 'auto';

set(handles.axes1,Ax);

Img = Std;Img.CData = [];Img.Xdata = [];Img.Ydata = [];
Img.CDataMapping = 'Scaled';
Img.Erasemode = 'none';
handles.image = Img;
inpargs = varargin{:};
[r,c,z] = size(inpargs);
handles.image.CData     = inpargs;
handles.imSize          = [r,c,z];
handles.viewtype        = 1;
handles.imageModality   = [];
handles.hText           = [];
handles.global_windowing= 0;
handles.SliceThickness  = [];
handles.imageInfo       = [];
handles.currentSliceNumber = 1;
handle.image.SliceSensitivityFactor =[];

handles.oimage = handles.image;
cimg = handles.image.CData(:,:,1);
% Create image object and set the properties
handles.ImgObject = image(Img,'Parent',handles.axes1);
set(handles.SliceNumEdit,'String',1);
set(handles.figure1,'Colormap',gray,'Units','Pixels');
% Set the properties of the axes
cclim =[min(cimg(:)) max(cimg(:))];
if (cclim(2)>0 & cclim(2)-cclim(1) ~= 0)
    set(handles.axes1,'CLim',cclim,...
        'PlotBoxAspectRatio',[c r 1]);
end
set(handles.axes1,'XLim',[1 c],'Ylim',[1 r],...
    'PlotBoxAspectRatio',[c r 1]);
set(handles.ImgObject,'Xdata',[1 c],'Ydata',[1 r],'CData',cimg);
drawnow
% Set the slider's value and step size
if z > 1
    turnDisplayButtons(handles,'on')
    set(handles.SliceNumSlider,'Min',1,'Max',z,'Value',...
        1,'SliderStep',[1.0/double(z-1) 1.0/double(z-1)]);
end
% Define the line and associate it with the context menu
set(handles.ImgObject,'UIContextMenu',handles.ImMaps);
% Update handles structure
%--------------------------------------------------------------------------
%% Set appdata for the inntensity adjustment GUI
setappdata(0  ,  'hMainGui'    , gcf);
hMainGui = getappdata(0, 'hMainGui');
maxINT = max(max(max(handles.image.CData)));
minINT = min(min(min(handles.image.CData)));
intensityParam = struct('lowerLimit',cclim(1),'upperLimit',cclim(2),...
    'maxIntensity', maxINT, 'minIntensity',minINT);
handles.intensityParam = intensityParam;
setappdata(hMainGui,  'intensityParam'  ,intensityParam);
%% Read and display logo image
% ----------------------------------------------------------------
fdir = which('imlook3d');
txt = [fdir(1:end-10) '\imlook3d.png'];
imlogo = imread(txt);
Sz= size(imlogo);
flogo = figure('Position',[10000 10000 Sz(2) + 4 Sz(1) + 4],'name','Imlook3D',...
    'numbertitle','off','menubar','none');
movegui(flogo,'center');
set(flogo,'Units', 'pixels');
image(imlogo(:,:,1:3))
set(gca, ...
    'Visible', 'off', ...
    'Units', 'pixels', ...
    'Position', [2 2 Sz(2) Sz(1)]);
text(220,16,'3D Image Display Tool','Fontsize',12);
text(130,355,'Version 1.2: Copyright 2006, Omer Demirkaya','Fontsize',8);
pause(3);delete(flogo);clear imlogo
%% ------------------------------------
%--------------------------------------------------------------------------
guidata(hObject, handles);
%--------------------------------------------------------------------------
% --- Outputs from this function are returned to the command line.
function varargout = imlook3d_OutputFcn(hObject, eventdata, handles)
 varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function SliceNumSlider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% --- Executes on slider movement.
%------------------------------------------------------------
function SliceNumSlider_Callback(hObject, eventdata, handles)
NewVal= round(get(hObject,'Value'));
cimg = handles.image.CData(:,:,NewVal);
if ~(handles.global_windowing)
    cclim = [min(cimg(:)) max(cimg(:))];
    if (cclim(2)>0 & cclim(2)-cclim(1) ~= 0)
        set(handles.axes1,'CLim',[min(cimg(:)) max(cimg(:))])
    end
else
    set(handles.axes1,'CLim',[handles.intensityParam.lowerLimit  handles.intensityParam.upperLimit])
end  
set(handles.ImgObject,'Cdata',cimg);
set(handles.SliceNumEdit,'String',num2str(NewVal));
drawnow
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function SliceNumEdit_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%--------------------------------------------------------------------------
function SliceNumEdit_Callback(hObject, eventdata, handles)
z= size(handles.image.CData,3);
strg = get(hObject,'String');
if str2num(strg)>=1 & str2num(strg)<=z
    set(handles.SliceNumSlider,'Value',str2num(strg));
    cimg = handles.image.CData(:,:,str2num(strg));
    set(handles.ImgObject,'Cdata',cimg);
    handles.currentSliceNumber = str2num(strg);
    drawnow
end
if ~(handles.global_windowing)
    cclim = [min(cimg(:)) max(cimg(:))];
    if (cclim(2)>0 & cclim(2)-cclim(1) ~= 0)
        set(handles.axes1,'CLim',[min(cimg(:)) max(cimg(:))])
    end
else
    set(handles.axes1,'CLim',[handles.intensityParam.lowerLimit  handles.intensityParam.upperLimit])

end 
guidata(hObject, handles);
% --------------------------------------------------------------------
% --------------------------------------------------------------------
function changeColorMaps_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function petColormaps_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function CTcolormaps_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
% --------------------------------------------------------------------
function Hot_Callback(hObject, eventdata, handles)
htable = feval('hot');
set(handles.figure1,'Colormap',htable); 
if handles.imSize(3)> 1 
    set(handles.SliceNumEdit,'BackgroundColor',[.1 .1 .1],'ForegroundColor','r');
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function Gray_Callback(hObject, eventdata, handles)
htable = feval('gray');
set(handles.figure1,'Colormap',htable);
if handles.imSize(3)> 1 
    set(handles.SliceNumEdit,'BackgroundColor','k','ForegroundColor','w');
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function InvGray_Callback(hObject, eventdata, handles)
htable = 1-feval('gray');
set(handles.figure1,'Colormap',htable);
if handles.imSize(3)> 1 
    set(handles.SliceNumEdit,'BackgroundColor','w','ForegroundColor','k');
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function Jet_Callback(hObject, eventdata, handles)
htable = feval('jet');
set(handles.figure1,'Colormap',htable);
if handles.imSize(3)> 1 
    set(handles.SliceNumEdit,'BackgroundColor','b','ForegroundColor','y');
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function boneWindow_Callback(hObject, eventdata, handles)
handles.intensityParam.lowerLimit = -250;
handles.intensityParam.upperLimit = 1250;
set(handles.axes1,'CLim',[-300 1250])
guidata(hObject,handles);
% --------------------------------------------------------------------
function lungWindow_Callback(hObject, eventdata, handles)
handles.intensityParam.lowerLimit = -2500;
handles.intensityParam.upperLimit = 1100;
set(handles.axes1,'CLim',[-2500 1100])
guidata(hObject,handles);
% --------------------------------------------------------------------
function mediasitnalWindow_Callback(hObject, eventdata, handles)
handles.intensityParam.lowerLimit = -450;
handles.intensityParam.upperLimit = 350;
set(handles.axes1,'CLim',[-450 350])
guidata(hObject,handles);
% --------------------------------------------------------------------
%---------------------------------------------------------
% Callbacks for imtoolsmenu
%----------------------------------------------------------
function imToolsMenu_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function imPixval_Callback(hObject, eventdata, handles)
if isempty(handles.hText)
handles.hText = impixelinfoval(handles.figure1,handles.ImgObject);
set(handles.hText,'FontWeight','bold');
set(handles.hText,'FontSize',10);
else
    delete(handles.hText);
    handles.hText =[];
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function imHistogram_Callback(hObject, eventdata, handles)
myhistogram(1)
%-------------------------------------------------------------
function imProfile_Callback(hObject, eventdata, handles)
improfile;
title('Intensity profile');
ylabel('Intensity');
xlabel('Pixel position');
%------------------------------------------------
% Histogram function
% -----------------------------------------------
function myhistogram(htype)

⌨️ 快捷键说明

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