SOLVED Is image density an actual feature of an image,or merely a means of defining the size of the image in the viewer?

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
porphyry5
Posts: 12
Joined: 2011-05-22T10:06:09-07:00
Authentication code: 8675308

SOLVED Is image density an actual feature of an image,or merely a means of defining the size of the image in the viewer?

Post by porphyry5 » 2019-03-25T17:21:34-07:00

Would someone kindly explain to me the purpose of -resample. As I understand the option it is a simultaneous resizing and reset of the density of the image, so that the resampled image will occupy the same physical dimensions when presented in a different viewing device.

Which begs the question, why bother to resize at all, why not keep the original image and simply declare its density to be that desired on the new viewer? Because, by resizing the image by -resample, there is no actual change in the number of pixels (dots) per inch, that is determined only when it is viewed.
Last edited by porphyry5 on 2019-03-26T13:26:09-07:00, edited 1 time in total.

snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by snibgo » 2019-03-25T17:33:19-07:00

porphyry5 wrote:Would someone kindly explain to me the purpose of -resample. As I understand the option it is a simultaneous resizing and reset of the density of the image, ...
Correct.
porphyry5 wrote:...so that the resampled image will occupy the same physical dimensions when presented in a different viewing device.
Yes, provided the display software respects the density setting.

However, when displaying an image on the screen, most software will ignore the density setting.
snibgo's IM pages: im.snibgo.com

porphyry5
Posts: 12
Joined: 2011-05-22T10:06:09-07:00
Authentication code: 8675308

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by porphyry5 » 2019-03-26T12:16:39-07:00

snibgo wrote:
2019-03-25T17:33:19-07:00
porphyry5 wrote:Would someone kindly explain to me the purpose of -resample. As I understand the option it is a simultaneous resizing and reset of the density of the image, ...
Correct.
porphyry5 wrote:...so that the resampled image will occupy the same physical dimensions when presented in a different viewing device.
Yes, provided the display software respects the density setting.

However, when displaying an image on the screen, most software will ignore the density setting.
Thank you for your response, so I take it that -density has no actual meaning beyond being a hint to polite software to display the image at a particular size?

snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by snibgo » 2019-03-26T12:26:08-07:00

Yes.

Personally, for my image processing, I usually deal in pixels, not inches or centimetres or whatever. The density and physical dimensions are rarely of any importance.
snibgo's IM pages: im.snibgo.com

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

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by fmw42 » 2019-03-26T12:35:23-07:00

Density and physical dimensions are generally only important for printing, but not for display or further processing of the images.

Note that vector files such as SVG, EPS, PDF, PS etc will be rasterized and so will need to have some density set before reading the vector file so that ImageMagick knows how finely to rasterize (convert to pixels) and thus how large the raster image dimension will be.

porphyry5
Posts: 12
Joined: 2011-05-22T10:06:09-07:00
Authentication code: 8675308

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by porphyry5 » 2019-03-26T13:04:28-07:00

snibgo wrote:
2019-03-26T12:26:08-07:00
Yes.

Personally, for my image processing, I usually deal in pixels, not inches or centimetres or whatever. The density and physical dimensions are rarely of any importance.
Many thanks. I'm sorry if I've been overly persistent on this point, but my end objective is ocr to text with tesseract, which asserts that its ideal density is 300 dpi, but without enlarging on the point. But in practice changing the density made no improvement, and I assumed I was missing some other unstated information. I think it must be important only when starting from a paper document.

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

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by fmw42 » 2019-03-26T13:10:53-07:00

As I understand it, the only time you might need a density of 300 dpi is if you started with a vector image. For example if you scanned into a PDF format. Then you would need to specify the density in order to rasterize the PDF file. (Alternately extract any imbedded raster image from within the PDF). See my post above about vector image formats.

For example:

Code: Select all

convert -density 300 -units pixelsperinch image.pdf image.png

porphyry5
Posts: 12
Joined: 2011-05-22T10:06:09-07:00
Authentication code: 8675308

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by porphyry5 » 2019-03-26T13:18:43-07:00

fmw42 wrote:
2019-03-26T12:35:23-07:00
Density and physical dimensions are generally only important for printing, but not for display or further processing of the images.

Note that vector files such as SVG, EPS, PDF, PS etc will be rasterized and so will need to have some density set before reading the vector file so that ImageMagick knows how finely to rasterize (convert to pixels) and thus how large the raster image dimension will be.

As I understand it, the only time you might need a density of 300 dpi is if you started with a vector image. For example if you scanned into a PDF format. Then you would need to specify the density in order to rasterize the PDF file. (Alternately extract any imbedded raster image from within the PDF). See my post above about vector image formats.

For example:

Code: Select all

convert -density 300 -units pixelsperinch image.pdf image.png
Thank you for your help, all this is to improve my success with tesseract ocr-ing screen-shots of firefox windows to extract their text content. Trial and error has led me to using tiff files exclusively, and as I'm not printing anything, I think now I can safely ignore image density as a factor in that.

snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is image density an actual feature of an image, or merely a means of defining the size of the image in the viewer?

Post by snibgo » 2019-03-26T13:34:50-07:00

porphyry5 wrote:... my end objective is ocr to text with tesseract, which asserts that its ideal density is 300 dpi, but without enlarging on the point.
In my limited experience of OCR, the height of capital letters such as HIM should be at least 20 pixels high. Smaller characters give less accuracy. The pixels per inch of the raster image has no importance, as such, but are relevant when typed documents are scanned, eg if a paper document has 8 text lines per inch, the capital height will be about 0.1 inches, so needs scanning at 200 dpi or more to ensure we have 20 pixels per capital.

As Fred says, when reading a vector format, the density setting before rasterizing the input file is important, but can be changed in the resulting raster image.
snibgo's IM pages: im.snibgo.com

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

Re: SOLVED Is image density an actual feature of an image,or merely a means of defining the size of the image in the vie

Post by fmw42 » 2019-03-26T14:45:54-07:00

snibgo is correct. I forgot about the density needed when scanning a document into raster format. So if you were told to scan at 300 dpi, then go ahead and do that. As snibgo said, the larger the text, the better the OCR. Of course you need to balance that against file size if you are going to save the scanned documents.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SOLVED Is image density an actual feature of an image,or merely a means of defining the size of the image in the vie

Post by anthony » 2019-03-26T17:14:39-07:00

Image Density or Resolution
http://www.imagemagick.org/Usage/basics/#density
The density of an image is completely irrelevant to the actual images pixel size. It is just a set of numbers stored with the image to tell output devices such as printers and displays how many dots (or pixels) per inch the image should be displayed at, OR for vector formats like postscript, PDF, MWF, and SVG the pixel scale to draw using any real world coordinates that may be used within the image.

For more information on Resolution and Density of images see the notes on the Resample Resize Operator. For information of Resolution and Density for Text and Fonts see Pointsize and Actual Font Size.
Resample - Changing an image's resolution
http://www.imagemagick.org/Usage/resize/#resample

Pointsize, Density and the Actual Font Size (or images)
http://www.imagemagick.org/Usage/text/#pointsize

Aside: I have updated the 'basic' description which seems to have a lot of duplication of description to make it work better. This will appear in couple of hours or so.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply