Using volshow with AlphaData for an RGB volume
10 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Narvik
2024-3-22
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!