MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: distorting an image

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105344] Re: [mg105324] distorting an image
  • From: Mark McClure <mcmcclur at unca.edu>
  • Date: Sun, 29 Nov 2009 05:08:35 -0500 (EST)
  • References: <200911280605.BAA01372@smc.vnet.net>

On Sat, Nov 28, 2009 at 1:05 AM, Leon Gunther <thegunthers at rcn.com> wrote:
> I want to take an image and map each point (x,y) to another point u(x,y) and v(x,y) so
> as to produce a distorted image. It would be analogous to painting a piece of rubber
> and distorting  the rubber.

I don't know of a way to act directly on an Image object but
we can translate an Image to a standard Graphics object and
then act on that.  Here's a little code I put together for
this purpose.

pic = ExampleData[{"TestImage", "Tree"}];

(* The rectangle we'd like the image to occupy *)
{xMin, xMax} = {-1,
   1};
{yMin, yMax} = {-1, 1};

imageData = ImageData[pic];
{m, n} = ImageDimensions[pic];
pts = Flatten[Table[{j, i}, {i, yMax, yMin, -(yMax - yMin)/m},
    {j, xMin, xMax, (xMax - xMin)/n}], 1];
pp = Flatten[Most /@
    Partition[Table[{i, i + 1, i + n + 2, i + n + 1},
       {i, 1, m*n + n + 1}], n + 1], 1];
vc = N[ Table[#, {4}] & /@ Flatten[imageData, 1]];
picPolygons = GraphicsComplex[N@pts, Polygon[pp, VertexColors -> vc]];

(* The image as a Graphics object *)
Graphics[picPolygons]

(* Act on it via the complex exponential. *)
f[z_] = Exp[z];
f[{x_, y_}] = ComplexExpand[{Re[f[x + I*y]], Im[f[x + I*y]]}];
f[GraphicsComplex[inPts_, primitives_]] := GraphicsComplex[
   f /@ inPts, primitives];
Graphics[f[picPolygons]]


Mark McClure


  • Prev by Date: Re: ListPointPlot3D - how to join points
  • Next by Date: Using GraphPlot to draw an empty graph
  • Previous by thread: distorting an image
  • Next by thread: Re: distorting an image