Anthony and Fred,
Thank you very much for your help. As the calculation of the transformation
coefficients is quite fast compared to the pixel transformations themselves, I
now don't see a tremendous need to try and save the coefficients for reuse on
subsequent frames.
I was not aware (didn't read the entire documentation, you see) that you could
do a
convert frame_1034?.png ... \
-distort .... \
-scene 10340 new_frame_%05d.png
type of command to operate on multiple images at once. This certainly seems
the way to proceed for me. I shall implement this and let you know how I make
out, though it may not be for a few weeks as new projects have thrust
themselves upon me since I posted this on Friday. :( On the bright side, as
this process is memory limited, I will likely be able to justify a beefier
machine to increase speed :)
Once again, thank you very much for your help.
Mike
--------Reply 2 from Anthony Thyssen---------
The -verbose setting will give you the PerspectiveProjection coefficents
that should be equivelent to the distortion just done.
The -fx equivelent is the reverse coordinate mapping that is actually
applied as a check on what is going on internally, and as a debuggng
tool. It would however very VERY VERY VERY slow.
You can either use the same distort control points for each frame, as
compared to the actual distortion process this is quite fast, OR use the
Projection coefficents. Though the if only four points are used he
amount of calculation IM does is small compared to the calculations
needed for the actual distortion, so the savings would not be great.
See the updates to the IM Examples page on the Perspective Projection
for info on what the coefficents actually mean mathematically.
Howeever did you know you can have IM read in multiple frames, number
depending on the amount of memory in your computer, and have it distort
ALL those frames in one go?
EG:
convert frame_1034?.png ... \
-distort .... \
-scene 10340 new_frame_%05d.png
will distort the ten frames from 10340 to 10349.
If you have a good amount of memory you can increate the number of
frames per command. I beleieve you can even do this with "mogrify"
but I can't be certain how well it will work as I have never done this.
Please let us know, how you go.
PS: you can also change the distortion slightly from frame to frame.
For example make a 'scene change' that looks like the screen is being
'flipped' over!
-------Reply 2a from Anthony Thyssen--------
The -set option:distort:verbose 1 was an old technique that was used before I
figured out to access the normal -verbose setting.
Use -verbose instead of -set option:distort:verbose 1
--
Anthony Thyssen ( System Programmer ) <[EMAIL PROTECTED]>
--------Reply 1 from Fred Weinhaus---------
Hello Mike,
Anthony and I were just discussing that last night. He has a verbose
setting for use with -distort perspective that will output the
transformation coefficients, which then can be reused with -distort
perspectiveprojection
He sent me a while back the following example, but I have not been
able to reproduce the text/coefficient output.
For example, 2-point affine (fallback from perspective!)
convert rose: -virtual-pixel black -set option:distort:verbose 1 \
-distort perspective '0,0,10,5 0,45,5,20' x:
Outputs to STDERR
Affine Reverse Map
-fx 'xx=+2.700000*i +0.900000*j -31.500000;
yy=-0.900000*i +2.700000*j -4.500000; p{xx,yy}'
Affine Forward Map
-distort AffineProjection \
'0.333333,0.111111,-0.111111,0.333333,10,5'
I expect similar output for a 4 point perspective - but get the
perspective coefficients rather than the affine fall back ones.
For example from his Distort Examples page:
convert building.jpg -matte -virtual-pixel transparent \
-set option:distort:verbose 1 \
-distort Perspective \
'7,40 4,30 4,124 4,123 85,122 100,123 85,2 100,30' \
building_pers.png
should output to stderr the coefficients, but I cannot get them to
list to the terminal even with a redirect. I keep getting an error
message something like:
"convert: option requires an argument `-distort' @
wand/convert.c/ConvertImageCommand/1147"
I tried both:
convert building.jpg -matte -virtual-pixel transparent \
-set option:distort:verbose 1 \
-distort Perspective \
'7,40 4,30 4,124 4,123 85,122 100,123 85,2 100,30' \
building_pers.png 2> tmp.txt
and
str=`convert building.jpg -matte -virtual-pixel transparent \
-set option:distort:verbose 1 \
-distort Perspective \
'7,40 4,30 4,124 4,123 85,122 100,123 85,2 100,30' \
building_pers.png 2>&1`
echo $str
Perhaps I misunderstand how to do this.
So I will forward him this message (as he is on his weekend now).
When he gets it he can clarify for you (and me) further.
HOWEVER, I doubt that computing the coefficients from the points
takes that much time that you would really notice it (at least not on
a single frame). Perhaps on hundreds of frames. But it should be
insignificant compared to all the computations for transforming all
the pixel data.
Nevertheless, that was at least part of the reason to have the
-distort perspectiveprojection
Fred
--------Original Post-----------
>Greetings.
>
>I have a program that incorporates ImageMagick to do a perspective
>transformation on a single image. I give it the requisite
>coordinates and it works extraordinarily well.
>
>Now, I need to move to the next level. I have a series of images,
>let's call it a movie, on which I would like to do a perspective
>transformation of each frame. The coordinates will be the same for
>each frame as the camera and the reference points are fixed. As it
>takes some time to compute the transformation matrix, I was
>wondering if there was a built-in way to calculate the matrix on the
>first frame, then retain the matrix and use it on each successive
>frame to improve efficiency.
>
>I see from the documentation
>(http://www.imagemagick.org/script/command-line-options.php#distort)
>that I can use the -verbose setting to get the internal coefficients
>and an -fx equivalent. However, I am not sure this -fx equivalent
>would actually save on computation time.
>
>Could anyone enlighten me as to the most efficient way of doing this
>identical perspective transformation on a series of images? Is
>calculating the transformation matrix even a significant amount of
>time?
>
>Thank you very much,
>Mike
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users