Page 3 of 3

Re: Help with composite images

Posted: 2009-05-03T16:07:25-07:00
by fmw42
anthony wrote:as y is only dependant on x, all pixels of constant x will have the the same value. thus no compression only displacement!!! It is like -wave just displacing to a circlar curve, rather than to a sine curve!
Sorry, but I still don't understand. Why do you want to do this? What is the effect on the cylinder and or image texture? I am missing the point of this. The only thing that seems reasonable to me is a compression of the cylinder, if at all. What is the point of some other kind of y displacement other than a linear compression? I am not following you. Please clarify. Thanks

Re: Help with composite images

Posted: 2009-05-03T22:59:42-07:00
by anthony
Look at the original example that started this whole discussion!

The image was compressed in the X direction, and displaced in a -wave like function in the Y direction.

The Y displacement however is not a sin curve such as -wave, but in an elliptical arc which is what I was giving. You figured out the X compression, I figured out the Y displacement!

Re: Help with composite images

Posted: 2009-05-04T09:54:34-07:00
by fmw42
OK, I think I understand now. Sorry to be so slow at catching on. You are trying to account for the (orthographic) tilt of the cylinder so that the top and bottom of the image are curved. Your formula may not be an exact representation, but it may look similar. I will look into this. Thanks.

Re: Help with composite images

Posted: 2009-05-04T16:32:58-07:00
by anthony
For orthographic projection a circular arc converted into an ellipse by a 50% reduction in displacement will produce a correct orthographic cylinder. Cylinders are a lot easier than cubes :-)

Re: Help with composite images

Posted: 2009-05-04T18:26:16-07:00
by fmw42
Seems to be working out, but the details are taking a while to work out. I think I have the vertical mode worked out in my test script. Still have to formalize it all. I have tried to approximate the tilt with a rotation parameter, so that the arc is scaled appropriately (as sin(tilt)) and the length (as cos(tilt)) also. I also had to pad and then potentially remove excess as the curved part now displaces more than the length shrinks for small angles. I also implemented a 2 sided (only) trim, which I will note at the bottom.

Here are some test results:

tilt=0 degrees
Image

tilt=11 degrees
Image

tilt=22 degrees
Image

tilt=45 degrees
Image

Here is how I did a 2-sided trim, top and bottom only, (assuming background=$bgcolor=black all around and a safecolor=$scolor=white):

convert \( $infile -bordercolor $bgcolor -border 1x0 \) \
-size 1x1 xc:"$scolor" -gravity west -composite \
-size 1x1 xc:"$scolor" -gravity east -composite \
-trim +repage -bordercolor $bgcolor -shave 1x0 $outfile

Re: Help with composite images

Posted: 2009-05-04T18:41:26-07:00
by anthony
I would also suggest you generate a seperate destination image to the source image so that teh new image can be appropriatally smaller in width and longer in height.

You can see the technique of using a separate destination image from any -verbose output for the 'plus' +distort.

It also should simplify your mathematics a lot.

Re: Help with composite images

Posted: 2009-05-04T19:26:24-07:00
by fmw42
I am not using distort. I am using composite displace. And I am also not always using fx either. So I am not sure what you are suggesting?

Re: Help with composite images

Posted: 2009-05-04T20:41:21-07:00
by anthony
fmw42 wrote:I am not using distort. I am using composite displace. And I am also not always using fx either. So I am not sure what you are suggesting?
I mean craete a destination image that is the right size, and make it the first image, and have -fx read the color from the source image given as the second or 'v' image.

See the FX Equivelent output for ANY -verbose +distort operattion for an FX example.
EG:

Code: Select all

  convert rose: -matte -virtual-pixel transparent -verbose  \
              +distort Perspective "0,0,0,0 0,46,0,46 70,0,60,10 70,46,60,30"  \
             +verbose null:
output a FX Equivelent (-distort replacement) of...

Code: Select all

  -size 62x48 -page -1-1 xc: +insert \
  -fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
       rr=-0.009420*ii -0.000000*jj + 1;
       xx=(+0.507246*ii +0.000000*jj -0.000000)/rr;
       yy=(-0.166667*ii +1.000000*jj -0.000000)/rr;
       rr>0 ? v.p{ xx-v.page.x-.5, yy-v.page.x-.5 } : blue'
It creates a destination image of 62x48 (with a -1-1 offset) whcih is place BEFORE
the source image and colors looked up using the fx operation v.p{...}

Re: Help with composite images

Posted: 2009-05-04T21:25:47-07:00
by fmw42
I believe I understand what you are asking me to do (as I have done that before with -fx), but I don't use -distort anywhere and not always -fx to create the distortion maps nor to apply the distortion map. Applying the distortion maps is done with composite displace and not -distort. Anyway, the resizing is easy with -scale to convert from a 1 row image to one of the desired padded height. The only addition is to trim the result, but only as an option. I am allowing it to be trimmed in 1 dimension, 2 dimension or not at all. I may even be able to generate the exact height without padding and trimming, but I have not yet worked on that. I have some other things also still to change and test.

If I misunderstand, please clarify as I am confused about how to use a second image when I am not using -fx (or -distort).

Re: Help with composite images

Posted: 2009-05-04T21:55:56-07:00
by anthony
fmw42 wrote:I believe I understand what you are asking me to do (as I have done that before with -fx), but I don't use -distort anywhere and not always -fx to create the distortion maps nor to apply the distortion map. Applying the distortion maps is done with composite displace and not -distort. Anyway, the resizing is easy with -scale to convert from a 1 row image to one of the desired padded height. The only addition is to trim the result, but only as an option. I am allowing it to be trimmed in 1 dimension, 2 dimension or not at all. I may even be able to generate the exact height without padding and trimming, but I have not yet worked on that. I have some other things also still to change and test.

If I misunderstand, please clarify as I am confused about how to use a second image when I am not using -fx (or -distort).
I did not ask you to use -distort in your scripts, only examine its equivalence output to get across the idea of distorting directly to an image that is already the right size.

Re: Help with composite images

Posted: 2009-05-05T09:56:56-07:00
by fmw42
I can certainly use the less efficient fx everywhere to make the distortion maps the correct size, but then they will not match in source image. How does composite displace handle that? I do not want to replace composite displace with fx. The whole point of the exercise was to speed up what I can do easily with fx by using composite displace.

Re: Help with composite images

Posted: 2009-05-05T20:40:22-07:00
by anthony
Composite displace can not handle a image size change ;-(

If I every get around to creating a replacement displace operator (with optional EWA handling compressed areas) then yes size changes (or viewports) should be posible.

The better solution would of course be to get cylindrical distortions built into the -distort operator, and allow its use of +distort, and handling of invalid pixels (-matte color).

Re: Help with composite images

Posted: 2009-05-05T21:05:40-07:00
by fmw42
OK. Now we are on the same page. In the mean time, I am still working to streamline my script and make modifications.

Re: Help with composite images

Posted: 2009-05-09T15:53:37-07:00
by fmw42
My script, cylinderize, is now done and uploaded to my server at http://www.fmwconcepts.com/imagemagick/index.html

It has been updated to permit tilting of the cylinder.