4
$\begingroup$

I am trying to map the image "Angels and Devils" by M.C. Escher onto a cigar-like shape. The code I have now is

With[
 {
  img = Import[
    "https://upload.wikimedia.org/wikipedia/en/b/bf/Escher_circlelimit_iv-with_overlay.png"
    ]
  }
 ,
 RevolutionPlot3D[
  {Sqrt[1 + t^2/10 - 1/t^2], t}
  , {t, 0.957122, 7.5}
  , Mesh -> None
  , Axes -> False
  , PlotStyle -> Texture[img]
  , TextureCoordinateFunction -> ({#1, #2} &)
  ]
 ]

Mathematica graphics

Where circle-limit-iv.jpg is the image file.

The problem is that this image has some white space around the circle, since the image is actually a rectangle.

I would like to have it so that the edge of the circle is mapped to the edge of the surface. Is there any way to do this?

$\endgroup$
2
  • $\begingroup$ I edited your question to provide a working example, but I don't see the problem you describe. You can revert the edit, if you feel my edit changed your question in an undesirable way, or edit again to show this time a complete working example of your problem. $\endgroup$ – rhermans Jun 21 '18 at 13:11
  • $\begingroup$ Thanks for taking the tour!. There are things to do after your question is answered. It's a good idea to stay vigilant for some time, better approaches may come later improving over previous replies. Experienced users may point alternatives, caveats or limitations. New users should test answers before voting and wait 24 hours before accepting the best one. Participation is essential for the site, please do your part. Also consider choosing a meaningful username, if you want. $\endgroup$ – rhermans Jun 21 '18 at 14:17
2
$\begingroup$

rhermans gave you already the answer, however with your and with every image that has a uniform padding, you can simply call ImageCrop without parameters. Here is a better resolution of the image and after cropping, you can directly use it as a texture

tex = ImageCrop@Import[
   "http://www.katarte.net/wp-content/uploads/2015/10/Escher-Circle-limit-IV-1960.jpg"];

RevolutionPlot3D[{Sqrt[1 + t^2/10 - 1/t^2], t}, 
  {t, 0.957122, 7.5}, 
  Mesh -> None, 
  Axes -> False, 
  PlotStyle -> Texture[img], 
  TextureCoordinateFunction -> ({#1, #2} &), 
  Lighting -> {{"Ambient", ColorData[97, 2]}}
]

Mathematica graphics

$\endgroup$
1
$\begingroup$

To crop your image into a square you can use

ImageCrop[#, Min[ImageDimensions[#]] {1, 1}] &

Example

With[
 {
  CropSquare = ImageCrop[#, Min[ImageDimensions[#]] {1, 1}] &
  }
 , CropSquare[ExampleData[{"TestImage", "Apples"}]]
 ]

Mathematica graphics

$\endgroup$
1
  • 1
    $\begingroup$ You got my upvote! I haven't noticed your answer until I had searched for a better image and prepared the example so I just went ahead and posted it although you already said the ImageCrop is the solution. $\endgroup$ – halirutan Jun 21 '18 at 14:14

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.