Page 1 of 1

Stiching images

Posted: 2014-08-30T13:55:07-07:00
by zahnrad
Hi forum,

I'm not sure if what I want can be accomplished with either ImageMagick's convert or montage. I've tried both and failed miserably. Most examples I found are too easy and don't do what I want. Here's the problem description:

I have n source Images. Let's say 3 sources, A.png B.png and C.png. I want to have a single destination image, X.png.

X.png shall have a fixed size, let's say 1000x1000 px. It shall have a white background and contain:
The region 10x13+15+17 of A.png at 400,410.
The region 20x23+25+27 of B.png at 300,310
The region 30x33+35+37 of C.png at 200,210

Is this possible with one single convert/montage command? If so, how?

Thanks,
Jeremy

Re: Stiching images

Posted: 2014-08-30T14:16:42-07:00
by snibgo
It would go something like this:

Code: Select all

convert
  -size 1000x1000 xc:white
  ( A.png -crop 10x13+15+17 +repage ) -geometry 400,410 -composite
  ( B.png -crop 20x23+25+27 +repage ) -geometry 300,310 -composite
  ( C.png -crop 30x33+35+37 +repage ) -geometry 200,210 -composite
  X.png
Adjust for your platform (Unix, Windows, whatever).

Re: Stiching images

Posted: 2014-08-30T14:50:10-07:00
by fmw42
It is best to always provide your IM version and platform. There are syntax differences between Linux/Mac OS vs Windows. To provide the exact command line syntax, we need to know your platform.

Re: Stiching images

Posted: 2014-08-30T14:51:16-07:00
by glennrp
Linux complains about the -geometry

I think they should be +X+Y instead of X,Y

Using this on Linux (Ubuntu 14.04 LTS) with IM-6.8.9-7, with the parentheses escaped,

Code: Select all

convert \
  -size 1000x1000 xc:white \
  \( A.png -crop 10x13+15+17 +repage \) -geometry +400+410 -composite \
  \( B.png -crop 20x23+25+27 +repage \) -geometry +300+310 -composite \
  \( C.png -crop 30x33+35+37 +repage \) -geometry +200+210 -composite \
  X.png
works for me.

Re: Stiching images

Posted: 2014-08-30T15:01:51-07:00
by fmw42
For (unix) reference, see
http://www.imagemagick.org/Usage/layers/#convert

I believe the windows equivalent is

Code: Select all

convert ^
  -size 1000x1000 xc:white ^
  ( A.png -crop 10x13+15+17 +repage ) -geometry +400+410 -composite ^
  ( B.png -crop 20x23+25+27 +repage ) -geometry +300+310 -composite ^
  ( C.png -crop 30x33+35+37 +repage ) -geometry +200+210 -composite ^
  X.png

Re: Stiching images

Posted: 2014-08-30T15:09:53-07:00
by snibgo
Yeah, sorry, "+400+410" etc not "400,410". Gosh, I'm getting stupid.

Re: Stiching images

Posted: 2014-08-31T02:14:58-07:00
by zahnrad
Aaaaaaaaaah thank you guys so much! The parentesis was what I was missing (becuase I played with those switches but they always applied to the wrong portion of the image). Thank you so so much! This is perfect! Woooo! :-)

I'm on Linux x86_64, but I'm not using a shell so I won't have to worry about escaping parenthesis (forking/execing directly). Didn't know however that ImageMagick behaved differently across platforms, so I'll keep that in mind for the future.

Thanks again.
Jeremy

Re: Stiching images

Posted: 2014-08-31T06:43:35-07:00
by snibgo
zahnrad wrote:Didn't know however that ImageMagick behaved differently across platforms, so I'll keep that in mind for the future.
It doesn't. It is the platforms that are different.