File Exchange

image thumbnail

Medical Image Processing Toolbox

version 1.3 (166 KB) by Alberto Gomez
Classes and functions for N-dimensional medical image processing, inspired by ITK


Updated 27 Jun 2016

View License

This package contains a collection of classes and functions, which allow to comfortably work with medical images and meshes. It provides a intuitive and transparent way of dealing with spacing, origin, image orientation, etc. The package includes functions for input-output with common image formats (mhd, gipl) and mesh formats (vtk, stl), and basic (although not necessarily simple) image processing operations such as image resample, image reslice and image transform.
Please do not hesitate to propose new features, examples or any constructive comments!

Cite As

Alberto Gomez (2019). Medical Image Processing Toolbox (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (33)

yijun WANG


Mete Naz


Can I read seg.nrrd file with any of your codes? I tried .nrrd reader but it gave me errors since segmented data is, I guess, considered as 4D volume. Is there any way to read .seg.nrrd file?

Thanks in advance!

it is nice but pls send me mni project based on medical image proccesing

can you please explain how can I call this function (write_mhd(file name, image))? I can not understand the input parameters?
what is the differences of file name and image??

Hello, I am trying to add the toolbox to my Matlab. But, I have this error 'Community-authored Add-Ons are temporarily unavailable'.
Is there any solution for this. Thank you

Shen DU

Hello, I am trying to dilate a 3D geometry in STL format.
With the function read_stlMesh, the geometry could be loaded successfully.
Then I try to use the function meshDilate(). It does not work and a problem "ERROR: there is no attribute available".

So I wonder does it possible to dilate a geometry in STL format ?

Thanks in advance for your reply.

R Lin

I tried to load mhd files, it was going well but I got the following error for some mhd files:
Undefined function or variable 'zlibdecode'.

Error in read_mhd>read_raw (line 75)
rawData =zlibdecode(uint8(rawData));

Error in read_mhd (line 20)
data = read_raw([ path filesep info.DataFile ], info.Dimensions,info.DataType,'native',0,ndims, info);

Did I do something wrong?

I try to write mhd/mha image using the write_mhd() function, but it fails.
My image is a 3D matrix of double values.
I get this type of error: Attempt to reference field on non-structure array.
Because my image is not a struct, then it fails to reach the image.size and image.orientation fields.

Is there any restriction on the input data? And which format should I use?

Thank you

in this awesome tool box you're depending on Frustum as an already built class.
But unfortunately I couldn't find it.
any one has can help me find the frustum class?
Best Regards



I have data format as .img and .hrd. and i want to use this tool (

But it support .bin and .header format.

Would you let me know how to convert .img and .hrd or .raw and .mhd to .bin and .header format so that i can use the above mentioned tool for my data for 3d to 3D rigid image registration. I have knee MRI data, not brain MRI

revathi t

Will this toolbox work with my matlab2014a?


Can we use this for mha files??


how can i trannsform mhd image by 4*4 matrix??
my code:
matrix=[ -0.9357 0.2129 0.2815 -424.3918
0.2370 -0.2120 0.9481 -329.0604
0.2615 0.9538 0.1479 363.3647
0 0 0 1.0000];

outputImage = transformImage(matrix,volinputImg,volreferenceImage,'debug' );

% % % Error is appeared in ImageType(referenceImage) function; inputImg=Vol_moving;
% % % Error is appeared in sub function ImageType(referenceImage);referenceImage=Vol_fixed;

You can currently import meshes in VTK ASCII format. For vtk images, you need to convert them to mhd first. You can use Paraview for that.


Hi Guys, I have to import data from VTK file to Matlab and show them. Do you have some tutorial for it ? Thx


The toolbox currently supports gipl and mhd only.

I have added some mising files like vtkMathPerpendiculars.m

Thanks for rating

And is it possible to open analyze(.hdr and .img)? NiFTi (.nii) and .nrrd files with your code?

Hi! Thanks for sharing code!
When I try to run test_image.m I get a message "Undefined function 'vtkMathPerpendiculars'". Where I can get it?

you can display the image by doing imshow(


Shruti naik

hi alberto, thanks! :) do we directly need to run read_mhd and how exactly display the .mha files using imshow()? do revert :) waiting!! regards

first of all thanks sharing code

i want to ask a question

i have dwi brain image .gipl format.i want to tick on .gipl image with roi and then want to make logic one in roi area and logic zero outside of roi area

if someone knows how it is done, kindly help me

waiting feedback


Hi Noha,
You do not need to change paths for this package in particular. You will need to add the files to your matlab path (as you would do for any other package) or put the file in your working directory. Usually it is enough to right click in the folder where the files are from the matlab file browser and click on "add to path"-> "selected folders and subfolders".

Noha Asas

How could I deploy that package, so as to use the functions immediately without the need to change paths??

Unfortunately it currently reads/writes ASCII vtk mesh files only. Mhd binary files are supported though.


Can it read binary VTK?

Yes Akshay, among several other functionalities that is exactly what it does

Akshay Gore

Is this function used to read raw/mhd file?

Bo Sun

Could this toolbox read and write '.mha' files? Since i only found the function used to read and write '.mhd' files.Thanks



* Some bug fixing and extended features for neighbourhood operations
* Extended image I/O
* Improved visualization

Some bug fixing
Added some missing functions

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Read Medical Data 3D

Inspired: Simple Viewer 3D