Hi,
This is my first post. Sorry about it but I never used ImageMagick command line before so I'm not very used to the different options and possibilities.
Basically, I need to clean up an image to pass it through an OCR. This image has a gray background at the top that it's causing problems so I want to get rid of it. I need to get the text within the rectangles so hopefully filtering somehow the gray background will make the task easier. I tried different ways using the convert command with monochrome and threshold options but with no luck.
This is a sample image: http://img687.imageshack.us/img687/4535/facturam.png You can find at the very top the data I want to extract. "Factura" and date.
Any hints?
Help with filtering an image
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Help with filtering an image
Median will help, eg "-median 1 -threshold 67%".
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Help with filtering an image
If you are on Unix, you can try my textcleaner script at the link below. I have not tried it on your image, yet.
P.S. Never mind, I just tried it and it does not help and is way too slow with such a large image.
P.S. Never mind, I just tried it and it does not help and is way too slow with such a large image.
Re: Help with filtering an image
Hi snibgo and fmw42, thanks for your answering back.
I tried with -median and threshold: "convert factura2.tif -median 1 -threshold 67% factura2b.tif" but unfortunately didn't worked as expected. In fact it returns the same result as I was getting by using only -threshold. Image turns completely black:

Best.
I tried with -median and threshold: "convert factura2.tif -median 1 -threshold 67% factura2b.tif" but unfortunately didn't worked as expected. In fact it returns the same result as I was getting by using only -threshold. Image turns completely black:

Best.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Help with filtering an image
Using the image you supplied above,
convert facturam.png -median 1 -threshold 67% f2.png
removes the required grey background, leaving the letters intact. This is on IM 6.6.0-8 in Windows 7.
What version IM are you on? If old, try an upgrade. What platform? If Windows using command files, don't forget to double the percent sign.
convert facturam.png -median 1 -threshold 67% f2.png
removes the required grey background, leaving the letters intact. This is on IM 6.6.0-8 in Windows 7.
What version IM are you on? If old, try an upgrade. What platform? If Windows using command files, don't forget to double the percent sign.
snibgo's IM pages: im.snibgo.com
Re: Help with filtering an image
Hi snibgo,
I'm using IM 6.3.7 on Ubuntu Linux. It may also be that the original image file is a .tif (imageshack convers it to png when uploaded)
Updated: Yes, it is the fact of being a .tif image. Tried as you mentioned with the PNG image and it worked.
Martin
I'm using IM 6.3.7 on Ubuntu Linux. It may also be that the original image file is a .tif (imageshack convers it to png when uploaded)
Updated: Yes, it is the fact of being a .tif image. Tried as you mentioned with the PNG image and it worked.
Martin
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Help with filtering an image
Your IM is old. I suggest you upgrade.
I converted the png to a tif, and it works for me:
But your orignal tif may have some other issue. If you provide a URL to it, I can try it out.
I converted the png to a tif, and it works for me:
Code: Select all
D:\web\im>"%IMG%convert" facturam.png facturam.tif
D:\web\im>"%IMG%convert" facturam.tif -median 1 threshold 67% f2.png
snibgo's IM pages: im.snibgo.com
Re: Help with filtering an image
No bother, I could not send the original because it has personal data within. But I get your point. Will try also to update IM.
Thanks very much for your help!
Thanks very much for your help!