This is an image viewer designed to view a 3D stack of image slices. For example, if you load into matlab a DICOM series of CT or MRI images, you can visualize the images easily using this tool. It lets you scroll through slices, adjust the window and level, make ROI measurements, and export images into standard image formats (e.g., .png, .jpg, or .tif) or the 3D mask as NIFTI file (.nii). Use imtool3D_nii to load NIFTI files.
This tool is written using the object-oriented features of matlab. This means that you can treat the tool like any graphics object and it can easily be embedded into any figure. So if you're designing a GUI in which you need the user to visualize and scroll through image slices, you don't need to write all the code for that! Its already done in this tool! Just create an imtool3D object and put it in your GUI figure.
imtool3D is used heavily by several other projects: qMRLab, imquest, lesionTool
- Matlab's image processing toolbox (ROI tools are disabled otherwise)
- dicm2nii (if NIFTI images are used)
Mouse control | action |
---|---|
Middle (shift+) Click and drag | Zoom in/out |
Left Click and drag | Contrast/Brightness |
Right (ctrl+) Click and drag | Pan |
Scroll wheel | Change slice |
imtool3D features 3D multi-label mask (ROI) that can be loaded, edited and saved.
Segmentation strategy in imtool3D consists in adjusting contrast to reveal the targeted structure, and alternating between (1) manual smart brush segmentation, (2) active contour, (3) slice interpolation, (4) 3D smoothing of the mask and (5) plane orientation (axial, sagittal or coronal).
See the demo for Brain tumor segmentation using imtool3D_nii_3planes.m
or imtool3D_3planes.m
Brush tool controls | action |
---|---|
Middle click and drag | Change brush diameter |
Right click | erase |
double click (smart brush only) | Toggle between bright or dark segmentation |
- Measure area
- Get stats in this area
- Show intensity profile
- Measure distance in pixels
- Symmetrize the mask (replicate mask with respect to the line)
- Split the mask in two parts
- Colorbar button on top left to show current slice histogram and colorbar
- Use histogram button on the right to get statistics and interactive histogram plot in the different ROI
- Drag and drop files on the viewer to load them
- Create your own open function for your specific file extention
imreadext.m
. For example (.png file):
function I = imreadpng(pngfile)
I = imread(pngfile);
- Append in the volume (5th) dimension or replace already loaded data
Use imtool3D_3planes.m to display the three orientation planes.
A = rand(100,100,30,10,3);
imtool3D(A)
load mri % example mri image provided by MATLAB
D = squeeze(D);
D = permute(D(end:-1:1,:,:),[2 1 3]); % LPI orientation
tool = imtool3D(D);
tool.setAspectRatio([1 1 2.5]) % set voxel size to 1mm x 1mm x 2.5mm
% Add viewer in a panel in the middle of the GUI
GUI = figure('Name','GUI with imtool3D embedded');
annotation(GUI,'textbox',[0 .5 1 .5],'String','Create your own GUI here',...
'HorizontalAlignment','center','VerticalAlignment','middle');
Position = [0 0 1 .5]; % Bottom. normalized units
tool = imtool3D([],Position,GUI)
% set MRI image
load mri % example mri image provided by MATLAB
D = squeeze(D);
D = permute(D(end:-1:1,:,:),[2 1 3]); % LPI orientation
tool.setImage(D)
tool.setAspectRatio([1 1 2.5]) % set voxel size to 1mm x 1mm x 2.5mm
corn_gray = imread('corn.tif',3); % load the gray version
imtool3D(corn_gray)
corn_RGB = imread('corn.tif',2); % load RGB version
tool=imtool3D(corn_RGB);
tool.isRGB = 1;
[corn_indexed,map] = imread('corn.tif',1); % load indexed version
tool = imtool3D(corn_indexed);
h = tool.getHandles;
colormap(h.Axes(tool.getNvol),map)
colormap(h.HistImageAxes,map)
tool.setClimits([0 255])
tool = imtool3D;
tool.montage = 1;
Brain montage:
v = VideoReader('xylophone.mp4');
tool = imtool3D(v.read([1 Inf]));
tool.isRGB = 1;
use left/right arrows to move through image frames
use shift+right for fast forward (10-by-10 frames)
For this example, we will display color-coded nerve direction of the brain.
Download HCP Diffusion MRI Template http://brain.labsolver.org/diffusion-mri-templates/hcp-842-hcp-1021
%% load HCP Diffusion MRI Template
load('HCP842_1mm.fib','-mat')
% reshape FA
fa0 = reshape(fa0,dimension); fa0 = fa0(:,end:-1:1,:);
% Find diffusion peak direction
peak = reshape(odf_vertices(:,index0+1)',[dimension 3]);
peak = peak(:,end:-1:1,:,:);
%% Open imtool3D and display
tool = imtool3D(repmat(fa0,[1 1 1 3]).*abs(peak));
% use RGB mode
tool.isRGB = 1;
tool.RGBdim = 4;
tool.RGBindex = [1 2 3];
% move to slice 63
tool.setCurrentSlice(63)
Brain nerve bundles color-coded by direction:
(red: left-right, green: antero-posterior, blue: superior-inferior)
Use button bellow left slider ('R' on the screenshot) to turn between RGB and grayscale and to select active color channelIn this example, we display the mouse brain atlas from Allen Institute Website
% read template and mask
[AVGT, metaAVGT] = nrrdread('average_template_25.nrrd');
[ANO, metaANO] = nrrdread('annotation_25.nrrd');
% renumbering of labels
ic = unique(ANO(:));
for ii=1:length(ic)
ANO(ANO==ic(ii))=ii;
end
% display
tool = imtool3D(permute(AVGT(end:-1:1,:,:),[3 2 1]));
tool.setMask(permute(ANO(end:-1:1,:,:),[3 2 1]))
tool.setMaskColor(jet(length(ic)))
tool.setAlpha(.1)
For this example we will display a map of brain activation extracted from an FMRI dataset.
Download fmri dataset: http://www2.bcs.rochester.edu/sites/raizada/Matlab/fMRI/speech_brain_images.mat
load('speech_brain_images.mat'); % load dataset
tool = imtool3D({subj_3danat speech_Tmap});
tool.setNvol(2); % show top image (brain activation for speech task)
tool.setClimits([1 7]); % threshold activation >1
tool.changeColormap('hot')
tool.setOpacity(.3)
Brain activation during a speech task:
% list your images
imlist = dir(fullfile(toolboxdir('images'),'imdata','BrainMRILabeled','images','vol_*.mat'));
for ii=1:5
% load image
load(fullfile(imlist(ii).folder,imlist(ii).name))
% display image in imtool3D
tool = imtool3D(vol);
% wait for closing imtool3D figure
waitfor(tool.getHandles.fig);
% get Mask
Mask = tool.getMask(1);
% save Mask
save(['Mask' num2str(ii) '.mat'],'Mask')
end
- Support for 5D volumes (scroll through time and volumeS with arrows)
- Keyboard shortcut
- Multi-label mask
- Save mask
- NIFTI files (.nii) support (double click on a. nii file in Matlab filebrowser)
- New tools for mask (interpolate slices, active contour...)
- Convert Mask2poly and poly2mask
- splines in polygons (double click a circle)
- 3 planes view
Justin Solomon (Original release)
Tanguy Duval (4D (time) and 5D (different contrast); multi-label mask; active_contour, undo button, mask2poly, poly2mask, shortcuts)
https://fr.mathworks.com/matlabcentral/fileexchange/40753-imtool3d