Message Boards Message Boards

GROUPS:

Visualizing 3D images of fruits and vegetables

Posted 8 years ago
13137 Views
|
2 Replies
|
25 Total Likes
|

I stumbled upon insideinsides.blogspot.com today, which is a really cool blog that shows fruits and vegetables going through an MRI machine.

The objective of this post is to take slices of these foods and reconstruct them, color them, and look at different cross sectional views that a GIF can't offer.

Looking inside a pumpkin

enter image description here

After we import this gif, there's a bit of preprocessing we need to do before getting our 3D image.

pumkinslices = Import["http://imgur.com/TvwD0.gif"];
pumkinprocessed = RemoveAlphaChannel[ColorConvert[ImageTake[#, {40, -10}, {20, -20}], "Grayscale"]] & /@ pumkinslices;

Here we removed the borders for each slice, converted the images grayscale, and lastly removed the alpha channel which will make the background transparent in the 3D image. Now we're ready to see the 3D image:

Image3D[pumkinprocessed, BoxRatios -> {1, 1, .75}]

enter image description here

Notice we need to manually choose the BoxRatios. What if we want to see inside the pumpkin? We can use a built in ColorFunction:

Image3D[pumkinprocessed, BoxRatios -> {1, 1, .75}, ColorFunction -> "LowRange"]

enter image description here

Neat! But what if we wanted more control of what we can see? To edit with more control, we can right click on our image to bring up an interactive editor.

enter image description here

Adjust levels to see past this inner shell: enter image description here

Coloring celery

enter image description here

We import the slices just like before:

celeryslices = Import["http://i25.tinypic.com/11t7b7s.jpg"][[1 ;; 82]];
celeryprocessed = RemoveAlphaChannel[ColorConvert[#, "Grayscale"]] & /@ celeryslices;
Image3D[celeryprocessed, BoxRatios -> {1, 1, 1}]

enter image description here

We open up the ColorFunction editor again and this time choose a color scheme. AlpineColors seems to work best.

enter image description here

Cross sections of a colored watermelon

enter image description here

Again, import the slices and create the 3D image:

melonslices = Import["http://www.pencapchew.org/watermelon.gif"];
melonprocessed = RemoveAlphaChannel[DeleteSmallComponents@ColorConvert[ImageTake[#, {1,-1}, {100,-100}], "Grayscale"]]& /@ melonslices;
Image3D[melonprocessed, BoxRatios -> {1, 1, 1}]

First let's color the watermelon in the ColorFunction editor. We're lucky because there is a default color scheme called "WatermelonColors". We will however have to adjust the levels. enter image description here

We're now ready to look at cross sections. The advantage we have is we can choose any direction to make cuts now, whereas the GIF is restricted to the z-axis! The easiest way to take cross sections is by clicking the image which will bring up a menu. Click the "Clipping" tab and you're set.

enter image description here

Coloring corn with a custom ColorFunction

enter image description here

Here's the corn in 3D:

cornslices = Import["http://pencapchew.org/ae/corn.gif"][[9 ;;]];
cornprocessed = RemoveAlphaChannel[ColorConvert[#, "Grayscale"]]& /@ cornslices;
Image3D[cornprocessed, BoxRatios -> {1, 1, 1}]

enter image description here

If we look back to the ColorFunction editor for the watermelon, notice there is a way to copy the ColorFunction generated. This will give us the tools to make our own ColorFunction without the need of the editor.

enter image description here

The function ends up looking like this:

(Blend[{{0., RGBColor[0.1, 0.1, 0.1, 0.]}, 
     {0.313368, RGBColor[0.458381, 0.616899, 0.367651, 0.67293]}, 
     {1., RGBColor[0.882911, 0.359638, 0.360092, 1.]}, 
     {1., RGBColor[0.882911, 0.359638, 0.360092, 1.]}}, #1] & )

This function essentially blends colors (with an alpha channel) with certain blending weights. Let's use this strategy to color the corn husks tan and the corn, well corn colored. To find these colors we can use Interpreter:

corn = Append[Interpreter["Color"]["corn"], 1.];
tan = Append[Interpreter["Color"]["tan"], 1.];

Playing around we can find the appropriate blending factors and we have our custom ColorFunction:

Image3D[cornprocessed, BoxRatios -> {1, 1, 1}, 
     ColorFunction -> (Blend[{{0, RGBColor[0, 0, 0, 0]}, {.75, corn}, {.25, tan}}, #]&)]

enter image description here

Make sure to check out insideinsides.blogspot.com to see many mesmerizing GIFs. Post any neat 3D images you make from these GIFs below!

POSTED BY: Greg Hurst
2 Replies

Very nice, Chip, thanks for sharing!

A trick I use sometimes working with 3D images is applying GradientFilter to remove flat opaque voxels and see the wall / surface structure better:

celeryslices = Import["http://i25.tinypic.com/11t7b7s.jpg"][[1 ;; 82]];
celeryprocessed = RemoveAlphaChannel[ColorConvert[#, "Grayscale"]] & /@ celeryslices;
celery3D = Image3D[celeryprocessed, BoxRatios -> {1, 1, 1}]  

GradientFilter[celery3D, 1]

enter image description here

POSTED BY: Vitaliy Kaurov
Posted 8 years ago

That's really cool Vitaliy!

POSTED BY: Greg Hurst
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract