Code covered by the BSD License  

Highlights from
image3Ddata

5.0

5.0 | 2 ratings Rate this file 17 Downloads (last 30 days) File Size: 2.22 KB File ID: #24081
image thumbnail

image3Ddata

by Kevin Moerman

 

11 May 2009

Creates coordinate/colour data for 3D image visualisation

| Watch this File

File Information
Description

This simple function creates a structure array containing coordinate and colour data for 3D images. The example below shows how the function allows one to use the patch function to plot the whole image or a selection of voxels in 3D. The CData is generated using the voxel intensities.

N.B. The function has not been optimised for large images. Large images (function has been tested for images under 100x100x100) may produce memory problems.

%% EXAMPLE
M=rand(15,15,15);
[IMAGE_3D_DATA]=image3Ddata(M);

%Getting faces and vertices for full image
voxel_no=1:1:numel(M);
voxel_face_no=IMAGE_3D_DATA.voxel_patch_face_numbers(voxel_no,:);
M_faces=IMAGE_3D_DATA.voxel_patch_faces(voxel_face_no,:);
M_vertices=IMAGE_3D_DATA.corner_coordinates_columns_XYZ;

%Getting faces and vertices for selection of voxels
voxel_no2=M>0.95;
voxel_face_no2=IMAGE_3D_DATA.voxel_patch_face_numbers(voxel_no2,:);
M_faces2=IMAGE_3D_DATA.voxel_patch_faces(voxel_face_no2,:);
M_vertices2=IMAGE_3D_DATA.corner_coordinates_columns_XYZ;

figure;fig=gcf; clf(fig); colordef (fig, 'white'); units=get(fig,'units'); set(fig,'units','normalized','outerposition',[0 0 1 1]); set(fig,'units',units);
set(fig,'Color',[1 1 1]);

subplot(1,2,1);
hp=patch('Faces',M_faces,'Vertices',M_vertices,'EdgeColor','black', 'CData',IMAGE_3D_DATA.voxel_patch_CData(voxel_face_no,:),'FaceColor','flat');
hold on; view(45,30); axis equal; axis tight; colormap jet; colorbar; caxis([0 1]);
xlabel('J'); ylabel('I'); zlabel('K');
title('Full image');

subplot(1,2,2);
hp2=patch('Faces',M_faces2,'Vertices',M_vertices2,'EdgeColor','black', 'CData',IMAGE_3D_DATA.voxel_patch_CData(voxel_face_no2,:),'FaceColor','flat');
hold on; view(45,30); axis equal; axis tight; colormap jet; colorbar; caxis([0 1]); grid on;
set(hp2,'FaceAlpha',0.8);
xlabel('J'); ylabel('I'); zlabel('K');
title('Selection of voxels');

Acknowledgements
This submission has inspired the following:
ind2patch
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
12 May 2009 zhijian liu

Cool!I need it。

26 Feb 2010 B Treeby

Very useful piece of code. Do you have any suggestions on saving the resulting images - saving as an eps file seems to result in a raster style image.

19 Jun 2011 Kevin Moerman

The function ind2patch can be used equivalently to this code but is more versatile and memory efficient.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
3d image visualisation Kevin Moerman 11 May 2009 13:21:33
image plotting Kevin Moerman 11 May 2009 13:21:33
patch Kevin Moerman 11 May 2009 13:21:33
voxel plot Kevin Moerman 11 May 2009 13:21:33
3d image visualisation zhijian liu 12 May 2009 06:02:28

Contact us at files@mathworks.com