Filter löschen
Filter löschen

Using volshow with AlphaData for an RGB volume

13 Ansichten (letzte 30 Tage)
Imaging3D
Imaging3D am 14 Mär. 2024
Bearbeitet: Imaging3D am 22 Mär. 2024
I'm using volshow to render two 3D volumes with one (V2) enclosing the other (V1).
V1 and V2 are 3D binary masks with the value of 1 inside the volumes and 0 everywhere else.
The RGB volume (V) is defined as follows.
V = zeros([size(V1) 3]);
V(:,:,:,2) = V1;
V(:,:,:,1) = V2;
Using volshow, I get the following picture, which is expected.
However, when I used the following AlphaData to render the outer volume (V2) to be transparent, the color is almost lost.
Adata = zeros(size(V1));
Adata(V2>0.5) = 0.5;
Adata(V1>0.5) = 0;
I tried a different setting for AlphaData as follows.
Adata = ones(size(V1));
Adata(V2>0.5) = 0.5;
Adata(V1>0.5) = 0;
However, the result is worse.
Has anyone had a similar problem?

Akzeptierte Antwort

Narvik
Narvik am 22 Mär. 2024
Hi,
As per my understanding, you are trying to render two 3D volumes with outer volume (V2) to be transparent using "volshow" function and facing issues related to blurring.
The following code uses 'AlphaData' property of the "volshow" function to render a transparent outer volume.
% dimensions of the volume
dim = 100;
[x, y, z] = ndgrid(1:dim, 1:dim, 1:dim);
% centers for V1 and V2
center = [dim/2, dim/2, dim/2];
% radii for V1 and V2
radiusV1 = 20;
radiusV2 = 40;
% binary masks for V1 and V2
V1 = sqrt((x - center(1)).^2 + (y - center(2)).^2 + (z - center(3)).^2) <= radiusV1;
V2 = sqrt((x - center(1)).^2 + (y - center(2)).^2 + (z - center(3)).^2) <= radiusV2;
% ensure V1 is fully contained within V2 by combining the masks correctly
V2 = V2 & ~V1;
% create an RGB volume
V = zeros([size(V1), 3]);
% assign V1 to the green channel and V2 to the blue channel
V(:,:,:,2) = V1; % green channel for V1
V(:,:,:,3) = V2; % blue channel for V2
% initialize AlphaData with full transparency
Adata = zeros(size(V1));
% make V2 semi-transparent, but only where V1 is not present
Adata(V2 > 0 & V1 == 0) = 0.01;
% ensure V1 remains fully opaque
Adata(V1 > 0) = 1;
% Display the volume with volshow
h = volshow(V);
viewer = h.Parent;
viewer.BackgroundColor="white";
viewer.BackgroundGradient="off";
% set alpha data
h.AlphaData = Adata;
Output :
Note : The above code was run on R2024a.
For viewing edges of the volume with some transparency, the 'RenderingStyle' property (specifically, 'GradientOpacity' rendering style) seems to be more relevant. Refer to the following documentation links for more information:
The modified code using 'RenderingStyle' property is as follows :
% dimensions of the volume
dim = 100;
[x, y, z] = ndgrid(1:dim, 1:dim, 1:dim);
% centers for V1 and V2
center = [dim/2, dim/2, dim/2];
% radii for V1 and V2
radiusV1 = 20;
radiusV2 = 40;
% binary masks for V1 and V2
V1 = sqrt((x - center(1)).^2 + (y - center(2)).^2 + (z - center(3)).^2) <= radiusV1;
V2 = sqrt((x - center(1)).^2 + (y - center(2)).^2 + (z - center(3)).^2) <= radiusV2;
% ensure V1 is fully contained within V2 by combining the masks correctly
V2 = V2 & ~V1;
% create an RGB volume
V = zeros([size(V1), 3]);
% assign V1 to the green channel and V2 to the blue channel
V(:,:,:,2) = V1; % green channel for V1
V(:,:,:,3) = V2; % blue channel for V2
% display the volume with volshow
h = volshow(V);
viewer = h.Parent;
viewer.BackgroundColor="white";
viewer.BackgroundGradient="off";
% set rendering style
h.RenderingStyle = "GradientOpacity";
Output:
Hope this helps!
  1 Kommentar
Imaging3D
Imaging3D am 22 Mär. 2024
Bearbeitet: Imaging3D am 22 Mär. 2024
Thank you so much for the clear explanation and extremely helpful examples!
The MATLAB version also appears to be involved. I used to use 2023a, which produced the same problem as what I had posted. It works perfectly with 2023b and 2024a.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by