Remove white spot

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
gvandyk
Posts: 15
Joined: 2015-09-08T12:40:32-07:00
Authentication code: 1151

Remove white spot

Post by gvandyk »

Hi

I am busy scanning books with a book scanner using 2 cameras and a central light source. A reflective glass is covering the pages in order to press the pages flat. On all the images the central light leaves a small white spot on the resulting images.

How can this spot be removed?

I need to process thousands of pages, and the spot is not always in the same place, so I would need some generic way of removing the spot.

Here is an example of one of the images:

https://www.dropbox.com/s/fjqqpbk8r8e2xjo/spot.jpg

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove white spot

Post by fmw42 »

What is your version of IM and platform?

If on Unix, try using my script, textcleaner, to make the whole background white. That should make your white spot blend into the white background.

Otherwise, try IM

Code: Select all

convert image -negate -lat 20x20+10% -negate result
to achieve something similar.
gvandyk
Posts: 15
Joined: 2015-09-08T12:40:32-07:00
Authentication code: 1151

Re: Remove white spot

Post by gvandyk »

HI

Thank you very much, that works well when I convert the image to do text extraction etc, and thank you very much, we are already using your script.

But: We need to provide the original color image as well, as these are very old artefacts dating back to the mid 18:00 in some cases. There are markings on the paper and the authenticity needs to be kept on the originals.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove white spot

Post by snibgo »

It may be difficult to remove automatically, without leaving a trace.

Do you have a better quality image? JPEG introduces junk and makes the problem even more difficult.
snibgo's IM pages: im.snibgo.com
gvandyk
Posts: 15
Joined: 2015-09-08T12:40:32-07:00
Authentication code: 1151

Re: Remove white spot

Post by gvandyk »

Unfortunately the JPEG is the only image that we have currently. The cameras only produce JPEG.

We don't mind leaving a little trace on the image, as this is understandable, but the spot needs to "almost" disappear.
gvandyk
Posts: 15
Joined: 2015-09-08T12:40:32-07:00
Authentication code: 1151

Re: Remove white spot

Post by gvandyk »

I can get the area that should be changed with the -threshold parameter.

convert input.jpg -threshold 87% -negate output.png

The next hurdle to overcome would be, is to make those pixels under the "threshold" black area to be X % darker.

I've managed to replace those pixels by a different color, but I don't know how to darken the pixels relative to the "brightness" of the pixels.

Any ideas?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove white spot

Post by fmw42 »

see -mask at http://www.imagemagick.org/Usage/masking/#special_masks and -brightness-contrast at http://www.imagemagick.org/script/comma ... s-contrast

Code: Select all

convert input.jpg -threshold 87% -negate mask.png 
convert input.jpg -mask mask.png -brightness-contrast X,Y +mask result.png
or

Code: Select all

convert input.jpg \
\( -clone 0 -threshold 87% -negate -write mpr:mask +delete \) \
-mask mpr:mask -brightness-contrast X,Y +mask result.png
gvandyk
Posts: 15
Joined: 2015-09-08T12:40:32-07:00
Authentication code: 1151

Re: Remove white spot

Post by gvandyk »

Thanks Fred

I eventually used 83% for threshold, 23 for brightness and -50 for contrast. The spot is much less and are within the acceptable parameters.

So the following is working ok:

Code: Select all

convert input.jpg \
\( -clone 0 -threshold 83% -negate -write mpr:mask +delete \) \
-mask mpr:mask -brightness-contrast 23,-50 +mask result.png
Post Reply