File Exchange

image thumbnail

Medical Image Reader and Viewer

version 3.83 (918 KB) by

A toolbox to handle reading, viewing, and writing dicom images, supporting simultaneous PET/MR



View License

This toolbox can read and write medical imaging data in dicom format with the 'readImages' function. The output of this function is a structure containing attributes of the image or volume. This structure can then be used as input into other functions in the toolbox.
This toolbox supports:
- reading and writing of dicom data
- mapping of volume voxel locations
- oblique slice alignment and registration
- manual 3D image rotation
- selecting and extracting single voxel coordinates
- drawing 2D or 3D region-of-interest masks
- coregistered image viewing supports PET/CT and PET/MR

CT = readImages([CT_ImageDirectoryPath]);
PET = readImages([PET_ImageDirectoryPath]);
coords = VolumeViewer3D(PET,CT,'getCoords');
mask = VolumeViewer3D(PET,CT,'drawROI');

Comments and Ratings (31)

HiJosh and everyones, i have face this problem? please help me

VolumeViewer3D(p, c)
coregistering volumes...
Cannot find an exact (case-sensitive) match for 'Settings'

The closest match is: settings in C:\New folder\pet\settings.m

Error in VolumeViewer3D>initialSetup (line 1535)
s = Settings;

Error in VolumeViewer3D (line 184)

At line 230 in dicm_hdr, the operation s.PixelData.Start = p.iPixelData; creates the structure field 'PixelData' within structure 's'. Since your version is complaining, try to add the following line just before this, at line 229

s.PixelData = struct;

Let me know if this works. If it does, I'll make the change and update the version - if not, try to share your data so I can attempt to reproduce the error on my end.

Jie Deng

Hi Josh, it says 'File read error, try again with another file', followed by a pop up window for single file selection. When I select a single .dcm file, here is the error msg. They are GE PET images.

Field assignment to a non-structure array object.

Error in dicm_hdr (line 230)
s.PixelData.Start = p.iPixelData;

Error in readImages>parseInputs (line 363)
test = dicm_hdr([imageDir imageFiles{1}]);

Error in readImages (line 87)
inStruct = parseInputs(varargin{:});

What is the problem you are having? Put a breakpoint on the line containing the call to 'readDicomImages' then call it from the command line to produce the error.

Jie Deng

Thanks for building and sharing this toolbox, very helpful! I am currently using 2017a version but encountered a problem reading images using 'readImages', do you have any idea why?

Trina Kok


Josh (view profile)

you can do this easily (e.g. if your mask has the same dimensions as PET.volumes):

mask = logical(mask);
VolumeViewer3D(PET, mask);


Sorry Josh, i have presented my question badly. In fact, I have already my mask and I'd like to show it together with PET-CT scan,for example, with "contour" function. But i'm not sure where i should add these codes in your original codes.
Thank you :)


Josh (view profile)

For example, say you want make a mask of an image 'Im', matching its dimensions, [imX, imY, imZ], for all pixels above 'threshold' in a 11x11x11 box centered on [x, y, z], you could do something like this:

mask = false(imX, imY, imZ);
mask(x - 5 : x + 5, y - 5 : y + 5, z - 5 : z + 5) = true;
mask = mask & Im > threshold;


Thanks for the reponse. I have fixed missed information in my dicom file :) And SUV works well! I'm now trying to add a contour mask on the image. Hope for suggestions, thank you :)


Josh (view profile)

Thanks Yuntao. The viewer shows PET SUV by default, but it must have all the required information from the Dicom, i.e. injection and scan times, subject mass, image quantification units, and radiotracer. Put a breakpoint on the call to 'calculateSUV', then call it manually from the prompt. This will point to the problem.


Thank you Josh Schaefferkoetter. That's a great job which helps me a lot on my project. I think it will be better if the toolbox can also show the suv value :)

Lalith kumar

Amazing contribution Josh. This tool helped me a lot :)!


Josh (view profile)

The function was looking for a dicom field that did not exist in those TCIA images. I added a check to avoid this - try the new version. Thanks for pointing this out.


quix (view profile)

Hi, nice toolbox!

I tried to read in an image from The Cancer Imaging Archive (TCIA) but was unable to. The message is 'File read error, try again with another file'. The message is repeated for any single slice I choose in the series.

The data can be retrieved here:, Subject ID: QIN-HEADNECK-0003

Josh, thank you for the hint. I just doubled each font size and now I have a nice display. I am using your viewer on my iMac 27" with 2560 x 1440 pixels. The original fonts display was really tiny and hard to read. Now it works fine.

Thank your for this helpful toolbox which I am using for my research work!


Josh (view profile)

Thanks for the feedback. The viewer was tested at high DPI and normal 1080 resolution. What size is your display?

The quick fix would be to do a ctrl-F search through VolumeViewer3D.m for 'FontSize' and change all the necessary field values. Let me know which value works best for the screen you are using.

Is there any chance to increase the font size of the sliders, value outputs and handles in the 3D Viewer window? Unfortunately on my machine everything is pretty small on the screen. But besides that drawback the 3D Viewer is superb!

I'll consider adding these to the next version. Thanks for the feedback!

Just in case it is useful for others,
With Matlab2014a I needed to add a try/catch in VolumeViewer3D.m (line 3372)
if s.matlab.desktop.HighDPISupport
hAxOffset = 0.0005;
vAxOffset = 0.0005;
hAxOffset = 0.0007;
vAxOffset = 0.001;

Very useful tool. I had to adapt it to read GE images from the cancer imaging archive, because some tags in the dicom info are vendor-specific. I used the dictionary from
I changed in all cases:
dict = dicm_dict('GE');
meta = dicm_hdr([imageDir '\' imageFile], dict);
instead of:
meta = dicominfo([imageDir '\' imageFile]);

Peter Lakner

Peter Lakner

Where/how should I share the data?

Thanks for the feedback. I wrote the code to prompt for new image data if any errors were found, this is convenient but makes it tricky to troubleshoot - maybe I'll think of a different way to handle this... In the meantime, if you can share your dicom data, I'll take a look.

Peter Lakner

Please ignore that last comment, I pressed enter by mistake. The current version does not seem to work for me, using the readImages function, even if I provide the directories it opens a file finder, and whenever I select a file it tells me there is a "File read error, try again with another file."

Peter Lakner

Hello, getting a file read error

The output variable is now initialized as a structure so should fix the problem. Let me know if it still doesn't work.

Looks nice program, but I have a similar problem as payam. After loading GE images with MATLAB 2015b:
Field assignment to a non-structure array object.

Error in VolumeViewer3D>parseInputs (line 397)
out.modality = 'VOL';

Error in VolumeViewer3D (line 36)
inStruct = parseInputs(varargin);

I loaded several PET studies from the TCIA site, including the phantom data, and found a small bug related to the GE and Philips series naming convention; I couldn't reproduce your error though. With which specific data sets were you having issues?

The toolbox seems good.
I have tried to read a PET volume from TCIA ( using readImages. I faced this error:

Field assignment to a non-structure array object.

Error in readImages (line 82)
out.nSeries = nSeries;

Also the same error for phantom images. I am using Matlab 2015b.



fixed high DPI display bug


bug with reading dicom


small bug with writing dicom


fixed bug for reading dicom files with no extension


performance tweaks


updated examples


faster image coregistration


minor improvements


incomplete filename bug fix


ability to combine 2D and 3D, and volume and mask inputs


improved input handling


improved input and error handling




corrected dicom tag writing


UI formatted for high DPI displays


updated examples


updated examples


Ability to draw and output 2D or 3D mask


output structure initialization


modified coregistration


GE and Philips series naming convention bug fix


minor tweaks


fixed smoothing functionality


small bug fix


minor tweaks and enhancements


updated examples


faster and more accurate interpolation


performance improvements


bug fixes


improved handling of large image matrices


faster and more efficient memory handling

MATLAB Release
MATLAB 8.5 (R2015a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today