5.0

5.0 | 1 rating Rate this file 18 Downloads (last 30 days) File Size: 2.47 KB File ID: #28210
image thumbnail

ind2patch

by Kevin Moerman

 

15 Jul 2010

Allows plotting of patch data (slices and voxels) for 3D images for selected voxels

| Watch this File

File Information
Description

This function generates patch data (faces “F”, vertices “V” and color data “C”) for 3D images. The patches are only generated for the voxels specified by the linear indices in “IND”. The variable “ptype” indicates
the type of patch:

‘v’ Voxel (box)
‘sx’, ‘sy’, ‘sz’ Mid-voxel slice for x, y and z direction respectively
%% EXAMPLE
clear all; close all; clc;

%% Simulating 3D image
[X,Y,Z]=meshgrid(linspace(-4.77,4.77,75));
phi=(1+sqrt(5))/2;
M=2 - (cos(X + phi*Y) + cos(X - phi*Y) + cos(Y + phi*Z) + cos(Y - phi*Z) + cos(Z - phi*X) + cos(Z + phi*X));
M=M./max(M(:)); %Normalise, not required

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]);
hold on; xlabel('X-J','FontSize',20);ylabel('Y-I','FontSize',20);zlabel('Z-K','FontSize',20);

%% Creating and plotting patch data

%Setting up indices for slices to plot
S=round(size(M,2)./2);
L_slices=false(size(M));
L_slices(:,S,:)=1;
IND_slices=find(L_slices);
[Fs,Vs,C_slice]=ind2patch(IND_slices,M,'sx'); %Creating patch data for x mid-voxel slices
hs=patch('Faces',Fs,'Vertices',Vs,'EdgeColor','none', 'CData',C_slice,'FaceColor','flat','FaceAlpha',0.75);

%Setting up indices for slices to plot
S=round(size(M,1)./2);
L_slices=false(size(M));
L_slices(S,:,:)=1;
IND_slices=find(L_slices);
[Fs,Vs,C_slice]=ind2patch(IND_slices,M,'sy'); %Creating patch data for y mid-voxel slices
hs=patch('Faces',Fs,'Vertices',Vs,'EdgeColor','none', 'CData',C_slice,'FaceColor','flat','FaceAlpha',0.75);

%Setting up indices for slices to plot
S=round(size(M,3)./2);
L_slices=false(size(M));
L_slices(:,:,S)=1;
IND_slices=find(L_slices);
[Fs,Vs,C_slice]=ind2patch(IND_slices,M,'sz'); %Creating patch data for z mid-voxel slices
hs=patch('Faces',Fs,'Vertices',Vs,'EdgeColor','none', 'CData',C_slice,'FaceColor','flat','FaceAlpha',0.75);

%Setting up indices for voxels to plot
IND=find(M>-0.2 & M<=0);
[Fs,Vs,C_slice]=ind2patch(IND,M,'v'); %Creating patch data for selection of low voxels
hs=patch('Faces',Fs,'Vertices',Vs,'EdgeColor','k', 'CData',C_slice,'FaceColor','flat','FaceAlpha',1);

%Setting up indices for voxels to plot
IND=find(M>0.9);
[Fs,Vs,C_slice]=ind2patch(IND,M,'v'); %Creating patch data for selection of high voxels
hs=patch('Faces',Fs,'Vertices',Vs,'EdgeColor','k', 'CData',C_slice,'FaceColor','flat','FaceAlpha',1);

axis equal; view(3); axis tight; colormap jet; colorbar; caxis([0 1]); grid on;
set(gca,'FontSize',20);

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
image3Ddata

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 (1)
31 Jul 2010 Yomismo

Awesome.

I´ll use this for wave propagation models. Very easy to use code.

Thank you.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
image Kevin Moerman 15 Jul 2010 11:42:20
patch Kevin Moerman 15 Jul 2010 11:42:20
3d Kevin Moerman 15 Jul 2010 11:42:20
voxels Kevin Moerman 15 Jul 2010 11:42:20
voxel Kevin Moerman 15 Jul 2010 11:42:20
slice Kevin Moerman 15 Jul 2010 11:42:20
slices Kevin Moerman 15 Jul 2010 11:42:20
volume Kevin Moerman 15 Jul 2010 11:42:20
image processing Kevin Moerman 15 Jul 2010 11:42:20
medical Kevin Moerman 15 Jul 2010 11:42:20
data exploration Kevin Moerman 15 Jul 2010 11:42:20
visualisation Kevin Moerman 15 Jul 2010 11:42:20

Contact us at files@mathworks.com