Convert to 300dpi

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
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Convert to 300dpi

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert to 300dpi

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Convert to 300dpi

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert to 300dpi

Post 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).
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert to 300dpi

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Convert to 300dpi

Post by galv »

Is there a way to make -resample use a -scale instead of a -resize?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert to 300dpi

Post by fmw42 »

just use -scale and -density to get the pixel resolution and density you want.
dproc
Posts: 19
Joined: 2010-09-14T20:39:15-07:00
Authentication code: 8675308

Re: Convert to 300dpi

Post 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.
Post Reply