Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to directly transform an image?

This works but seems klunky :

Graphics[{Translate[ Raster@ImageData@image, {x,y}], .. other graphics objects .. }]

Just wondering if there is a better way..

Per JM.s comment, you can sort of do this with ImageForwardTransformation I actually looked at those before asking the question and didn't think they would work, but now I went back and figured it out..

here is a simple translation:

{w, h} = ImageDimensions[img]
ImageForwardTransformation[ img , (# + {x, y}) &, Background -> 1, 
        DataRange -> Full, PlotRange -> {{0, w + x}, {0, h + y}}]

This creates a new larger image, large enough to contain the transformed result but still anchored with a corner at {0,0}, so isn't really equivalent to simply translating the image.

share|improve this question
Look up ImageTransformation[] and ImageForwardTransformation[]. – J. M. May 30 '13 at 20:27
If I understand correctly, all you need is Inset. – Jens May 30 '13 at 21:28
Thanks, I was not aware of Inset, useful indeed! – george2079 May 31 '13 at 19:04
up vote 2 down vote accepted

Here is a completely random illustration of how to use Inset to place an image into a Graphics:

img = Image[
    ExampleData[{"Geometry3D", "Cow"}],
    ImageSize -> 360, Background -> None],
   ImageResolution -> 144
    Disk[{.2, .4}, .6],
    Inset[Rotate[img, -t^2], {0, 1} + t {.9, -.8}]
   Background -> Lighter[Gray],
   PlotRange -> {{0, 1}, {0, 1}},
   ImageSize -> 360
  {t, 0, 1, .1}

cow movie

The image img has transparent background, and is superimposed on a green circle in a Graphics object. When positioning the Inset inside Graphics, it is useful to always specify an explicit PlotRange, because it allows you to determine the position more accurately in the logical coordinate system of the other graphics objects. Here, I chose to make the left and bottom edges be at 0, and the top and right correspond to 1. In addition, I also included a Rotate command to show that you can add other transformations of the img inset.

share|improve this answer
Thanks for this illustration of "the cow jumped over the (green) moon". – bill s Jun 1 '13 at 5:48

Your Answer


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

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