Increasing DPI results in doubling of image size

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
ryboto
Posts: 5
Joined: 2016-11-02T11:37:34-07:00
Authentication code: 1151

Increasing DPI results in doubling of image size

Post by ryboto »

I'll start off by letting you know I'm new to Imagemagick.

What I'm trying to do with the software is change the dpi of scanned images. Ideally I'd like to apply a horizontal and vertical dpi, as our image has different horizontal and vertical pixel dimensions, but it's fine if square pixels are my only option. Anyway, the camera has a object pixel size of ~5.2um/pixel, or 4880dpi. The images are 8192x9216, and about 73MB each. When I open them in Photoshop, the program reports 72dpi as the pixel size.

The issue is that when I load them into our image analysis software, it sees the image as 96x96dpi, which causes the physical scale to be much too large. If I resize the dpi in photoshop by setting the physical width to 1.68 inches, the image opens properly in our image analysis software. The dpi is a little off at ~4875dpi, but that's fine. So, of course, I COULD use photoshop and batch process, but opening 73MB images is painfully slow from our network.

I have been able to edit the dpi with Imagemagick through two different lines of code. The issue is that through either method, the image size goes up to 136MB, while with photoshop, the image size stays the same. I'd like to use Imagemagick for the speed and convenience of being able to incorporate into a scripted action, but the file size increase isn't going to work.

Here is the code:

Code: Select all

mogrify -density 4884x3907 -units PixelsPerInch C:\2\*.bmp
and

Code: Select all

Convert C:\2\image.bmp -units PixelsPerInch -density 4884 C:\2\out.bmp
I've also tried -set density, and sometimes, the dpi shows up as 12405.4, which is 2.54 times the dpi I'm trying to set...obviously a units issue. Still, the code works, and the pixel size does reduce so that the print size is 1.6777 x 1.89 inches, but the file size increases.

Is there any way to keep the file size from going up? I would think that reducing the dpi would cause it to increase, because then the print size would be much larger, right?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Increasing DPI results in doubling of image size

Post by snibgo »

"-density" doesn't change the number of pixels. If the filesize (in bytes) changes significantly, I suspect the compresson method has changed. What does "identify" say about compression? Have you tried "-compress XXX"?
snibgo's IM pages: im.snibgo.com
ryboto
Posts: 5
Joined: 2016-11-02T11:37:34-07:00
Authentication code: 1151

Re: Increasing DPI results in doubling of image size

Post by ryboto »

Thanks for the reply. I'm not trying to change the number of pixels, just the dpi/print area.

I ran identify and the output was:
BMP3 8192x9216 8129x9216+0+0 8-bit sRGB 256c 75.5MB 0.437u 0:00.275

I have not tried -compress, not exactly sure how to use it.
ryboto
Posts: 5
Joined: 2016-11-02T11:37:34-07:00
Authentication code: 1151

Re: Increasing DPI results in doubling of image size

Post by ryboto »

If I use the -verbose command, it lists "Compression: None"... is that useful information?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Increasing DPI results in doubling of image size

Post by snibgo »

You have one file that is 73 MB.

You convert it with IM, and the result is 136 MB. You want to know why it is larger.

Telling me that one of them (which one?) is not compressed only partly answers the question.
snibgo's IM pages: im.snibgo.com
ryboto
Posts: 5
Joined: 2016-11-02T11:37:34-07:00
Authentication code: 1151

Re: Increasing DPI results in doubling of image size

Post by ryboto »

The original image is showing up as uncompressed, sorry. So that's the 73MB image.

The altered image with the adjusted DPI, the 136MB image, identify -verbose reports "Compression: RLE".
ryboto
Posts: 5
Joined: 2016-11-02T11:37:34-07:00
Authentication code: 1151

Re: Increasing DPI results in doubling of image size

Post by ryboto »

I tried this:

Code: Select all

mogrify -density 4880 -units PixelsPerInch -compress None C:\2\*.bmp
As I'd prefer to use mogrify vs convert for batches of images, and this resulted in images that were the same 73MB as the original, but their DPI reports as 4880 in Photoshop.

So...I think this is solved! Thanks!!
Post Reply