Page 1 of 1
Move specific pixels
Posted: 2013-07-15T10:59:20-07:00
by ThatGuy
Hey guys,
as a foreigner this is pretty hard to explain so let me show you some pictures that hopefully get my point across.
Let's say I have a picture like this:
Is there any way to move only the blue rectangle (via convert.exe) to some other place? Like this:
I need to do this with a few hundred pictures, so I really hope that this program can do something like that!+
Cheers
Re: Move specific pixels
Posted: 2013-07-15T11:22:21-07:00
by glennrp
You could use the -roll option, if the background is really a single color as illustrated. If it is a more complex image,
how are you going to know what is behind the small image that you move?
If you can separate the small image from the background (or if you originally have them as separate images), then
there are various ways of placing the small image on the large one. I usually use the "-draw" option but there are
other possibilities.
Re: Move specific pixels
Posted: 2013-07-15T12:47:51-07:00
by ThatGuy
Hey glennrp,
thank you for your reply! Sadly I've over smiplified the pictures. Let me show you an actual example:
As you can see the left half of the image is somehow a little bit too high (4 pixels higher than the right side). I want to move that part down, so that it will look like this:
Is that possible?
Re: Move specific pixels
Posted: 2013-07-15T12:58:38-07:00
by GreenKoopa
Did the left side get moved down 4 pixels, or is that a rotate?
Re: Move specific pixels
Posted: 2013-07-15T13:08:36-07:00
by GreenKoopa
For each image, do you know exactly what area you want moved and by how much? Is the background always transparent?
Re: Move specific pixels
Posted: 2013-07-15T13:14:08-07:00
by ThatGuy
GreenKoopa wrote:Did the left side get moved down 4 pixels, or is that a rotate?
Do you mean in the second picture? I've manually done that with an image editing program. But since I have a couple of hundred pictures that are like in the first image, I can't do that with every single one of them, for obvious reasons.
GreenKoopa wrote:For each image, do you know exactly what area you want moved and by how much? Is the background always transparent?
Yes and yes!
Re: Move specific pixels
Posted: 2013-07-15T13:59:33-07:00
by GreenKoopa
It will depend on how you want to specify the area and new location. Here is one option:
convert src.png ^
( -clone 0 -crop 64x50+0+0 ) ^
( -clone 0-1 -compose Dst_Out -composite ) ^
-delete 0 +swap ^
-geometry +0+4 -compose Over -composite ^
dst.png
1 - read in file
2 - copy area to be moved
3 - erase area to be moved from background
4 - housekeeping
5 - paste area to new location
6 - write out file
This command is formatted for Windows.
Re: Move specific pixels
Posted: 2013-07-15T14:00:51-07:00
by fmw42
Split the image into two parts as needed using -crop. Take the part you want moved down and use -roll on it. Then append the two images back together.
See -append or +append
http://www.imagemagick.org/script/comma ... s.php#crop
http://www.imagemagick.org/script/comma ... php#append
http://www.imagemagick.org/script/comma ... s.php#roll
This works fine, except for the white border at the bottom is now rolled to the top on one side. If the image was fully transparent background without the white strip at the bottom, this would have worked
convert 51e450eaba387_src.png -crop 50x100% +repage \( -clone 0 -roll +0+4 \) -delete 0 +swap +append result.png
Thus you need a more sophisticated routine to preserve the bottom area, crop the part you need moved, fill the area you cropped with transparency and then composite the cropped image shifted down by 4 pixels. see GreenKoopa's solution above.
Re: Move specific pixels
Posted: 2013-07-15T18:05:39-07:00
by ThatGuy
Thanks guys, I've managed to work it out!
Re: Move specific pixels
Posted: 2013-07-16T21:54:46-07:00
by anthony
You have two simple solutions.
A Roll with a region, or a Roll with a Write mask
In both cases you specify the area to limit the modification, and then do that modifiation.
See Masking
http://www.imagemagick.org/Usage/masking/#write_mask
and Regions
http://www.imagemagick.org/Usage/masking/#regions
Not regions actually separates a rectangle from the original image, modifies it, then composes it back on the original image. But does almost all that work behind the scenes making it easy to use.