I am writing some functions in Mathematica for representing MRI anatomical image volumes. The natural way to represent such a volume seems to be as an Image3D form. However, I've noticed an inconsistency in the way that these images are rendered and was wondering if there is a way around this.
Some MRI volumes display just fine because they have intensity values that have been scaled to be in the range of 0-1. Many MRI volumes, however, have values ranging from 0-256 or higher. I want to returning an Image3D object in which the data has not been modified, so I would like to keep the values between 0 and 256 in this case. Unfortunately, these volumes don't display correctly, even with a correctly specified color function.
I can't reproduce the MRI data due to subject confidentiality, but this example shows the problem:
volumeData = {{{0, 0, 0}, {0, 0.5, 0}, {0, 0, 0}},
{{0, 0.5, 0}, {0.5, 1, 0.5}, {0, 0.5, 0}},
{{0, 0, 0}, {0, 0.5, 0}, {0, 0, 0}}};
colorFunction = Function[
Blend[
{{0., RGBColor[0., 0., 0., 0.]},
{0.1, RGBColor[0.2, 0.2, 0.2, 0.]},
{0.15, RGBColor[0.5, 0.5, 0.5, 0.8]},
{1.0, RGBColor[0.9, 0.9, 0.9, 1.]}},
#]];
GraphicsRow[
{Image3D[
volumeData,
ColorFunction -> colorFunction,
Boxed -> True],
Image3D[
256.0 * volumeData,
ColorFunction -> (colorFunction[#/256.0]&),
Boxed -> True]}]
This simple example produces the following output:
Does anyone know how to fix this so that data in ranges outside of 0 - 1 can be displayed in an Image3D object?
Image3D
simply doesn't have this feature. It uses the standard range 0..1, and it's not meant for data storage. For your application it's likely better to keep the data in an array and think of Image3D as simply a visualization function. You can write your own function whichRescale
s the data to make it suitable forImage3D
. $\endgroup$