TransWikia.com

Can Image3D be setup to make any voxel with an RGB element >1 or <0 black, or better yet clear?

Mathematica Asked on August 7, 2021

I’m working with ~ 10^8 voxels which can have RGB values outside of 0 – 1. Currently I go through nested For statements with a bunch of || tests. It would be great to set such voxels to {0,0,0} within Image3D. Better yet would be to turn the voxel transparent.

Here is a small example that obviously doesn’t use all possible combinations of out of range elements:

test = {{{1.5, 1, 1}, {-1.5, 0, 0}, {1.5, 0, 0}, {-1.5, 0, 0}}, {{1.5,
      1, 1}, {-1.5, 0, 0}, {1.5, 0, 0}, {-1.5, 0, 0}}};

Image3D[test]

One Answer

R,G,B values should be between 0 and 1. MMA will simply clip you values. E.g, the first voxel {1.5,1,1} will be clipped to {1,1,1} and therefore displayed as "white", what makes it invisible on a white background.

test = {{{{1.5, 1, 1}, {-1.5, 0, 0}, {1.5, 0, 0}, {-1.5, 0, 
      0}}, {{1.5, 1, 1}, {-1.5, 0, 0}, {1.5, 0, 0}, {-1.5, 0, 0}}}};
Image3D[test]

enter image description here

To get the full color palette, you must rescale your data, using e.g. Rescale:

test = {{{{1.5, 1, 1}, {-1.5, 0, 0}, {1.5, 0, 0}, {-1.5, 0, 
      0}}, {{1.5, 1, 1}, {-1.5, 0, 0}, {1.5, 0, 0}, {-1.5, 0, 0}}}};
test = Rescale[test, {-1.5, 1.5}]
Image3D[test]

enter image description here

However, if we want voxel with invalid colors to be invisible, we can add an alpha channel and set it to 0 and use ColorSpace -> "RGB". To demonstrate this we also need to change the data:

test = {{{{0, 1, 1}, {-1.5, 0, 0}, {1, 0, 0}, {0, 0, 0}}, {{0, 0, 
      1}, {0, 0, 1}, {0, -1, 0}, {-1.5, 0, 0}}}};
test = Map[Append[#, If[(0 <= Min[#]) && (Max[#] <= 1), 1, 0.]] &, 
  test, {3}]
Image3D[test, ColorSpace -> "RGB"]

enter image description here

Correct answer by Daniel Huber on August 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP