Display 3D volumes with different colours in the surface

10 views (last 30 days)
Dear all,
I'm working with brain MRI images and as a result I obtain statistical maps (values between 0 and 25) which I would like to represent in 3D with a colormap. I have x, y and z coordinates, and stat(the statistical value which I want to represent in color). I used a nice function called PATCH_3Darray, calling patch for each voxel, and I obtained this image:
I would like to smooth the voxels, so they do not seem bricks and don't have corner-edges. How could I smooth all if there are individual patches?
I was considering binarizing my statistical image, get connected voxels, create an isosurface like: BW=statistical_image>0; CC = bwconncomp(BW); L = labelmatrix(CC); color=hsv(15);
for i=1:1:numel(unique(L)) A=(L==i); e = patch(isosurface(A,0.5), ... 'FaceColor', color(i,:), 'EdgeColor', 'none'); hold on end
and somehow get in the surface/"face" of each object the real values in the matrix statistical_image (as in the first image), colored with a colormap. How could I do it? Please, could you help me with code?
Thank you very much, All the best,
Úrsula

Accepted Answer

UrsulaPR
UrsulaPR on 6 Dec 2016
Hi,
I solved the problem using isosurface and a nice function,"smooth triangulated mesh" https://es.mathworks.com/matlabcentral/fileexchange/26710-smooth-triangulated-mesh:
% dims: image dimensions
axx=1:dims(1); ayy=1:dims(2); azz=1:dims(3); [xgrid,ygrid,zgrid] = meshgrid(axx, ayy, azz);
%statistical_image
%binary_statistical_image: assuming only positive values, put 1s where %statistical_image > 0
[faces,verts,colors] = isosurface(xgrid,ygrid,zgrid,binary_statistical_image,0.99999,statistical_image,'','verbose');
addpath('smoothpatch_version1b') mex smoothpatch_version1b\smoothpatch_curvature_double.c -v
mex smoothpatch_version1b\smoothpatch_inversedistance_double.c -v
mex smoothpatch_version1b\vertex_neighbours_double.c -v
FV.vertices=verts; FV.faces=faces; FV_smoothed=smoothpatch(FV,1,5); hpatch=patch(FV_smoothed, ... 'FaceVertexCData', colors, ... 'FaceColor','interp', ... 'edgecolor', 'interp');
Hope this helps,
All the best, Úrsula

More Answers (3)

KSSV
KSSV on 30 Nov 2016
Edited: KSSV on 30 Nov 2016
Try/type shading interp after plotting the figure.

UrsulaPR
UrsulaPR on 30 Nov 2016
Edited: UrsulaPR on 30 Nov 2016
Thank you KSSV,
I already tried shading interp but I get "Warning: Color Data is not set for Interpolated shading# multiple times.
The input to patch3D_array is a matrix with NaN in nonsignificant voxels, and the statistical value in the significant voxels. The call is [hpat,hcbar] = PATCH_3Darray(statistical_map,cmap,'col').
Inside patch3D_array (downloaded from Matlab Central), there is a handle for each patch hpat{loopJ} = patch(xco,yco,zco,cmap(loopJ,:));
Would you suggest a different way to represent my data, instead of PATCH3D_array?
Thank you very much,
Úrsula

UrsulaPR
UrsulaPR on 4 Dec 2016
Dear all,
I tried with isocolors and even though I didn't get what I expected, hopefully I'm improving. The code I tried is:
% 'activation' is the statistical volume, with values between 0 and 30. % 'dims' are the dimensions of the image. % Get a binary version, for isosurface:
activation_binary=zeros(size(activation)); activation_binary(activation>0)=1;
% Isosurface of all the activation clusters
[x,y,z] = meshgrid(1:dims(1),1:dims(2),1:dims(3)); p = patch(isosurface(smooth3(activation,'gaussian',[3 3 3]'),0.5));
% Isonormals and isocolors, trying to put the "activation" statistical values as a color
isonormals(x,y,z,activation,p) isocolors(x,y,z,activation,p) set(p, 'FaceColor', 'interp'); set(p, 'EdgeColor', 'none'); alpha(p,1)
% Custom color map yellow-orange-red
RGB_yellow=[255,255,0]; RGB_orange=[255,123,0]; RGB_red=[255,0,0]; T=vertcat(RGB_yellow,RGB_orange,RGB_red)./255; % %T = [255,255,0;255,123,0;255,0,0]./255; max_number=numel(unique(activation)); x = [0, max_number/2, max_number]; cmap = interp1(x/max_number,T,linspace(0,1,max_number));
% Color the surface
colormap(cmap);colorbar axis vis3d tight
The figure is:
I visualize a volume with different colors in the surface, but not the correct colors, they should be from a bit above 0 to 30. Please, do you have any suggestions?
Thank you very much and sorry for the long email.
All the best,
Ursula

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!