フィルターのクリア

Trying to add color gradient to patch(isosurface))

17 ビュー (過去 30 日間)
Simon Penninag
Simon Penninag 2021 年 3 月 1 日
コメント済み: Simon Penninag 2021 年 3 月 2 日
Hi all,
im currently trying to visualize a pressure field in a 3D voxel field of a 32x32x32 image.
The way this currently works is through using patch(isosurface()) as is shown in the code below.
image = rand(32,32,32);
filtered = imgaussfilt3(image,2.5);
BW = imbinarize(filtered,0.517);
patch(isosurface(BW),'FaceColor','white','EdgeColor','black')
The image above is what it produces.
What it does is plot the contour of the 1's and leave empty the 0's but I want it to do something else. The 1 values are going to be replaced by pressure field values (1 to 33) and I want the white+black contour to change into a color gradient. So far I couldnt get any colormap to do this. Is this even possible?

採用された回答

darova
darova 2021 年 3 月 2 日
Here is an example (not tested)
% BW - is your 01 3d matrix
% A - is your color value matrix (0-33)
cm = jet(33); % colormap
fv = isosurface(BW,0.9);
fv.facevertexcdata = cm(A(:),:); % get color according to 0-33
patch(fv,'facecolor','interp')
  3 件のコメント
darova
darova 2021 年 3 月 2 日
Everything is ok. I understood correctly. Here are corrections
% BW - is your 01 3d matrix
% A - is your color value matrix (0-33)
cm = jet(34); % colormap
fv = isosurface(BW,0.9); % extract patch data
[m,n,k] = size(A);
[x,y,z] = meshgrid(1:m,1:n,1:k); % mesh
v1 = fv.vertices;
A1 = griddata(x,y,z,A,v1(:,1),v1(:,2),v1(:,3)); % interpolate A data (0-33) for x y z position
ind = 1 + round(A1); % indices
fv.facevertexcdata = cm(ind,:); % get color according to 1-34
patch(fv,'facecolor','interp')
Simon Penninag
Simon Penninag 2021 年 3 月 2 日
It works like a charm! Thanks!

サインインしてコメントする。

その他の回答 (1 件)

ANKUR KUMAR
ANKUR KUMAR 2021 年 3 月 1 日
Not sure about the exact what you wish to plot. But you can give it a try to plot using imagesc, use the gray colormap to plot.
imagesc(nanmean(filtered,3)
colorbar
colormap(gray)
  1 件のコメント
Simon Penninag
Simon Penninag 2021 年 3 月 1 日
I'm trying to reproduce the contour shown in the original post. It's a 3D image of the voxels that have the value '1' as oppossed to the value '0'. This '1' is going to become a value between 0 and 33 and needs a corresponding colour gradient.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeScalar Volume Data についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by