8
$\begingroup$

An answer at zhihu motivated me to ask this question:

Though applying a texture to a surface or a Graphics object is quite convenient in Mathematica, the quality is a bit low. So the question is straight foward: how do I get the texture on 3-D plots to be of higher quality?

Test code:

img = Texture[
   Graphics[Table[Disk[{j, i}, Sqrt[i]/6], {i, 25}, {j, 50}], 
     PlotRange -> {{1, 50}, {-5, 25}}, ImageSize -> 1000] // 
    Rasterize];
SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, Mesh -> None, 
 TextureCoordinateFunction -> ({#5, #4} &), PlotStyle -> img, 
 Lighting -> {{"Ambient", White}}]

Result generated by test code:

edge not sharp enough!

One can see that graphic used as a source for the texture is quite clear while the final result is not satisfying, in particular, the edge is not sharp enough. How to improve the quality of the result?

$\endgroup$
  • $\begingroup$ What about adding the option PlotPoints -> 100? $\endgroup$ – Jens Feb 11 '17 at 5:53
  • $\begingroup$ @Jens I've tried that, but not useful. $\endgroup$ – Wjx Feb 11 '17 at 6:02
  • $\begingroup$ Then I probably don't understand what you mean by "edge." $\endgroup$ – Jens Feb 11 '17 at 6:16
  • $\begingroup$ I think this problem may have come up before but I cannot find it. @Jens the edges in the texture itself, i.e. the transition between black and white. The whole texture looks blurry rather than crisp. I have a vague memory that someone solved this by splitting a surface into multiple Texture regions. $\endgroup$ – Mr.Wizard Feb 11 '17 at 6:23
  • 1
    $\begingroup$ @SteveK Hi, if you have question please ask on instead of posting answers. But before you proceed, please prepare a minimal example and explanation of what exactly is the problem. $\endgroup$ – Kuba Jun 16 '17 at 11:28
7
$\begingroup$

m_goldberg's solution jogged my memory and the problem is even a pitfall:

Note that Rasterize[Grapphics[. . .]] is not an Image:

gr2d = Graphics[Table[Disk[{j, i}, Sqrt[i]/6], {i, 25}, {j, 50}], 
   PlotRange -> {{1, 50}, {-5, 25}}, ImageSize -> 1000];

Rasterize[gr2d] // Head
Graphics

Alexey's solution applied:

tex1 = Rasterize[gr2d, "Image"] // Texture;

SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, Mesh -> None, 
 TextureCoordinateFunction -> ({#5, #4} &), PlotStyle -> tex1, 
 Lighting -> {{"Ambient", White}}]

But I would like to ask in advance, What if I only have the high quality rasterized image but not its original form? That rasterized image surely is clear enough for a very high quality texture but Mathematica returns a poor quality result.

This is not a problem, in fact it is the solution, if you have an actual Image rather than a Raster.

img = gr2d // Image;

tex2 = Texture[img];

SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, Mesh -> None, 
 TextureCoordinateFunction -> ({#5, #4} &), PlotStyle -> tex2, 
 Lighting -> {{"Ambient", White}}]

enter image description here

$\endgroup$
  • $\begingroup$ Well, it seems this is a proper solution I want…… I've never thought I STILL will drop into pitfalls after so many years of fuzzing with Mathematica :( Thanks a lot! $\endgroup$ – Wjx Feb 12 '17 at 3:02
  • 1
    $\begingroup$ @Wjx well I've been at it for ~17 years and I still couldn't give you a quick answer, so don't feel bad. Or laugh at me, whichever you prefer. $\endgroup$ – Mr.Wizard Feb 12 '17 at 3:13
8
$\begingroup$

Don't rasterize. I think Texture is doing its own rasterization, so you are seeing the results of a double rasterization.

img = 
   Texture[
     Graphics[
       Table[Disk[{j, i}, Sqrt[i]/6], {i, 25}, {j, 50}], 
       PlotRange -> {{1, 50}, {-5, 25}}, ImageSize -> 600]];
SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, 
  Mesh -> None, 
  TextureCoordinateFunction -> ({#5, #4} &), 
  PlotStyle -> img, 
  Lighting -> {{"Ambient", White}}]

plot

$\endgroup$
  • 3
    $\begingroup$ Well, this result seems satisfying enough, Thanks! But I would like to ask in advance, What if I only have the high quality rasterized image but not its original form? That rasterized image surely is clear enough for a very high quality texture but Mathematica returns a poor quality result. $\endgroup$ – Wjx Feb 11 '17 at 12:06
  • $\begingroup$ @Wjx. I don't know the answer to the question you raise in your comment. I have never been in the situation you describe. Perhaps someone else, who has, will chime in. $\endgroup$ – m_goldberg Feb 11 '17 at 14:29
  • $\begingroup$ Thanks for your contribution! I really really want to accept both if I could. but Wizard's solution is closer to what I want in mind, so I chose his. Thanks again! $\endgroup$ – Wjx Feb 12 '17 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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