Code covered by the BSD License  

Highlights from
Viewer3D

4.81818

4.8 | 35 ratings Rate this file 254 Downloads (last 30 days) File Size: 9.48 MB File ID: #21993
image thumbnail

Viewer3D

by

 

04 Nov 2008 (Updated )

MIP, Color, Slice and Shaded 3D (shearwarp) Volume Rendering, interactive 3D view/measurement GUI

| Watch this File

File Information
Description

This function can be used to interactively view any kind of 2D,3D and 4D image volumes like CT and MRI. Allowing segmentation and distance measurements or ROI selection in 2D slices.

It includes Maximum intensity projections (MIP), Volume Rendering (VR) , Slice render, and colored and Phong shaded Volume rendering.

Voxel opacity and color tables can be changed on the fly allowing also iso surface kind of renders.

The fast render algorithm which renders a 3D volume to a 2D image, is based on a Matlab coded implementation of the Shear-Warp transform, in which instead of rotating the viewer rays the slices are sheared.

There are two major Matlab files:
- viewer3d.m : The interactive GUI
- render.m : The function which renders volume data with the shear-warp transform to an 2D image.

File-formats supported:
    Matlab Files (.mat)
    Dicom Files ( .dcm , .dicom )
    V3D Philips Scanner ( .v3d )
    GIPL Guys Image Processing Lab ( .gipl )
    HDR/IMG Analyze ( .hdr )
    ISI Files ( .isi )
    NifTi ( .nii )
    RAW files ( .raw , .* )
    VMP BrainVoyager ( .vmp )
    XIF HDllab/ATL ultrasound ( .xif )
    VTK Visualization Toolkit ( .vtk )
    Insight Meta-Image ( .mha, .mhd )
    Micro CT ( .vff )

Note:
This version is 100% Matlab code, but to make it faster if you run "compile c-code" in the config menu. I also included an older version with the shearwarp algorithm in c-code / mex-code

Please report bugs, successes and if you know some possible code speedups.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (83)
27 Jun 2014 Larissa

I would like to know if it is possible to extract the volume data rendered without the matlab viewer (plot). Can anyone help me? Thanks.

20 Jun 2014 Christian  
14 May 2014 Smita

I am also getting the black screen with 2014a.

08 May 2014 Mohammad

Thank you for this easy-to-use tool. I keep getting the same black scree with MATLAB 2013a. Please let us know if someone figured out the problem.

Mohammad

08 Apr 2014 Shirin

This looks like a very good tool; however i keep getting a black screen!!

I get the GUI but have a black screen within it!!

I'm using Matlab version R2013a.

Can someone give me an idea of what might be wrong?

Thanks in advance

04 Nov 2013 JP

Hi Dirk,
very nice software.
Is it possible to change the background color ? Say, from black to white ?
How should it be referenced if used to generate images for a paper ?
JP

03 Oct 2013 Milton

This works very well for me. Thank you!

(the rating button does not seem to be working. I would give it a 5-star if I could)

24 Aug 2013 Kimberly Riley

This looks like a very neat tool however i keep getting a black screen. i've set my path to include all folders within the main folder viewer3d_version11. i've loaded the .mat file CommandlineData.mat. then just typed viewer3d(V) in the command line. i get the GUI but have a black screen within it. I'm using matlab version 2013a. can someone give me an idea of what might be wrong?
thanks

27 Jul 2013 Sebastian

This is very nice.

Some suggestions for future.
1.) Manually set view point. Maybe even output a movie.
2.) Manually set alpha/color. Dragging is very cumbersome.

27 Jul 2013 Sebastian  
28 Jan 2013 Ramiro Massol

hi Dirk
can your application render multi-coloured volumes (e.g. RGB)?
best

11 Jan 2013 ocelote

How do you keep the contrast in the 3D view ?

09 Jan 2013 Xixi  
01 Dec 2012 Roger

Great program;

I've added some mirror functionalities, so it automatically creates the mirror ROI.

Unfortunately, I can't compile it on a MAC, using llvm--twolevel_namespace -undefined error

07 Nov 2012 Silvio

Hi, thanks for this great piece of software. Is there a possibility to change the background color from black to white?

17 Oct 2012 fred sampedro

Beautiful piece of software :). How can I change the title of the figure? (I mean the 'viewer3d' on the top left of the OS window)

Thanks a lot!

11 Oct 2012 André Zeug

Dirk, please let us know how to set dataset parameters like voxel size for the render.m function. I would like to process my data in a script using your render.m function rather than your viewer3d GUI.

Thanks in advance!

29 Jun 2012 Yuri

How can I change the voxel sizes, window width, etc from my Matlab function rather than using the GUI every time again?

29 Jun 2012 Joy

Hi Dirk,

How does the example of function "[Mshear,Mwarp2D,c]=makeShearWarpMatrix(Mview,sizes)" in render.m works ???? Anyone knows ??? Please help me out here.... Thanks

25 Jun 2012 Joy

I'm still new with this matlab. i've an interpolated image that need to be projected out with MIP. But how do i go about doing this MIP ?? Or could you show me which part from your render.m is programming the MIP function??

Thanks in advance :D

20 Jun 2012 Yuri

I'm new to the dicom format. I have a directory of hundreds of CT slices of a wrist. How do I read all them into the tool to obtain a 3D image?

Thanks

30 May 2012 Murat Shagirov  
09 May 2012 Urs Utzinger

If Dirk-Jan has spare time I was hoping he could consider implementing commands to:
1) reset rotation to be North/South/East/West on top (or have a field where the rotation, translation and zoom can be entered by hand).
2) Option to apply rotation, zoom and translation performed in one widow to the other windows (linking view setting between windows)
3) Function to crop data cube by placing planes perpendicular to x/y/z
4) 3D cursor to probe intensity while also showing location.

09 May 2012 Urs Utzinger  
23 Jan 2012 Brian MacDonald

I am having trouble getting the voxel size function to work. When I increase the voxel size nothing happens. Any thoughts?

27 Nov 2011 leila

I want to visualize a 3D *.mat data with the "viewer3d",I first tried to visualize the "matlab mri image" by the following code, but nothing displayed!
>> load mri
>> D = squeeze(D);
>> viewer3d(D);

what's the problem? maybe there is an especial format for the *.mat files that I don't know, please help me.thanks.

23 Nov 2011 bahar cham  
13 Oct 2011 Johannes

oh got it ... I figured out to use render() (instead of viewer3d) with the corresponding arguments.

11 Oct 2011 Johannes

Great tool!
Is it possible to generate multiple TOF-frames (and save them) for a movie from the command line?
As far as I see, only the volume-data is specified as input parameter for viewer3d!?

20 Jul 2011 Layla

...problem solved! The issue is not the code, it's the fact that I don't have the Image Processing Toolbox installed. Oops.

20 Jul 2011 Layla

I'm trying to run this file on CentOS. I tried to simply run the GUI by typing "viewer3d" (no quotes) into the command window while in the correct directory. I get the following error messages:

??? Undefined function or method 'imshow' for input arguments of type 'uint8'.

Error in ==> menubar>CreatMenuBar at 181
data.menuitems(i).HandleImshow=imshow(barimage,'Parent',data.menuitems(i).Handle);

Error in ==> menubar>UpdateMenu at 353
CreatMenuBar(uimenuhandle,datahandle,Pos,figure_handle)

Error in ==> menubar at 83
UpdateMenu(datahandle,figure_handle);

Error in ==> viewer3d>addWindowsMenus at 3239
menubar

Error in ==> viewer3d>addWindows at 3098
data=addWindowsMenus(data);

Error in ==> viewer3d>viewer3d_OpeningFcn at 155
data=addWindows(data);

Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ==> viewer3d at 47
gui_mainfcn(gui_State, varargin{:});

I also tried working with some of the example data. I typed in the command that the help file suggests:

load('ExampleData\CommandlineData.mat');
viewer3d(V);

And I get more errors: ??? Error using ==> load
Unable to read file ExampleData\CommandlineData.mat: No such file or directory.

I'm very confused. I'm definitely working in the right directory. Any insight?

18 Jul 2011 WEI LIU

Terrific code. mha_read_volume can be slightly improved for reading 3-D deformation field (i.e., a vector field) by replacing line 80 to the code as follows:

if(~isfield(info,'ElementNumberOfChannels'))
V = reshape(V,info.Dimensions);
else
nchannel=str2double(info.ElementNumberOfChannels);
V = reshape(V, [nchannel info.Dimensions]);
end

23 May 2011 Wouter

File -> open medical 3d file.
Image File Name appears to contain a patient name in folder. Might want to remove that:
Other\P****s A****s 05***1603\201***9\1.2.826.0.1

07 May 2011 Al Ka

Is there a copyright disclaimer? Can it be used for research purposes?

06 May 2011 laleh  
29 Mar 2011 Norbert Gal

Hello....
When i try to render a set of slices of DICOM files i have the following error:

??? Operands to the || and && operators must be convertible to logical scalar values.

Error in ==> viewer3d>LevelRenderImage at 531
if
((ndims(renderimage)==2)&&(data.volumes(dvss).WindowWidth~=0||data.volumes(dvss).WindowLevel~=0))

Error in ==> viewer3d>show3d at 394
renderimage1=LevelRenderImage(data.subwindow(wsel).render_image(i).image,data,dvss,wsel);

Error in ==> viewer3d>menu_ChangeRender_Callback at 3057
show3d(false,true);

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> viewer3d at 47
gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uimenu Callback

Can you help mee?

17 Mar 2011 Ganesh

* I would like to convert *

17 Mar 2011 Ganesh

I would convert a .mat file into .mha file. Can I do this with Viewer3d and if so, how? Thanks

06 Mar 2011 Igor

Great tool..
25 Jan 2011 version implements some interesting new features , however it seems like there sre some bugs too :
1 - viewer3d.m line 2203:
data=makeVolumeXY(data);
i've changed it to:
data=makeVolumeXY(data,dvs);
since i've got an error after

viewer3d(uint8(my_data));
volume - 1
renderer - MIP
config->quatily vs speed -> Store volume for all 3 major directions (ON)->Apply

??? Input argument "dvs" is undefined.

Error in ==> viewer3d>makeVolumeXY at 2227
data.volumes(dvs).volumex=shiftdim(data.volumes(dvs).volume,1);

Error in ==> viewer3d>qualityspeed_pushbutton_applyconfig_Callback at 2203
data=makeVolumeXY(data);
<.........>

2- if any of 2 checkboxes in config GUI was enabled and saved with 'Save as default', later >>viewer3d(uint8(my_data));
leed to
??? Reference to non-existent field 'volume'.

Error in ==> viewer3d>computeNormals at 2237
[fy,fx,fz]=gradient(imgaussian(double(data.volumes(dvs).volume),1/2));

Error in ==> viewer3d>addOneVolume at 216
data=computeNormals(data,nv);

Error in ==> viewer3d>addVolume at 183
data=addOneVolume(data,V(:,:,:,i),Scales,Info,Editable);

Error in ==> viewer3d>viewer3d_OpeningFcn at 170
if(isnumeric(V)), addVolume(V,[1 1 1],info); end

And.... it would be nice to have ability to specify Renderer and volume selection in a function call....Those routine actions can be quite booring...

22 Feb 2011 Dirk-Jan Kroon

*Haseeb
If you have your Volume in a Matlab command prompt.
Calculate an inverse of your data for example:
V = max(V(:))-V;
Now the lungs and the background have an high intensity.
To give the background a low intensity, you can use something like:
[L,n]=bwlabeln(V>max(V(:))*0.9);
s=zeros(1,n);
for i=1:n, s(i)=sum(L(:)==i); end;
[t,i]=max(s);
V(L==i)=0;

22 Feb 2011 Haseeb

Using a different data set, I was able to view the 3d reconstruction of the dicom data so problem solved. Does anyone know how I could focus on just the 3d reconstruction of the lungs from a CT scan? Though I get a 3D reconstruction, all I can visualize is the bone structure (rib cage, spine etc) around the lungs. Does anyone know how I could get around this problem?
Thanks,
Haseeb

11 Feb 2011 Haseeb

I have also used a .mat file
volume_image: [512x512x367 double]
I am still getting an error in this case,

??? Undefined function or method 'max' for input arguments of type 'struct'.

Error in ==> viewer3d>viewer3d_OpeningFcn at 165
volumemax=double(max(V(:))); volumemin=double(min(V(:)));

Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ==> viewer3d at 47
gui_mainfcn(gui_State, varargin{:});

What does this mean and how can I fix this? Perhaps my method of making a .mat file is wrong. I used the dicom23D function developed by Ariel Balter. Is there any other way of making a .mat file from Dicom files that I could use?
Haseeb

11 Feb 2011 Haseeb

I found out where the online help is, so problem solved there.

11 Feb 2011 Haseeb

Hi Dirk,
I have a CT dicom data. The files though have no extension name to them. How can I use this code to 3D render and view the data? You mention you have put an extended online html help online. How can I access this?
Thanks in advance

08 Feb 2011 chris

Working well with a few sample datasets. It would be great to have this work as an MPR slice viewer and measurement tool, with centering and rotation handles on each orthogonal plane. Seems it is only possible to view and measure from the cardinal axes, correct?

25 Jan 2011 Dirk-Jan Kroon

*Kai Steppenwolf
You can change the Pixel scaling in one of the sub-menus of "Volume 1".

Please note, that a major improved version (11), will be available tonight, or 26 Jan 2011.

25 Jan 2011 Kai Steppenwolf

glad to see the new version, great job! But it seems to have voxel size mistake errors when I read some MRI-Dicom-data. The 3D-view looks so flat, just like a 2D-picture. In the early version (8) I can use the voxel size option in the menu to define the right size, but this time the option seems to disappear in the newest version...

20 Jan 2011 Justin Fernandes

Great Job. I've been looking for something like this for a while. Hope I will be able to program like this in matlab some day. Many thanks.

25 Dec 2010 canfei

I are working in matlab2009a. And the files can work at first. But report some errors such as "??? Undefined function or method 'viewer3d' for input arguments of type 'int16'." , soon! And It is ame as to use "double" or "single" type, and so on. Why do this happen? I am too eger to solve this problem. Thank you!

17 Dec 2010 Dave Welch  
10 Nov 2010 Yuanming Suo

It works just great right now. Thanks for the hard work.

10 Nov 2010 Dirk-Jan Kroon

*Yuanming Suo , *Xinghua Lou
The newest version 9, has a whole new c-coded file

05 Nov 2010 Yuanming Suo

It works great on Linux. But still Dirk, could you kindly see how can we get around the bug in Windows? This is really a cool tool. If this bug is fixed, it will be even better. I tried to use Visual Studio as the compiler, Matlab still crashes......

27 Oct 2010 Dirk-Jan Kroon

*Xinghua Lou,

Thanks for your comment. I think the crash is caused by the (free) lcc-compiler of Matlab, If you install the Visual Studio (express) version it will probably work fine.

21 Oct 2010 Xinghua Lou

This is no question a wonderful tool for visualization in Matlab.

One bug I found: Matlab crashes after compiling the c mex files. My Matlab version is r2009a, os is Win XP.

22 Sep 2010 Tan

Hi Dirk,

Can you add a few quick demos based on the test data and test volume.

thanks

David

05 Sep 2010 Zubin Master

Hey Dirk,

This is a great tool. I've actually been struggling to find some code to visualize CT/MRI data from different angles as MIPs. I could only manage it from the orthogonal angles (couldn't figure out what algorithm to use for rendering from arbitrary angles). This implements it really well.

I was wondering what algorithm would be needed to render the MIP with perspective instead of an orthographic projection. We use these MIP images (Digitally Reconstructed Radiographs or DRRs) when planning radiation therapy treatments and they're usually displayed with perspective to simulate the distance between the radiation source and the patient.

Another poster also mentioned something about simulating DRRs. I was wondering if you could guide me to the algorithm
that I would need to look up to do this.

Thanks,

Zubin.

Another poster mentioned something about rendering your views as DRRs.

30 Aug 2010 Dirk-Jan Kroon

*Kai Steppenwolf

If you select one dicom file from a dataset with a lot of files representing a 3D volume, then the program will automatically load also all other files to build the 3D volume.

Best Regards, Dirk-Jan Kroon

29 Aug 2010 Kai Steppenwolf

Hi Dirk-Jan,

Just found your fantastic Viewer3D.

I have a series of DICOM files, which contain MR slices images of the brain. But the 'open medical 3D files' option can import only one dicom file every time.

Then I tried to read 3D data in to a Mathlab variable V, but the command VIEWER3D(V, RENDERTYPE, SCALES) works still incorrect。

Could you tell me, how can man handle a series of slices dicom image by using your Viewer3d?

Thanks,
Kai

06 Aug 2010 Andrew Brennan

Hi Dirk-Jan,
Looking at the code it doesn't appear to support pseudo coloured
bitmaps without first running rgb2grayscale() first. Then the act of applying pseudocolouring again on the 3d volume doesn't appear to work successfully. Is this feature available?
Thanks,
Andrew

23 Jul 2010 Dirk-Jan Kroon

*Jackson Shen

Thanks for your comment, I will have a look at malloc and mxMalloc ...

23 Jul 2010 Jackson Shen

Great Job, Again!

However,
1. Multi-threading is not working properly in my computer. Matlab is frozen. (Matlab 2008b or above, XP 32bit, Intel Core2 Quad with 2GB memory)
2. Memory leaking...

Using malloc and free causes memory leaking in Matlab. You must use mxMalloc and mxFree instead.

Type "feature memstats" in matlab to monitor the memory.

Looking forwards to see your next version.

Cheers,

Jian-Kun Shen

13 Jul 2010 chandrakala Gowda  
01 Jul 2010 Dirk-Jan Kroon

* oscar SanEmeterioNateras
First you have to load your data in to a Matlab variable V, the functions needed to load your medical format can be found on Mathworks.

30 Jun 2010 oscar SanEmeterioNateras

Hello Dirk,

I want to use your code to open a nii file of and MRA img that I have so I can do the MIP.
I tried to use the command:
VIEWER3D(V, 'MIP', [0.156, 0.29, 0.156]);
to open and run viewer but i am not sure what I should put for the 'V' input.
Can you give me and example or a suggestion on how to work on this thanks a lot.
~Oscar

02 Jun 2010 Dirk-Jan Kroon

* wang ning
If you only sea a blackbox enable auto contrast, because then your values are probably not ranged between 0 and 2^16-1

13 Apr 2010 wang ning

hi Dirk-Jan Kroon

my volume data is 512*512*272 uint16 why files don't work ?

ning thanks

16 Mar 2010 Pascal

Dirk,

Solid work!

The RENDER_MIP -- updatebuffer function-- can be modified to create a DRR of the volume. What's your take on it.

16 Mar 2010 Hans Müller

Wonderful! I wish I had found this 6 months ago!

21 Oct 2009 ted p teng

excellent work. thanks for sharing!

30 Sep 2009 Aaron Schurger

Outstanding! Sometimes has an error when I switch to a different rendering mode. Thanks for this application.

10 Sep 2009 Siyi Deng

awesome!

22 Jul 2009 Dirk-Jan Kroon

*Wenyuan
It runs on most Matlab versions, but not on the very old ones because Matlab figure file format changed in time, and saving to an older figure-file-format doesn't work that well.

21 Jul 2009 Wenyuan

Must it be run in the matlab 7.8 version? My matlab version is 7.0, will it be OK? I can't even run the sample: load TestVolume;viewer3d(V). Is it because of the lower matlab version?? Thanks..

15 Jul 2009 jichao zhao

it is very cool staffs. many thanks

16 Apr 2009 Shi vera

Fantastic

01 Dec 2008 Dirk-Jan Kroon

*Cris Luengo
Thanks for your Feedback, I will use it in my nex file update.
(non-isotropically display, can done by viewer3d(Image, [2 1 1]) with [2 1 1] the scaling)

01 Dec 2008 Cris Luengo

Very nice! But it's not very fast. I will try the old MEX-file code next, to see if that speeds it up or not. I tried it with an image 1000x500x250 pixels and found the rendering took 30 s or more.

Some suggestions:

- Don't update the display every time a node is moved in the alpha colors window. Instead, have a button "preview" to update the rendered image.

- Add checkmarks next to the menu items of the activated modes (render and config menus).

- Add an option to enter pixel spacing for non-isotropically sampled images (common in 3D imaging)

- Put the support M-files either within the main M-file or into a private/ subdirectory. That would make it easier to get started...

Great tool! Thanks!

05 Nov 2008 Dirk-Jan Kroon

Tommorow (06-2008) a version with extended HTML help will be online

* Jean-Yves Tinevez
The TestVolume.mat example:
load TestVolume;
viewer3d(V);

05 Nov 2008 Jean-Yves Tinevez

Tested successfully on MacOSX-Tiger, MATLAB 2008b & a.

Worked absolutely fine with matrices entered from command line (e.g. viewer3d(I)).

I had plenty of errors when trying to load a .mat file (e.g. the 2 ones given in demo), and putting tyhe mouse over the window. Here is the 1st one

??? Reference to non-existent field 'histogram_positions'.

Error in ==> viewer3d>createAlphaColorTable at 154
if (i<data.histogram_positions(1)), alpha=0; color=data.histogram_colors(1,:);

Error in ==> viewer3d>menu_load_view_Callback at 542
createAlphaColorTable();

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> viewer3d at 50
gui_mainfcn(gui_State, varargin{:});

Error in ==>
guidemfile>@(hObject,eventdata)viewer3d('menu_load_view_Callback',hObject,eventdata,guidata(hObject))

04 Nov 2008 Dirk-Jan Kroon

*Joaquim
Load View only works with Matlab files created by Save View. Some help can be found in menu -> help, and with help function.m in the console window.

04 Nov 2008 Joaquim Luis

OK
Sorry, I found a little help on the function's help section.

04 Nov 2008 Joaquim Luis

Dirk,
There is absolutely no help on how to use this. When I try to "Load view" than an endless number of errors occur.

Updates
05 Nov 2008

Extended the help (with pictures) and updated error check

06 Nov 2008

fixed small dimension bug in major viewing axis. And files to folders

22 Nov 2008

Now 100% Matlab code, no mex files needed. Also warp 2D interpolation bug and save/load bug fixed.

26 Feb 2009

Configuration screen, with trade off between quality, memory and speed. Implemented most suggestions by Cris Luengo. Some small bug fixes and optimizations.

03 Apr 2009

Slice rendering and measurements, multi-threaded image warp code, bugs fixed.

28 Jul 2009

Removed unnecessary code from mouse position read out. Maybe this fixed the mouse position out of sync bug, which occurred sometimes.

01 Oct 2009

Linux Ubuntu tested

02 Jun 2010

Now "Autocontrast" is automatically enabled if someone uses uint16 and the data uses only a part of the rang 0 to 2^16-1

07 Jun 2010

Now read single Dicom files containing a whole 3D/4D volume.
Fixed bug dividing by zero with empty slice in auto contrast.
Added option to click landmarks, and made keyboard shortcuts for measure options.

07 Jun 2010

Bug in "Load View" solved

18 Jun 2010

Solved major bugs in Dicom volume reading

25 Jun 2010

Added Dicom Info dialog.
Solved possible bugs when loading multiple files, without closing viewer3d.
Added Intensity Value to mouse slice info

25 Jun 2010

Fixed Dicom Sorting problem

06 Jul 2010

Sorted files into sub-folders, now can read many medical-formats with ReadData3D

06 Jul 2010

Fixed folder location compile_c_files, changed text in code from dicom to data3d

22 Jul 2010

Updated File-formats

10 Nov 2010

Replaced the c-code Affine Warp files. Now scaling is not longer always 0..1 but supports scales and units like Hounsfield

19 Nov 2010

Fixed Bug number of input arguments slice view, and fixed bug in window-level slider

12 Jan 2011

Major update : Added multiple window and multiple volume support.

25 Jan 2011

Added 4D support, color overlay and many other changes.

Contact us