1
$\begingroup$

A few days ago i made a publication asking about of projecing ContourPlot3D onto 2D slices (Project ContourPlot3D onto 2D slices. It is possible?), but i think i did not explain myself very well. I'm trying to show the evolution of a PDE dependent on time on a set of slices 2D from images CT. I have the code that generates a ContourPlot2D on a single image and of course it evolve on time generating of a lot a images that overlap to create a "animation".

The image of below show the output earlier mentioned:

enter image description here

Now, i'm trying to do the same but in a set of CT images of different brain slices so that the ContourPlot2D evolve on each slice of image CT, Something similar to creating a ContourPlot3.

The next code can show a figure in "3D" from a set of slices (images CT 2D) that can be moved on the three axes (x,y,z) in such a way that a 3D structure of the 2D slices can be formed. The image of below show that output:

enter image description here

To be precise, i want that by moving a slice in x, y or z, the ContourPlot2D show the portion of that contour in each slice, as if it were a sweep inside of brain.

That is, if the ContourPlot were a sphere embedded in the 3D structure of the brain, i would like to move the slices to show a ContourPlot2D on each slice, similar to what happens in the first image of this post but with the difference that each contour shows the evolve of the PDE for each slice as if it were a 3D sweep of a sphere projecting a 2D contour of that sphere into each slice.

i've already creates a ContourPlot3D from a PDE (x,y,x,t) and i tried make slices from Contour3D using SlicesContourPlot3D but the output is not desired.

I think that in order to carry out the process to obtain the desired output,i need first create a ContourPlot3D from pde(x,y,z) and then generate slices 2D from Contour3D and overlap it on slices of images CT but i tried it and i failed. I don't have idea of how do it. I hope to have explained myself and if you could give me some suggestions so i can start working them.

The codes of images are below. i created them in WM 11.0.1:

Code first image:

img2="Brain2Linux.png"

img3 = Sharpen[ColorConvert[img2, "Grayscale"]]

diffcoeff = ListInterpolation[ImageData[img3], InterpolationOrder - 
> 3]

sols = Quiet[
NDSolve[{Div[
   1./500.*(diffcoeff[798.*x, 654*y])^4*
    Grad[u[t, x, y], {x, y}], {x, y}] - D[u[t, x, y], t] + 
  0.025*u[t, x, y] == 0, 
u[0, x, y] == Exp[-1000. ((x - 0.6)^2 + (y - 0.6)^2)], 
u[t, 0, y] == 0, u[t, 1, y] == 0, u[t, x, 0] == 0, 
u[t, x, 1] == 0}, u[t, x, y], {t, 0, 20}, {x, 0, 1}, {y, 0, 1}]]

Plot3D[u[t, x, y] /. sols /. t -> 8, {x, 0, 1}, {y, 0, 1}, 
PlotRange -> All]

ImageCompose[img3, {ContourPlot[
u[t, x, y] /. sols /. t -> 8, {y, 0, 1}, {x, 0, 1}, 
PlotRange -> {{0, 1}, {0, 1}, {0.01, All}}, PlotPoints -> 100, 
Contours -> 200, ContourLines -> False, AspectRatio -> 798./654., 
ColorFunction -> "Temperature"], 0.6}]

frames = Table[
ImageCompose[
img3, {ContourPlot[
  u[t, x, y] /. sols /. d -> t, {y, 0, 1}, {x, 0, 1}, 
  PlotRange -> {{0, 1}, {0, 1}, {0.01, All}}, PlotPoints -> 100, 
  Contours -> 200, ContourLines -> False, 
  AspectRatio -> 798./654., ColorFunction -> "Temperature"], 
 0.6}], {t, 0, 10, 0.5}];

ArrayReshape[frames, {4, 5}] // TableForm

Export["/home/sknt/MEGA/Progra/Mathematica/Outputs/Brain2.gif", 
frames];

Code second image:

arc = "/home/sknt/MEGA/Progra/Mathematica/Inputs/M4-Axi(skull- 
full)\
Stanford";
M4 = Import[arc, #] & /@ Import[arc];
(Image[#, ImageSize -> 32]) & /@ M4;

color = Reverse[
ParallelMap[
With[{img = #}, 
  ColorCombine[{Colorize[img, ColorFunction -> "SolarColors"], 
    Binarize[img]}, "RGB"]] &, M4]];
(Image[#, ImageSize -> 32]) & /@ color;

data = Developer`ToPackedArray[Map[ImageData, color]];

With[{vista = {5, 8, 7}},
Manipulate[
Graphics3D[{Opacity[Dynamic[o]], Texture[data], EdgeForm[], 
 Dynamic[{

  With[{pts = 
     Table[{{x, 0, 0}, {x, 1, 0}, {x, 1, 1}, {x, 0, 1}}, {x, 0, 
       xx, step}]},
   Polygon[pts, VertexTextureCoordinates -> pts]],
  With[{pts = 
     Table[{{0, y, 0}, {1, y, 0}, {1, y, 1}, {0, y, 1}}, {y, 0, 
       yy, step}]},
   Polygon[pts, VertexTextureCoordinates -> pts]],

  With[{pts = 
     Table[{{0, 0, z}, {1, 0, z}, {1, 1, z}, {0, 1, z}}, {z, 0, 
       zz, step}]},
   Polygon[pts, VertexTextureCoordinates -> pts]],


  Polygon[{{x, 0, 0}, {x, 1, 0}, {x, 1, 1}, {x, 0, 1}}, 
   VertexTextureCoordinates -> {{x, 0, 0}, {x, 1, 0}, {x, 1, 
      1}, {x, 0, 1}}], 
  Polygon[{{0, y, 0}, {1, y, 0}, {1, y, 1}, {0, y, 1}}, 
   VertexTextureCoordinates -> {{0, y, 0}, {1, y, 0}, {1, y, 
      1}, {0, y, 1}}], 
  Polygon[{{0, 0, z}, {1, 0, z}, {1, 1, z}, {0, 1, z}}, 
   VertexTextureCoordinates -> {{0, 0, z}, {1, 0, z}, {1, 1, 
      z}, {0, 1, z}}]}]},
      Background -> Black, RotationAction -> "Clip", 
   ViewPoint -> vista],
       {{x, 0.5}, 0, 1}, {{y, 0.5}, 0, 1}, {{z, 0.5}, 0, 
   1}, {{o, 0.75, "Opacidad"}, 0, 1}, {{xx, 0, "X"}, .0, 
   1}, {{yy, 0, "Y"}, .0, 1}, {{zz, 0, "Z"}, .0, 
   1}, {{step, 0.05, "Paso"}, .005, 0.09}]]

Image brain firs picture: enter image description here

The dataset of images for the second picture can be downloaded from: https://graphics.stanford.edu/data/voldata/cthead-8bit.tar.gz

Thanks for possible suggestions.

$\endgroup$
  • $\begingroup$ Can you share the code that you have written so far? $\endgroup$ – user21 Feb 12 at 6:13
  • 1
    $\begingroup$ Not as links please but in your question. If you want a good answer to your question you should make it as easy as possible for people to answer your question. Following links on some other site does not work well. Have a look at how other people ask questions on this site. $\endgroup$ – user21 Feb 13 at 6:24
  • $\begingroup$ @user21 i re-edit the post. The codes are at the end of post. $\endgroup$ – Rodrigo López Feb 13 at 21:16
  • $\begingroup$ To follow up on what @user21 was asking for, can you also simplify the post a bit? Like cut down on the backstory, make a more minimal working example, etc. I'm sure what you want to do is entirely possible, but my eyes basically glazed over as I read this. I looked at the walls of text and my brain basically decided it wasn't worth doing all the necessary background reading to figure out what your question really is. $\endgroup$ – b3m2a1 Feb 13 at 22:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.