Page 1 of 1

Wraping around a Cylinder in Windows

Posted: 2014-04-08T19:10:32-07:00
by dfelder
Hello all. I need to wrap an image (roughly 8" x 4") around a image of a mug. Of course, Fred's Cylinderize function would work great; however, I don't work with UNIX/MAC/LINUX, and cylinderize is not a valid argument in a standard IM deployment. I am leveraging IM in Windows 7 through MSAccess using VBA. A typical command looks like this:

objMi.Convert myoldimage, "-background", "white", "-flatten", mynewimage

My problem is that I cannot use Fred's scripts because I cannot install all of the required components into my work's Window's system, yet the "Overlay Example 2" is exactly what I need.

Is there another, perhaps less efficient way to wrap the image using traditional IM commands? Even if it's many individual steps?

Thanks for any insight.

Cheers.

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-08T19:31:48-07:00
by fmw42
You could install Cygwin and then run my scripts. Alternately, see http://www.imagemagick.org/Usage/mappin ... e_cylinder

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-09T13:56:59-07:00
by dfelder
I am unable to install the Cygwin package, unfortunately (not allowed). In the meantime, though, if I follow that example script, I'm still having a little problem encoding it with VB.

convert rose: -background black -gravity south -splice 0x8 \
\( +clone -sparse-color barycentric '0,0 black 69,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 black -displace 17x7 rose_cylinder.png

how does that look if it's a single command line? (actually two lines)

Code: Select all

convert rose: -background black -gravity south -splice 0x8 +clone -sparse-color barycentric '0,0 black 69,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 black -displace 17x7 rose_cylinder.png
I didn't think some of those commands could be combined, and when I try to run them line by line, it's not working.

It's a shame I cannot just use your function, but c'est la vie. I need to build it the hard way and it's not built into IM.

Do you have any idea if the distort barrel command could get me close. It's seemingly way easier to work with.

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-09T15:14:16-07:00
by fmw42
clones must be enclosed by parens. Windows syntax is different. Remove the \. See http://www.imagemagick.org/Usage/windows/


convert rose: -background black -gravity south -splice 0x8 ^
( +clone -sparse-color barycentric '0,0 black 69,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 black -displace 17x7 rose_cylinder.png

If you want to make it two commands, remove the ^ from the first part and put it all on one line and remove the pipe and save the intermediate miff: as tmp.miff to disk, then remove later.

If you want it all as one command, use convert .... -composite rather than composite and remove the -swap 0,1

convert rose: -background black -gravity south -splice 0x8 ^
( +clone -sparse-color barycentric '0,0 black 69,0 white' ) ^
( +clone -function arcsin 0.5 ) ^
( -clone 1 -level 25%,75% ^
-function polynomial -4,4,0 -gamma 2 ^
+level 50%,0 ) ^
-delete 1 ^
-virtual-pixel black -define compose:args=17x7 -compose displace -composite rose_cylinder.png


This works for me in unix equivalent syntax on IM 6.8.8.10 Q16 Mac OSX

You do not say what version of IM you are using. That is always a good idea, since some IM commands are not available in older versions.

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-09T16:35:49-07:00
by dfelder
I'm using 6.8.8-10 Q8 64. I couldn't get this to work in the Windows cmd console. I'm going to have to find a different path...maybe a crop/wave or some other mix. It's kicking out a ton of errors and I've already spent 2 full days trying to get it to work. Oh well. Thanks, though!

convert mug.png -background black -gravity south -splice 0x8 (+clone -sparse-color barycentric '0,0 black 69,0 white') (+clone -function arcsin 0.5) (-clone 1 -level 25%,75% -function polynomial -4,4,0 gamma 2 +level 50%,0) -delete 1 -virtual-pixel black -define compose:args=17x7 -compose displace -composite mug_cylinder.png

If I remove the parens, the console crashes. The resulting image is all messed up (garmentdeli.com/mug_cylinder.png). Original image: garmentdeli.com/mug.png.

convert.exe: unable to open image `(+clone': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `(+clone' @ error/constitute.c/ReadImage/501.
convert.exe: iCCP: Not recognizing known sRGB profile that has been edited `mug.png' @ warning/png.c/MagickPNGWarningHandler/1832.
convert.exe: invalid argument for option `sparse-color': Invalid number of Arguments @ error/mogrify.c/SparseColorOption/526.
convert.exe: unable to open image `black': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `black' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `69,0': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `69,0' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `white')': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `white')' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `(+clone': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `(+clone' @ error/constitute.c/ReadImage/501.
convert.exe: iCCP: Not recognizing known sRGB profile that has been edited `mug.png' @ warning/png.c/MagickPNGWarningHandler/1832.
convert.exe: unable to open image `(-clone': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `(-clone' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `1': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `1' @ error/constitute.c/ReadImage/501.

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-09T16:42:35-07:00
by fmw42
convert mug.png -background black -gravity south -splice 0x8 (+clone -sparse-color barycentric '0,0 black 69,0 white') (+clone -function arcsin 0.5) (-clone 1 -level 25%,75% -function polynomial -4,4,0 gamma 2 +level 50%,0) -delete 1 -virtual-pixel black -define compose:args=17x7 -compose displace -composite mug_cylinder.png
Parens must have spaced between them and what is inside

Code: Select all

convert mug.png -background black -gravity south -splice 0x8 ( +clone -sparse-color barycentric '0,0 black 69,0 white' ) ( +clone -function arcsin 0.5 ) ( -clone 1 -level 25%,75% -function polynomial -4,4,0 gamma 2 +level 50%,0 ) -delete 1 -virtual-pixel black -define compose:args=17x7 -compose displace -composite mug_cylinder.png

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-09T17:29:56-07:00
by dfelder
Thanks for the adjustment, but it's just not working. I copied & pasted your code exactly and it's still throwing all kinds of errors. I think I need to find another path unless you see something obvious. Otherwise, I truly appreciate your input, but I don't want you to waste your time on it.

convert.exe: invalid argument for option `sparse-color': Invalid number of Arguments @ error/mogrify.c/SparseColorOption/526.
convert.exe: unable to open image `black': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `black' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `69,0': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `69,0' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `white'': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `white'' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `gamma': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `gamma' @ error/constitute.c/ReadImage/501.
convert.exe: unable to open image `2': No such file or directory @ error/blob.c/OpenBlob/2645.
convert.exe: no decode delegate for this image format `2' @ error/constitute.c/ReadImage/501.

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-09T17:40:07-07:00
by snibgo

Code: Select all

-sparse-color barycentric '0,0 black 69,0 white'
For Windows, replace single-quote by double-quote.

Code: Select all

-sparse-color barycentric "0,0 black 69,0 white"
EDIT: Or replace each space with a comma, and you don't need quotes at all.

Code: Select all

-sparse-color barycentric 0,0,black,69,0,white

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-10T13:28:18-07:00
by dfelder
Well, the good thing is that thanks to snibgo, I got some of this working in Windows. THANK YOU. However, what I'm trying to do is recreate what snibgo does here viewtopic.php?f=1&t=18497 THIS image:

Image

I have looked at the thread above and this one http://www.imagemagick.org/Usage/mappin ... e_cylinder but I have not been able to recreate the same curvature after manipulating every variable.

Instead, I get this...

Image or with a little tweaking: Image

This is my base, single line code that I have tweaking to no avail. I have tweaked the polynomial, the gamma, the args, but to no avail.

Code: Select all

convert orig3.png -background white -gravity south -splice 0x50 -set colorspace RGB ( +clone  -sparse-color barycentric "0,0 black 347,0 white" ) ( +clone -function arcsin 0.5 ) ( -clone 1 -level 25%,75% -function polynomial-4,4,0, -gamma 2 +level 50%,0 ) -delete 1 -virtual-pixel white -compose displace -define compose:args=86.75x49 -composite mug_cylinder.png
How, exactly, does snibgo get that centered curvature? I'm using the exact same trimmed base image and seemingly the same variables:

Image

Re: Wraping around a Cylinder in Windows

Posted: 2014-04-10T17:04:52-07:00
by anthony
A detailed dissection of the algorithm is giving in IM Examples
http://www.imagemagick.org/Usage/mappin ... e_cylinder

Re: Wraping around a Cylinder in Windows

Posted: 2015-11-25T07:51:07-07:00
by mcawhen
I've registered myself just to say THANK YOU for this:
fmw42 wrote:If you want it all as one command, use convert .... -composite rather than composite and remove the -swap 0,1

convert rose: -background black -gravity south -splice 0x8 ^
( +clone -sparse-color barycentric '0,0 black 69,0 white' ) ^
( +clone -function arcsin 0.5 ) ^
( -clone 1 -level 25%,75% ^
-function polynomial -4,4,0 -gamma 2 ^
+level 50%,0 ) ^
-delete 1 ^
-virtual-pixel black -define compose:args=17x7 -compose displace -composite rose_cylinder.png
You made my day, really. I was trying to use the sample algorithm an ImageMagick module for Drupal (IM RAW) and I was having problems with the miff:- command.

Thanks again.