Stiching images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
zahnrad
Posts: 2
Joined: 2014-08-30T13:49:40-07:00
Authentication code: 6789

Stiching images

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Stiching images

Post 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).
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stiching images

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Stiching images

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stiching images

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Stiching images

Post by snibgo »

Yeah, sorry, "+400+410" etc not "400,410". Gosh, I'm getting stupid.
snibgo's IM pages: im.snibgo.com
zahnrad
Posts: 2
Joined: 2014-08-30T13:49:40-07:00
Authentication code: 6789

Re: Stiching images

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Stiching images

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply