3D image production

14 vues (au cours des 30 derniers jours)
Brittney Gorman
Brittney Gorman le 30 Oct 2020
Réponse apportée : Tim le 30 Oct 2020
I want to create a 3D map similar to the one below that includes the enclosing box is that possible with volshow? Is there other 3D plotting commands that could accomplish this? I have been able to plot the image and box as 1 3D data set; however, the 3D image in the middle needs to be semi-transparent and the box begins to disappear when I apply the transparency:
% Random 3D data
Data = bsxfun(@power, rand(512, 512, 610),...
permute(linspace(0, 8, 610), [3, 1, 2])).*...
permute(linspace(1, 0, 610), [3, 1, 2]);
[x, y, z] = size(Data);
%Create a box with edges 7 pixels thick
imbox= ones(x+100,y+100,z+100)*20;
imbox(8:x+100-8,:,8:z+100-8)=0;
imbox(:,8:y+100-8,8:z+100-8)=0;
imbox(8:x+100-8,8:y+100-8,:)=0;
imcube = imbox;
imcube(50:x+49,50:y+49,50:z+49)= Data;
Colormap = jet;
Alpha = linspace(0,.5,256)';
Bground = [0 0 0];
scale=[2 2 1];
v = volshow(imcube,'Colormap',Colormap,'Lighting',false,'Alphamap',Alpha,'BackgroundColor',Bground,'ScaleFactors',scale);

Réponses (1)

Tim
Tim le 30 Oct 2020
Hello Brittany,
Volshow images are not standard axes and it does not appear that you can combine then with ordinary line or patch objects to add your own bounding box. Editing the volume to add a bounding box seems like a reasonable alternative. When I run your code I get the following:
The data disappears because of a scaling issue: the bounding box amplitude is 20, but the data maximum is 1, forcing the background to disappear since they map to low alpha levels when scaled. If you modify:
imbox= ones(x+100,y+100,z+100)*20
to something like:
imbox= ones(x+100,y+100,z+100)*(max(Data(:)) + min(Data(:)))/2;
Then it doesn't cause this scaling issue, and you get the following image:
If you want a simple-to-use patch based volume renderer that allows you to add your own lines, patches, etc., you can try VOXview from the file exchange, but it will totally crash out at the size & pixel density in your example. If you downsample though you can get some decent results and bound the box by setting the 'bounding_box' parameter to true, e.g.:
szz = [64, 64, 82];
Data = bsxfun(@power, rand(szz(1), szz(2), szz(3)),...
permute(linspace(0, 8, szz(3)), [3, 1, 2])).*...
permute(linspace(1, 0, szz(3)), [3, 1, 2]);
VOXview(Data, 'colormap', jet, 'bounding_box', true);
This gives:
And if you read the help for the function it is easy to modify & scale the axes to make the image dimensionally correct. I see I forgot to add your alpha map but that is also simple to add as a second argument to the input.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by