3
$\begingroup$

I would like to create a visualization of a volume with the help of equally-spaced grid lines. The effect I want to get is easily obtainable for 2D images, the image is simply divided into quadratic patches and the boundary is replaced by some constant value:

patchSize = 10;
insidePad2D[x_, padding_, val_] := 
 With[{offset = padding + 1}, 
  ArrayPad[x[[offset ;; -offset, offset ;; -offset]], padding, val]]
dataSpikey = ColorConvert[Import["ExampleData/spikey.tiff"], "Grayscale"] // ImageData;
imgSpikey = ArrayFlatten[BlockMap[insidePad2D[#, 1, 0] &, dataSpikey, {patchSize, patchSize}], 
   2] // Image

enter image description here

However, this seems to be more challenging for Image3D:

patchSize = 10;
insidePad3D[x_, padding_, val_] := 
 With[{offset = padding + 1}, 
  ArrayPad[x[[offset ;; -offset, offset ;; -offset, 
    offset ;; -offset]], padding, val]]
dataEngine = Import["ExampleData/CTengine.tiff", "Image3D"] // ImageData;
dataEngine = 
  ArrayFlatten[
   BlockMap[insidePad3D[#, 1, 0] &, 
    dataEngine, {patchSize, patchSize, patchSize}], 3];
imgEngine = Image3D[dataEngine]

enter image description here

The grid lines are visualized as zero-opacity voxels ("gaps") and not in black as desired. How can I fix this problem?

$\endgroup$

1 Answer 1

4
$\begingroup$

I was able to come very close to what I wanted. The trick is to apply the color function before the data is given Image3D. This way black voxels can be added as desired and the internal color function doesn't mess with it.

f = Blend[{{0., RGBColor[0.05635, 0.081, 0.07687, 0.00343663]}, {0.1, 
     RGBColor[0.8877, 0.2636, 0., 0.103093]}, {0.3, 
     RGBColor[1., 0.6036, 0., 0.302406]}, {0.66, 
     RGBColor[1., 0.9658, 0.4926, 0.661168]}, {1., 
     RGBColor[1., 0.6436, 0.03622, 1.]}}, #1] & (* Default color function of Image3D *)
dataEngineF = Map[f, dataEngine, {-1}];
dataEngineF = 
  ArrayFlatten[
   BlockMap[insidePad3D[#, 1, RGBColor[0, 0, 0, 0.01]] &, 
    dataEngineF, {patchSize, patchSize, patchSize}], 3];
Image3D[dataEngineF]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.