Version: ImageMagick 6.6.2-6 2011-04-02 Q16 (as far as I can go on this OS)
Platform: Ubuntu Linux
API: shell command line
Thanks for the help with getting the black background right and the stamps not piling on top of each other....
viewtopic.php?f=1&t=24509
Now my problem is the "green shadow" (I am scanning on green background for "green screen" purposes) that is an artifact of using a flatbed scanner. One side (or more than one side it the stamp is at an angle) shows a shadow (in the original and in the result) that is caused by the way the scanner lights the subject and the fact that a stamp does have thickness, thus a shadow is created. After processing with the script, the shadow is still somewhat present and I have not been able to make it go away. If I manually color-select in Gimp, I can select all the shadow areas and fill them with black, with good result -- but that is much more time consuming than not using the whole background removal script in the first place.
(The reason/need for "background removal" is that the the stamps often have black postmarks on them that go to the edge of the stamp, which, when manually filling background with black, "eats into" the stamp. Thus I am experimenting with "green screen" or "chroma key" scanning on a colored background ... so that I can automatically process a large number of these images to fill the backgrounds with solid black.)
I am now using the bg_removal script from the IM website WITH MODFICATION of the background setting thanks to Fred (no other modifications yet). The script I am using is here:
http://jsa.viewimage.net/temp/im/bg_rem ... modified.s
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)
The command line is:
sh bg_removal_js-modified.s -n source.tif 30 7 result-2.tif
The -n (normalize) does not seem to make a difference one way or the other.
The 30 is the "fuzz out" (the pixels that will be classified as background). I have played with this number and up to a point (10?) increasing it helps reduce the "green shadow" but past a point increasing the number seems to have no effect.
The 7 is the "fuzz in" (the pixels that will be classified as foreground and which are part of the desired final image). Any higher than 7 and the black background starts to "eat into" the stamp area. Any less and the green shadow increases.
One off-the-wall idea I have, but absolutely do not have the skills to even know where to begin, to say nothing to executing it, is to create an image that represents the gradient of color in the shadow area of the original source. Then have the script include ALL the colors in that gradient (that are in the gradient zone, but not in the stamp itself) in the color(s) that the script is including in the background. However, somehow that approach seems very complicated and backwards.
I have yet to see a scanner that does not cause this problem. Scanners seem to be made to scan images/text ON an object (paper) instead of scanning the object itself (a stamp).
I welcome any suggestions.
Removing "green shadow" caused by flatbed scanner
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Removing "green shadow" caused by flatbed scanner
You have a tough problem because you have now different shades of green as anti-aliased along the edges. Furthermore, you background is not a constant color, perhaps due to scanning as jpg and converting to tiff. Or just because you used green paper and the paper texture changes the color.
Perhaps you would have been better using black paper background.
The best I can see is to floodfill colorize the background to black and then try using -morphology close to remove some of the outside color.
try something like the following though even that leaves some green around the edges.
convert source.tif -fuzz 20% -fill black -draw "color 0,0 floodfill" -morphology close octagon:2 result.png
If you had a perfect background, you could use -compose changemask, see http://www.imagemagick.org/Usage/masking/#known_bgnd
Perhaps you would have been better using black paper background.
The best I can see is to floodfill colorize the background to black and then try using -morphology close to remove some of the outside color.
try something like the following though even that leaves some green around the edges.
convert source.tif -fuzz 20% -fill black -draw "color 0,0 floodfill" -morphology close octagon:2 result.png
If you had a perfect background, you could use -compose changemask, see http://www.imagemagick.org/Usage/masking/#known_bgnd
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Removing "green shadow" caused by flatbed scanner
Another thought: it is probably more accurate to first chop out the individual stamps, and apply separate processing to each one. For each stamp, construct a background image from "-sparse-color" using the four corners of the image, then "-compose difference" so the background is now roughly black. Because each stamp is processed by itself the background will be blacker.
snibgo's IM pages: im.snibgo.com
Re: Removing "green shadow" caused by flatbed scanner
Frank, Thanks. That's what I was afraid of.
- The scanning is done using Vuescan and is in whatever its internal format is prior to be saved as tiff. At no point is the image file intentionally (by me) any format other than tiff. Any irregularity may come from the texture of the green paper (though it is not visible to the eye) and/or artifacts introduced by the scanner or Vuescan.
- I can't use a black background for scanning -- that is the whole point of all of this. Because some stamps have postmarks that reach the edge of the stamp, using a black background reults in "eating into" the design when making the background solid black. The only way we have found around that is manual selection / de-selection of the edge areas that are being "eaten into". And that is the time-consuming work that this whole exercise is trying to avoid.
I will experiment with your ideas. As for the "known background" method, I had studied all that before starting this exercise. Unfortunately, the scanner-caused-shadow is an aspect that is _not_ "known" in the way that this method needs.
====
Snibgo, Thanks.
I will experiment with chopping out first, but I am not sure how that will address the shadow problem.
I do have access to a high-speed, high-volume chopping-out program specifically designed for stamps, but unfortunately, it has to be run on Windows (but I can do that if I must). I was just hoping for a more bulk-oriented solution that would do more of the steps with less work and intervention.
- The scanning is done using Vuescan and is in whatever its internal format is prior to be saved as tiff. At no point is the image file intentionally (by me) any format other than tiff. Any irregularity may come from the texture of the green paper (though it is not visible to the eye) and/or artifacts introduced by the scanner or Vuescan.
- I can't use a black background for scanning -- that is the whole point of all of this. Because some stamps have postmarks that reach the edge of the stamp, using a black background reults in "eating into" the design when making the background solid black. The only way we have found around that is manual selection / de-selection of the edge areas that are being "eaten into". And that is the time-consuming work that this whole exercise is trying to avoid.
I will experiment with your ideas. As for the "known background" method, I had studied all that before starting this exercise. Unfortunately, the scanner-caused-shadow is an aspect that is _not_ "known" in the way that this method needs.
====
Snibgo, Thanks.
I will experiment with chopping out first, but I am not sure how that will address the shadow problem.
I do have access to a high-speed, high-volume chopping-out program specifically designed for stamps, but unfortunately, it has to be run on Windows (but I can do that if I must). I was just hoping for a more bulk-oriented solution that would do more of the steps with less work and intervention.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Removing "green shadow" caused by flatbed scanner
My script, multicrop, should be able to extract and even un-rotate your stamps. But it will still leave the anti-aliased green that is mixed in with the edges of the stamps.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Removing "green shadow" caused by flatbed scanner
See if this works for you. I found the color of the border of the stamps and created an edge image just inside the outside of the stamps and replaced that edge region with the good color of the stamp border.
convert source.tif \
\( -clone 0 -fuzz 19% -fill black -draw "color 0,0 floodfill" -alpha off \) \
\( -clone 0 -fill "rgb(211,201,177)" -colorize 100 \) \
\( -clone 0 -fuzz 19% -fill none -draw "matte 0,0 floodfill" \
-background black -alpha background \
-fill white +opaque "rgba(0,0,0,0)" -alpha off \
-morphology edgein octagon:2 \) \
-delete 0 -compose over -composite source2.png
convert source.tif \
\( -clone 0 -fuzz 19% -fill black -draw "color 0,0 floodfill" -alpha off \) \
\( -clone 0 -fill "rgb(211,201,177)" -colorize 100 \) \
\( -clone 0 -fuzz 19% -fill none -draw "matte 0,0 floodfill" \
-background black -alpha background \
-fill white +opaque "rgba(0,0,0,0)" -alpha off \
-morphology edgein octagon:2 \) \
-delete 0 -compose over -composite source2.png