create offset variants of original image

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
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

create offset variants of original image

Post by galv »

I want to create several variations of a given image that have an offset in x or y. The resulting image's size should be 42x54 (this is the original's size also).
The variations should happen within the range in deviation given if possible. The background should be black.
How can this be done?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: create offset variants of original image

Post by fmw42 »

Please explain further and if possible show an example.

Your image can be shifted in x and/or y using -roll, but it will wrap around. So you would need to roll it, chop off the wrapped part and then add a black region to fill in the wrapped part using either -splice or -extent

convert image -roll ... -chop ... -splice ... result

Is that what you are after?

see
http://www.imagemagick.org/script/comma ... s.php#roll
http://www.imagemagick.org/Usage/crop/#shave
http://www.imagemagick.org/Usage/crop/#splice
http://www.imagemagick.org/Usage/crop/#extent


An alternate is to use -crop and then composite it onto a black background at the offsets you need using -geometery.


Another alternate is to use -distort SRT with a viewport crop. See
http://www.imagemagick.org/Usage/distor ... t_viewport
http://www.imagemagick.org/Usage/distorts/#srt
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: create offset variants of original image

Post by galv »

Example: http://ge.tt/58Q1SWa/v/0?c

first one is the original, rest are deviations.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: create offset variants of original image

Post by fmw42 »

Any of the methods I mentioned above will work to do that. If you have enough black border around the image, then all you need do is -roll.

So another method would be to pad sufficiently (at least as much as the amount you want to shift), then roll, then crop

convert image -bordercolor black -border ... -roll ... -gravity center -crop WxH+0+0 +repage result

where W and H are the input image sizes and the border is the larger amount you roll from X and Y
Post Reply