bg_removal script piles parts of image on top of each other
Posted: 2013-11-24T17:06:14-07:00
Version: ImageMagick 6.5.7-8 2012-08-17 Q16
Platform: Ubuntu Linux
API: shell command line
I make very large quantities of images of postage stamps for illustration purposes. The final result images of the postage stamps need to be a black background, like this:
http://jsa.viewimage.net/jsa/web/Lists/ ... 01_r_m.jpg
Sometimes the image shows only one stamp, sometimes several stamps.
*Often* the stamps are canceled/postmarked with a black postmark/cancellation that extends over the edge, like this:
http://jsa.viewimage.net/jsa/web/Lists/ ... 74_r_m.jpg
When the stamp images are scanned, there are *many* stamps in one scan. They are later divided up as appropriate.
Up until this time, the scanning has been done on a "black" (never is completely black) background. The background is then color-filled solid black in Gimp to get the pure black background.
However, when the black postmark/cancellation goes to the edge of the stamp, the black-filling "eats into" to stamp design, which is not desirable. No amount of threshold setting gets around that classic problem. Thus those situations have to be manually-selected or de-selected & black-filled in Gimp to make sure the black-fill does not "eat into" the stamp design.
For this reason, I have been experimenting with "chroma key" or "green screen" methods, using ImageMagick convert.
I found extensive and useful discussion of these methods starting here: http://www.imagemagick.org/Usage/masking/#bg_remove
I have read carefully and experimented. The results so far are extremely poor, but the biggest problem is that the *several* stamps in the image are become piled on top of each other.
I first tried the most simple methods (rather than the bg_removal script shown here: http://www.imagemagick.org/Usage/scripts/bg_removal )
However, both the simple scripts and the bg_removal script have approximately the same result ... everything piled on top of each other.
I can get a nice black background with the bg_removal script, but the stamps are all in a pile.
The problem seems to be related to the -compose and/or -composite. I have read and re-read the web pages about those, but I have not been able to understand what is going wrong.
IMAGE STARTS WITH:
*** I am posting a JPEG version for 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 (6 MB)
IMAGE FINAL RESULT IS (WRONG):
http://jsa.viewimage.net/temp/im/result_threshold.jpg
The result *should* be just like the starting image, but with a black background.
Right now I am not concerned with the horrible color/pattern of the result -- just the fact that the stamps are all become piled on top of each other.
I suspect that this method would not have this problem if the source.tif were a single stamp, instead of a group of stamps, however, the whole point of using this type of process is to be able to process a large group of stamps (and then cut them apart and rotate them at a later stage).
The simple scripts, taken from http://www.imagemagick.org/Usage/masking/#difference are as follows:
I have only changed the file names.
####################
# create difference.tif which is only used for the subsequent step
convert source.tif \( +clone -fx 'p{0,0}' \) \
-compose Difference -composite \
-modulate 100,0 -alpha off difference.tif
# create threshold_mask.tif
convert difference.tif -threshold 15% threshold_mask.tif
# create result.tif using threshold_mask.tif
convert source.tif threshold_mask.tif \
-alpha off -compose CopyOpacity -composite \
result_threshold.tif
#####################
Alternative script-based methods are also very welcome, but the examples in http://www.imagemagick.org/Usage/masking/#difference were so good that I was hoping that method could work.
Thanks for any help on this.
Platform: Ubuntu Linux
API: shell command line
I make very large quantities of images of postage stamps for illustration purposes. The final result images of the postage stamps need to be a black background, like this:
http://jsa.viewimage.net/jsa/web/Lists/ ... 01_r_m.jpg
Sometimes the image shows only one stamp, sometimes several stamps.
*Often* the stamps are canceled/postmarked with a black postmark/cancellation that extends over the edge, like this:
http://jsa.viewimage.net/jsa/web/Lists/ ... 74_r_m.jpg
When the stamp images are scanned, there are *many* stamps in one scan. They are later divided up as appropriate.
Up until this time, the scanning has been done on a "black" (never is completely black) background. The background is then color-filled solid black in Gimp to get the pure black background.
However, when the black postmark/cancellation goes to the edge of the stamp, the black-filling "eats into" to stamp design, which is not desirable. No amount of threshold setting gets around that classic problem. Thus those situations have to be manually-selected or de-selected & black-filled in Gimp to make sure the black-fill does not "eat into" the stamp design.
For this reason, I have been experimenting with "chroma key" or "green screen" methods, using ImageMagick convert.
I found extensive and useful discussion of these methods starting here: http://www.imagemagick.org/Usage/masking/#bg_remove
I have read carefully and experimented. The results so far are extremely poor, but the biggest problem is that the *several* stamps in the image are become piled on top of each other.
I first tried the most simple methods (rather than the bg_removal script shown here: http://www.imagemagick.org/Usage/scripts/bg_removal )
However, both the simple scripts and the bg_removal script have approximately the same result ... everything piled on top of each other.
I can get a nice black background with the bg_removal script, but the stamps are all in a pile.
The problem seems to be related to the -compose and/or -composite. I have read and re-read the web pages about those, but I have not been able to understand what is going wrong.
IMAGE STARTS WITH:
*** I am posting a JPEG version for 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 (6 MB)
IMAGE FINAL RESULT IS (WRONG):
http://jsa.viewimage.net/temp/im/result_threshold.jpg
The result *should* be just like the starting image, but with a black background.
Right now I am not concerned with the horrible color/pattern of the result -- just the fact that the stamps are all become piled on top of each other.
I suspect that this method would not have this problem if the source.tif were a single stamp, instead of a group of stamps, however, the whole point of using this type of process is to be able to process a large group of stamps (and then cut them apart and rotate them at a later stage).
The simple scripts, taken from http://www.imagemagick.org/Usage/masking/#difference are as follows:
I have only changed the file names.
####################
# create difference.tif which is only used for the subsequent step
convert source.tif \( +clone -fx 'p{0,0}' \) \
-compose Difference -composite \
-modulate 100,0 -alpha off difference.tif
# create threshold_mask.tif
convert difference.tif -threshold 15% threshold_mask.tif
# create result.tif using threshold_mask.tif
convert source.tif threshold_mask.tif \
-alpha off -compose CopyOpacity -composite \
result_threshold.tif
#####################
Alternative script-based methods are also very welcome, but the examples in http://www.imagemagick.org/Usage/masking/#difference were so good that I was hoping that method could work.
Thanks for any help on this.