Page 1 of 1

Removing the background

Posted: 2015-07-07T04:37:03-07:00
by plopsausage
Hello

I am scanning a library card catalogue and there has been a problem with the scanner. The result has been that the card has been scanned but it is a small part of the resulting scanned image.
To further complicate matters the card does not always appear in the same spot in the scanned image.
The problem we have is that we are aiming to run these through an OCR so that we can produce a text file. When i have attempted to run them through an OCR the results are rubbish. If i manually remove the unwanted area and then re read them the resulting text file is far better.
I don't really want to re scan the cards if i can help it so was wondering is there are any ways i can remove the unwanted areas in batch mode using imagemagick.
The background is not a uniform colour, it is generally darker than the card image, which is almost always white, with a few blue and purple cards thrown in.

Any ideas? Or do i go back to the scanner and try and sort out why it is producing the images this way?

Re: Removing the background

Posted: 2015-07-07T04:41:18-07:00
by Bonzo
I would recommend linking to at least one image as you will not get any useful response until people can view and try one.

The imagemagick version as well as the platform/operating system information would also be useful.

Re: Removing the background

Posted: 2015-07-07T05:04:58-07:00
by plopsausage
Hi Bonzo

Thanks

An example can be seen here: https://drive.google.com/file/d/0BxcyzL ... sp=sharing

I am using Ubuntu 12.04.4

Imagemagick version 6.6.9

Re: Removing the background

Posted: 2015-07-07T05:26:58-07:00
by snibgo
Try:

Code: Select all

convert image_-009.jpg -fill White -fuzz 60% -draw "color 0,0 floodfill" -fuzz 5% -trim -contrast-stretch 1%,50% x.png

Re: Removing the background

Posted: 2015-07-07T09:57:25-07:00
by fmw42
I think you should be able to do the same command using mogrify to process every image in a folder. Make a new folder, say folder2 to hold the output. Assume your images are in folder1.

Code: Select all

cd folder1
mogrify -path pathto/folder2 -format png -fill White -fuzz 60% -draw "color 0,0 floodfill" -fuzz 5% -trim -contrast-stretch 1%,50% *.jpg
This will process every jpg file in your folder1 and make the same named image in folder2 as png

see http://www.imagemagick.org/Usage/basics/#mogrify