Page 1 of 1

Convert to 300dpi

Posted: 2010-09-27T18:44:13-07:00
by galv
1. I have images that I want to feed to an OCR engine. The OCR states that the optimal recognition happens when the given image is at 300dpi. How can I convert any image to 300dpi? How can I calculate how much scaling it needs in order to be at 300dpi?

2. Second related question: How can I calculate how many dpi is my screen?

Re: Convert to 300dpi

Posted: 2010-09-27T21:57:23-07:00
by anthony
-resample 300

See IM examples, resize, resample
http://www.imagemagick.org/Usage/resize/#resample

As for your screen -- measure it! it is typically (these days) 90 to 120 dpi. Remember dpi = Dots per inch! Yes it is a little archaic.

Re: Convert to 300dpi

Posted: 2010-09-28T17:49:45-07:00
by galv
Thanks once again anthony!

1. I used -resample 300 (end image is about 700% bigger) and the OCR result is actually 1 error more than the -scale 400% method (end image is 400% bigger).
Does -resample use a different algorithm for scaling from -scale?

2. How can I measure my screen? I don't understand.

Re: Convert to 300dpi

Posted: 2010-09-28T18:01:50-07:00
by fmw42
2. How can I measure my screen? I don't understand.
Get the resolution from the display such as 1024x920 pixels.
Get the physical dimension of width and length in inches using a ruler.
Divide the width in pixels by the width in inches (or the height in pixels by height in inches).

Re: Convert to 300dpi

Posted: 2010-09-28T20:07:11-07:00
by anthony
galv wrote: I used -resample 300 (end image is about 700% bigger) and the OCR result is actually 1 error more than the -scale 400% method (end image is 400% bigger).
Does -resample use a different algorithm for scaling from -scale?
-resample uses a -resize, with the new size calculated using the resoultion.
If the input image has no resolution set it has a default resolution of 72 dpi which is probably wrong!!!!

To give the the input image a initial resolution, use...

Code: Select all

  convert -density ??? {image}
-resize however creates new colors to give the image a smooth look. You may need to threshold or 'unsharp' the result for OCR use.

-scale (or even -sample for enlargement) only doubles up pixel rows and columns so if the input was a bitmap, output is a bitmap.

Re: Convert to 300dpi

Posted: 2010-10-05T17:01:13-07:00
by galv
Is there a way to make -resample use a -scale instead of a -resize?

Re: Convert to 300dpi

Posted: 2010-10-05T17:05:09-07:00
by fmw42
just use -scale and -density to get the pixel resolution and density you want.

Re: Convert to 300dpi

Posted: 2010-10-05T17:53:52-07:00
by dproc
I suspect the OCR code means by "optimal" that it runs the fastest assuming a reasonably-sized font, not necessarily the most reliably. Try to avoid resampling unless you are hurting for speed. I'd be VERY surprised if the OCR code actually got more reliable after you downsampled! Secondly, DPI should not be confused with resolution. Some file formats include a DPI value and others do not. The DPI is strictly for indicating print and display sizing. For file types that do not include that (and for some print drivers and display apps that ignore the DPI in a file, if its there) the image will be displayed (printed) one-to-one pixels by default. If you're concerned about both reliability and speed, then I recommend ignoring that statement about DPI and just experimenting.