Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to compute a 3D gradient vector field of an Image3D object using the built-in GradientOrientationFilter function in Mathematica. From the documentation I extracted the example for computing the gradient vector field for the 2D case and put it into a module:

computeGradientField2D[image_Image] := Module[
   {dims, dirs, magnitudes},

   dims = ImageDimensions[image];
   dirs = ImageData[GradientOrientationFilter[image, 5]];
   magnitudes = ImageData[GradientFilter[image, 5]];
    MapThread[#1 {-Sin[#2], Cos[#2]} &, {magnitudes, dirs}, 2]
   ];

For drawing the vectors I also use the method from the documenation:

Show[ImageAdjust@img, 
 ListVectorPlot[
  MapIndexed[{{#2[[2]], dims[[2]] - #2[[1]]}, #1} &, or, {2}], 
  VectorColorFunction -> (Yellow &), VectorPoints -> Fine], 
 ImageSize -> 256]

This gives me the following output for a grayscale image of cell nuclei (left: raw image, right: raw image with overlayed vector field):

enter image description here enter image description here

So far so good. Now I am struggeling with the computation of the gradient vector field for Image3D objects. My current function looks like the following:

computeGradientField3D[image_Image3D] := Module[
   {img, dims, dirs, magnitudes},
   dims = ImageDimensions[image];
   dirs = ImageData[GradientOrientationFilter[image, 5]];
   magnitudes = ImageData[GradientFilter[image, 5]];
    MapThread[#1 {Cos[#2[[1]]], Sin[#2[[1]]] Cos[#2[[2]]], 
       Sin[#2[[1]]] Sin[#2[[2]]]} &, {magnitudes, dirs}, 3]
   ];

I am particularly not sure about the last line with the MapThread where the orientations of the vectors are created and multiplied with the magnitudes. The documentation of GradientOrientationFilter contains the following information about how to interprete the orientation angles:

enter image description here

Questions:

1. Am I misinterpreting the documentation?

2. How do I visualize the gradient vector field in the end (e.g. using ListVectorPlot3D)?

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.