On Sat, 14 Mar 2009 22:12:25 -0700
Dodger <[email protected]> wrote:

| I'm going to ask this question redundantly, in a few different ways,
| because it's hard to explain without pictures what I'm wanting to do,
| though the concept it pretty simple. Regardless of the simplicity of
| the concept, I can't work out how to do it without a LOT of complex
| work in ImageMagick (specifically using PerlMagick, but I can
| generally 'translate' from convert options to get it right).
| 
You are ucky then.  Distorts was a recent addition to IM examples
and one that I have worked hard to try to improve.

| First explanation -- raw form:
| 
| I want to select a specific polygon (in this case, simply a triangle
| since I'm dealing with 3d models textures, and they ae imited to tris
| and quads) and 'lift' it out of the image so I can stick it into
| another image and distort it before making it part of the other image.
| I know how to do the distortion with the Distort() method (equivalent
| to the -distort directive for convert). What I don't know is how to
| 'select' the polygon to 'cut and paste' into the new image.
| 
I pull out a triangle from an image using a mask in the -sparse-color
gradient example  (barycentric, three point color example).
   http://www.imagemagick.org/Usage/canvas/#barycentric


  convert -size 100x100 xc: \
          -sparse-color Barycentric '30,5 red   5,80 blue   95,95 lime' \
          \( -size 100x100 xc:black -fill white \
             -draw 'polygon 30,5  5,80  95,95' \) \
          +matte -compose CopyOpacity -composite \
          -fill white -stroke black \
          -draw 'circle 30,5 30,7  circle 5,80 5,82  circle 95,95 95,97' \
          sparse_bary_triangle.png

Basically it creates a second image (in parenthesis) consisting of
a black canvas with a white triangle.  This is then used as a mask
to extract the triangle from the generated gradient.

The last draw is just adding fluff to mark the control points.

Note that the control points are floating point numbers and specifying
the center of a pixel, requires the addition of 0.5,0.5 to the number.

Draw I do not thing needs that specification, so you may need to
do some check to see how draw coordinates match up to distort coordinates.
I have yet to do this, so if you do, let me know if thy match or not
(I do not think they do)

| Second explanation -- reason why I want to do this form:
| 
| I'm wanting to be able to convert textures for 3D models between two
| separate sets of UV mappings. If I can "grab" pieces of texture and
| then distort them and drop them into place, I will have a new texture
| tat fits the other mapping. The reasoning is this: There are a number
| of 3D models of humans that have 'wide' support in certain 3D
| communities.
| 
Very admirable, and I wish you luck.  I am wanting to incorporate
some method of inputting triangular meshes for image distortion and
or gradient coloring into IM, and even have some routines for generating
Delaney triangular meshes, from a list of points.

The current problem is figuring out how to modify the library to
handle data in a more polymorphic way, and how to extend the input
to read such a complex data type that defined pairs of points,
and the triangular mesh over those points (and an overall interpolation
factor) for the points.

A mesh does not exactly lend itself to the current polymorphic data type
of an list/array of floats.

| These figures have a lot of texture artists making photorealistic
| textures, bumpmaps etc. for them. There are other figures which have
| almost *no* support. While it's relatively easy to remap the latter
| figures to "take" the former ones textures, sometimes the companies
| selling the former figures try to (falsely) claim copyright on the
| texture coordinates themselves.
| 
| A desire to avoid  getting into a legal argument, particularly in
| court where they have more money than I do to blow on lawyers even
| though I am right, has inspired the need to make a simple texture
| converter. While some such texture converters exist, they are limited
| in the scope of the number of figures they support. I'd like to
| support more, particularly the human I'm making myself right now.
| 
Love to see your results!

Note you can speed up the distorts by limiting the ouput 'viewport'.
See IM example notes on this.
   http://www.imagemagick.org/Usage/distorts/#distort_viewport

Adding a viewport forces IM to generate a image layer (with offsets)
but reduces the amount of pixels and thus the calculations needed
for each 'layer' image.

That should be a big speed up when you deal with lots of small images.


| Since it's a relatively simple process to remap my figure to take
| their textures, I can just do this *once* to get the affine transform
| coordinates for the actual adjustment of each triangle (and each quad
| is simply two triangles back to back, so I can treat everything as
| triangulated) a texture itself to the new coordinates.

yes. I have been wanting to add correct forward mapped bilinear mapping
to the distorts listing, and Fred Weinhaus has even worked out the
exact formulas needed.  i just need to get four point bilinear distorts
working.

You could use a four perspective distort instead, but that may not
work well for texture alignment between quads.  Stay tuned.

| While this will
| introduce some artifacts and blurring, it's acceptable because the
| textures in question are generally produced at much higher resolution
| than is ever really necessary anyway (I've seen 2000x2000 maps for
| *teeth*).
| 
Don't forget that can distort to a highter resolution and then resize the
final result so as to get super-sampled quality improvements.

Also remember that all coordinates are floating point, and not integer.


| I'd like to include such a converter for free with my figure. I have
| already planned out a semi-automated system for converting conforming
| clothing for the figures, and the textures and morphs are the only
| blockers.

Again I really like to see you results, and your coding (with sample data
if possible).

| Morphs are, in addition, easy because I can use the
| "mapped-the-same" figure to generate a simple matrix of the vertices
| in my figure and which morph deltas to interpolate with barycentric
| weighting to calculate the new morph. The textures are the only
| blocker, and I know how to do it *conceptually* -- just not within the
| IM API.
| 
the time element just just another dimention of complexity. I have done
a little on it, but not much as yet.  Like to do more.

| Explanation 3: The "Photoshop equivalent" explanation
| 
| In Photoshop, I can use the polygonal lasso tool to select a triangle,
| then copy it and paste it into a new image, and then distort it to fit
| a new triangle on the new image, then flatten and repeat for each
| triangle. Of course, doing this manually in Photoshop would be tedious
| and take weeks and be prone to human error in my selections. Moreover,
| I could not distribute the new texture since it's a complete
| derivative work of the original texture. However, if I automated this
| procedure into a script, I could very easily instruct the user on how
| to run the script to convert textures themselves for their own use on
| my figure.
| 
| Since I already know how to do the distortion (and it is, in fact,
| better in ImageMagick because I can transform a triangle, instead of
| transforming a bounding box containing a triangle, allowing for more
| precision), I only need to know how to do the equivalent of:
| 
| - Select triangle polygon
| - Copy it
| - Paste it into a new image
| 
| After this I can easily enough distort it, and then position it on the
| new image (by padding the top and left with transparent pixels to put
| it in place, and then flatten the "layer" onto the new image.
| 
| If anyone can explain in IM how I go about this, I would so greatly
| appreciate it!
| 
Good luck, and please let me know how it all goes.




  Anthony Thyssen ( System Programmer )    <[email protected]>
 -----------------------------------------------------------------------------
    Any sufficently advanced magic is indistinguishable from technology.
                                    -- Rick Cook, "The Wizardry Compiled"
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to