Cylindrical displacement problem
Posted: 2011-04-10T01:34:17-07:00
I found quite cool example in IM docs which i thought would perfectly fit my needs for project: "cylindrical displacement", http://www.imagemagick.org/Usage/mappin ... e_cylinder . Was particularly happy with execution speed (key factor for me). But after some thorough testing i actually discovered it was not so cool, since it produced non-realistic results.
My finding is that horizontal "compression" at the left and right edges of the cylinder is way too low and the rendered picture lacks impression of real cylinder (though vertical transformations are OK). In other words, horizontal compression is nearly linear, but it should not be.
Original picture:
What i get is this:
script:
Note that rectangle width at left or right edge is almost the same as compared to rectangle width in middle. For realistic result this ratio of widths have to be more extreme. In this case ratio is about 1.08.
The result i wish is more like this:
script:
In this case widths ratio is about 1.85 and rises to infinity at the very edge. This picture is rendered by Fred's Cylinderize script. It is realistic, universal and produce correct results, but is about 7x slower than "cylindrical displacement" script, so i can't use it to achieve my goals . I guess i could increase it's performanceby by about 33% removing unnecessary for me shell scripting statements, but that's not engough.
My question is, is there a simple way to modify this "cylindrical displacement" script to apply more realistic horizontal compression? As we can see compression overall exists, but way too low, and i can't find a way to adjust it. Or does this script in essence lacks functionality to achieve this goal?
I am trying to change various params of the script, but with no success (i treat the script as black box and change params intuitevily only, since i do not understand fully what transformations are made). I figured out, that if i change 'arcsin 0.5' to, say, 'arcsin 0.1' i get impact to horizontal compression, but the opposite way i want! I get this:
Hor. compression degree is higher in the middle of the cylinder thatn at edges now.
I looked for other ways to solve problem, like adjusting horizontal compression in extra transformation step, like here:
http://www.imagemagick.org/Usage/mappin ... rtion_maps
But performance was even poorer than that of Cylinderize script.
My finding is that horizontal "compression" at the left and right edges of the cylinder is way too low and the rendered picture lacks impression of real cylinder (though vertical transformations are OK). In other words, horizontal compression is nearly linear, but it should not be.
Original picture:
What i get is this:
script:
Code: Select all
convert orig.png -background white -gravity south -splice 0x50 \
\( +clone -sparse-color barycentric '-50,0 black 600,0 white' \) \
\( +clone -function arcsin 0.5 \) \
\( -clone 1 -level 25%,75% \
-function polynomial -4,4,0 -gamma 2 +level 50%,0 \) \
-delete 1 -swap 0,1 miff:- | \
composite - -virtual-pixel white -displace 10x40 out.jpg
The result i wish is more like this:
script:
Code: Select all
./cylinderize -m vertical -p 20 -w 80 orig.png out2.jpg
My question is, is there a simple way to modify this "cylindrical displacement" script to apply more realistic horizontal compression? As we can see compression overall exists, but way too low, and i can't find a way to adjust it. Or does this script in essence lacks functionality to achieve this goal?
I am trying to change various params of the script, but with no success (i treat the script as black box and change params intuitevily only, since i do not understand fully what transformations are made). I figured out, that if i change 'arcsin 0.5' to, say, 'arcsin 0.1' i get impact to horizontal compression, but the opposite way i want! I get this:
Code: Select all
convert orig.png -background white -gravity south -splice 0x50 \
\( +clone -sparse-color barycentric '-50,0 black 600,0 white' \) \
\( +clone -function arcsin 0.1 \) \
\( -clone 1 -level 25%,75% \
-function polynomial -4,4,0 -gamma 2 +level 50%,0 \) \
-delete 1 -swap 0,1 miff:- | \
composite - -virtual-pixel white -displace 10x40 out.jpg
I looked for other ways to solve problem, like adjusting horizontal compression in extra transformation step, like here:
http://www.imagemagick.org/Usage/mappin ... rtion_maps
But performance was even poorer than that of Cylinderize script.