How to color select all colors in a gradient?

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
stampguy
Posts: 7
Joined: 2013-11-24T16:23:11-07:00
Authentication code: 6789

How to color select all colors in a gradient?

Post by stampguy »

Is it possible using command line scripts to do a color select of all the colors found in a gradient?

This relates to my posts about trying to black-fill the shadow area around the edge of scanned postage stamps that were scanned on a colored background. (Scanning on black background is not possible for reasons described in those posts).

- I would like to experiment with selecting the greenish colors in the shadow area around the edges of the stamps. To know those colors, I could make an image that contains those colors (i.e. an image of the gradient).

- I would like to add those colors to the selection of the background color that is being done in this script, but I don't have a clue how to do that. Note that the selection needs to be in the "background region" not in the foreground, i.e. not in the stamp design itself. In a crude way, I envision this working by checking each pixel that is adjacent to the already-selected background area and if that pixel's color is in the "list" of colors found in the gradient, then selecting it also.
http://jsa.viewimage.net/temp/im/bg_rem ... modified.s

Is this even possible?

=====

The source file coming from the scanning process is here:
*** I am posting a JPEG version for easy web viewing purposes.
http://jsa.viewimage.net/temp/im/source.jpg
*** The original TIFF version is here:
http://jsa.viewimage.net/temp/im/source.tif (5.5 MB)

The current result of the script process is here -- you really have to magnify the image to see the problem (the green shadows along the tops of the stamps' perforations):
http://jsa.viewimage.net/temp/im/result-2.tif (5.5 MB)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to color select all colors in a gradient?

Post by snibgo »

Interactive programs work with "selections". IM doesn't. The equivalent is to create a mask, eg black where the pixel is "selected" and white otherwise. You can then use this mask to control other operations.

If you want a mask of all colours in a gradient (or any arbitrary set of colour) you can put them in an image, then "-remap" the original to this, and find the difference from the original. All the pixels that are black were in the set; pixels any other colour weren't.
snibgo's IM pages: im.snibgo.com
Post Reply