Page 1 of 1

Replace Color only in specific area of an Image

Posted: 2013-06-05T05:36:12-07:00
by getyourkickson66
Hello,
i scan cd booklets and i put these booklets on a neon-green piece of paper (background) before scanning. However, these booklets unfortunately do not have a straight cut on the sides. so after trimming the image you can see neon-green pixels at the frame of the trimmed image. But because i have this neon green background as a trigger-color, i believe it's easier to replace this as you find this color hardly in the image itself. However i want to do the following thing:

Is it possible to only replace a color in a certain area of an image? In my case this would be the outer 5 pixels (border) of my images. If that is possible i would not have to double check if it accidentally replaced the color also in the image itself, because it would only apply to the outer five pixels.

thank you very much for your help

Re: Replace Color only in specific area of an Image

Posted: 2013-06-05T07:16:48-07:00
by GreenKoopa
You could make your changes as you do now to the entire image, then copy and paste the areas you want unmodified back in. Alternatively, you could use -floodfill to make your changes so that only areas connected to the outside are changed.

Re: Replace Color only in specific area of an Image

Posted: 2013-06-05T07:54:36-07:00
by getyourkickson66
how could such a comandline look like? i did not find anything regarding to replacing colours in the manpage under -floodfill

my current commandline is the following

convert input.jpg -crop \
`convert input.jpg -virtual-pixel edge -blur '0x15' -fuzz '15%' \
-trim -format '%wx%h%O' info:` +repage -background 'insert neon color here' -rotate '-90' +repage -deskew '40%' +repage -fuzz "40%" -trim +repage -bordercolor 'white' -border '10' +repage output.jpg

Re: Replace Color only in specific area of an Image

Posted: 2013-06-05T10:21:29-07:00
by GreenKoopa
This example is silly, but it gives you an idea of both methods.

Code: Select all

convert ^
logo: -fuzz 5%% -fill red -floodfill +0+0 white ^
( logo: -gravity center -crop 90x90%%+0+0 ) -composite ^
_.png
(Windows batch, adjust as needed.)
The first line does a floodfill, which may be useful for making your color replacement. The second line limits the affected area for extra safety. If you need to limit to a non-rectangular area, you need a mask.

If you need more specific ideas, an example image would help.