PIL Image transform
Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the image. The transform will take a rectangular 2D image and transform it to a 3D representation in 2D. Please see the link to see what I am trying to do: http://seanberry.com/transform.png I have PIL v1.15 installed which has a PERSPECTIVE transform, but it does not appear to do what I want - or I can't figure out how to use it correctly because it is using a transform matrix's coefficients. Here is the only info I could find on the usage: http://mail.python.org/pipermail/image-sig/2005-February/003198.html This is for the creation of images to be used in Flash. Originally I was doing the image processing in Flash because Flash 8 has a BitmapData class which does the basics of images, copy, transform, etc. To accomplish the transform I was using an algorithm that approximated triangles to fill and worked really well, but I need the image processing to be server side, not client. So, here I am. Anyone have any idea how to accomplish my goal here? Is there a way to fill a triangle with a bitmap using PIL? What about better docs on the PERSPECTIVE transform? Thanks for any and all help on this. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL Image transform
> This looks like a correct description of the sources:
>
> In Image.py:
>
> elif method == PERSPECTIVE:
># change argument order to match implementation
>data = (data[2], data[0], data[1],
>data[5], data[3],
>data[4],
>data[6],
>data[7])
>
> and then in Geometry.c:
>
> static int
> perspective_transform(double* xin, double* yin, int x, int y, void*
>data)
> {
>double* a = (double*) data;
>double a0 = a[0]; double a1 = a[1]; double a2 = a[2];
>double a3 = a[3]; double a4 = a[4]; double a5 = a[5];
>double a6 = a[6]; double a7 = a[7];
>
>xin[0] = (a0 + a1*x + a2*y) / (a6*x + a7*y + 1);
>yin[0] = (a3 + a4*x + a5*y) / (a6*x + a7*y + 1);
>
>return 1;
> }
>
> Something like this is almost what you what:
>
> im = im.transform(im.size, Image.PERSPECTIVE, (1, 0, 0, 0, 1, 0, -0.004,
> 0))
>
> But the problem really is that the top row of the image is at at y of
> 0-- I think you want the origin of the image to be in the centre for
> this to work properly.
>
> Is there a way to do that in PIL?
thanks for the reply. I have been able to use the Image.PERSPECTIVE
transform via trial and error to get it to work properly for each transform.
What I am really looking for I guess is a way to calculate the 8 int tuple
to match the perspective change I am going for. For a given image there may
be 5 elements that need to be 'painted' on with perspective. A database
table will include the transform tuples based on the source image. So, by
passing a starting image and a pattern image, the starting image can be
covered with. Perhaps the best way to explain is visually
http://seanberry.com/perspective.png
What I need to know is how you take a surface like (P1, P5, P6, P2) and
describe it with the 8 int tuple?
I know that for the elements in the transform a - h they are as follows...
(a, b, c, d, e, f, g, h)
a / e is the ratio of height to width. For a = 2, e = 1 the output is half
the width of the original.
b is the tan of the angle of horizonal skew. e is the vertical skew
equivalent of b.
c and f are the x and y offsets respectively.
g and h are the values that actually distort the image ranther than doing an
affine transform... which is where I need the help...
I appreciate any additional insight into this problem.
This is a small step in a massive project I am working on and need to get
past this part to move on to the next.
I am also willing to $pay$ for help that results in a success.
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
Easy question on minidom
I am using minidom to parse a 20,000 line XML file. I have a few instances where the number of child nodes of a particular node can be variable in number. To access them I am doing something like the following... xmldoc = minidom.parseString(r) results = xmldoc.childNodes[0] for myNode in results.childNodes[1].childNodes: do Stuff with myNode... problem is I am having a heck of a time trying to access the value of the node. For instance I get things like this But I need the values... any help here? -- http://mail.python.org/mailman/listinfo/python-list
Help on the deformer object
I am trying to use a MESH transform from the Python Imaging Library and am having trouble defining my deformer object. What I want to do is map one eight item tuple like (x0, y0, x1, y1, x2, y2, x3, y3) to another set of points like (x00, y00, x10, y10, x20, y20, x30, y30) where (xn, yn) is a point. >From the docs: im.transform(size, MESH, data, filter) image => image Similar to QUAD, but data is a list of target rectangles and corresponding source quadrilaterals. What I need to know is the format that the MESH should be in... a list of target rectangles and corresponding source quadrilaterals??? [(x0, y0, x1, y1, x2, y2, x3, y3) , (x00, y00, x10, y10, x20, y20, x30, y30)] does not work. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Pythonic way to condese my array
I have a list of dictionaries where each dictionary defines, among other
things, a row and column number. So, my list might look like this:
[{'row':1, 'column':1, otherdata}, {'row':1, 'column':2, 'otherdata}...]
This data is passed to flash and used there to create a grid of objects that
are placed based on the row and column values.
For a given set of data I may have values column values in the range of 1, 9
inclusive.
What I would like to do is take my list of dictionaries (like the one listed
above) and shift the column numbers down to fill in missing values...
example (only the column key,value pair is show for simplification):
[{'column':1}, {'column':2}, {'column', 4}, {'column': 8}, {'column':2},
{'column', 4}]
If this were the dataset... I would want to change all 4s to 3 and all 8s to
4. That way I end up with 1 ... 4 instead of 1, 2, 4, and 8.
Is there some slick way to do this?
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
