Page 1 of 2
NEF to PNG (PNG 6x larger file size)
Posted: 2012-01-17T00:48:41-07:00
by syntax
While converting Nikon RAW format .NEF files (taken with D40) to PNG with ImageMagick, I get PNG files that are roughly 6 times larger than the original "raw" images. That doesn't make any sense to me. The camera lists the mode as .NEF (RAW) and does not specify lossy/lossless or compressed/uncompressed. Theoretically lossless compression (PNG) should be smaller than RAW format images, unless I'm missing something.
Code: Select all
> convert DSC_0001.NEF DSC_0001.png
> ls -lah
-rw-r--r-- 1 5.4M 2011-12-03 17:21 DSC_0001.NEF
-rw-rw-r-- 1 29M 2012-01-17 00:29 DSC_0001.png
I've also tried using ufraw-batch to convert .NEF to .PPM. I then convert PPM to PNG and get more reasonable file sizes. However, they are still 1-2 MB larger than the original raw .NEF files. Does anyone have any insight into why this is occurring?
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2012-01-17T11:26:28-07:00
by glennrp
syntax wrote:While converting Nikon RAW format .NEF files (taken with D40) to PNG with ImageMagick, I get PNG files that are roughly 6 times larger than the original "raw" images. That doesn't make any sense to me. The camera lists the mode as .NEF (RAW) and does not specify lossy/lossless or compressed/uncompressed. Theoretically lossless compression (PNG) should be smaller than RAW format images, unless I'm missing something. ... Does anyone have any insight into why this is occurring?
Wikipedia (see
http://en.wikipedia.org/wiki/Raw_image_format) says "When converting from the four sensor 2x2 Bayer matrix raw form into single RGB pixels the original 4x12 (or 14) bit data is converted to 4x3x8 bit"
That doubles it. If you happen to write 16-bit PNG files, that doubles it again. You could try using the "-depth 8" option to avoid the second doubling (which is the same as what happens when you convert to the intermediate PPM format).
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T10:33:11-07:00
by nitingeetasagar
I'm also having the same problem. That explains a few things. But I'm unsure about the remaining 2x increase is size. I converted a 11MB NEF to PNG and to my surprise the size became approx. 60MB.. What is causing this?
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T10:40:39-07:00
by fmw42
If you are on Q16 IM, then try adding -depth 8
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T10:44:09-07:00
by snibgo
PNG doesn't give good compression for photographs. It's actually quite poor for photos.
Another possible factor: NEF files can be compressed or not, and the compression can be lossy or not. A lossy NEF file will certainly be smaller than a PNG made from it.
I use 16-bit tiff files with zip compression, and these are generally about 4x the size of the NEF files. I did a load of tests to determine the best lossless compression, and found that zip tiff was the best.
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T10:45:36-07:00
by nitingeetasagar
So now it became 16.2 MB from 11 MB. It is still more than the Raw file.
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T10:53:21-07:00
by nitingeetasagar
How can I know whether a NEF is lossy or not? And I wanted a loseless compression from NEF and thats the reason I converted it into PNG. Yep I understood with whatever that you were trying to tell. PNG will be more if you choose a 16 bit depth from a 8 bit NEF, but that should only double the size as far as I understood. What it is causing to go up 6 times than NEF?
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T11:12:14-07:00
by snibgo
Exiftool or Nikon's ViewNX 2 can tell you if the NEF is lossy or lossless.
Code: Select all
D:\pictures\20130713>exiftool -Nikon:NEFCompression aga_1434.nef
NEF Compression : Lossless
PNG compression wasn't designed for photos but for graphics. NEF compression was designed for photos.
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T12:06:28-07:00
by fmw42
You could try to convert to tiff with compression. It supports a number of compression modes.
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T15:32:55-07:00
by nitingeetasagar
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T15:49:39-07:00
by fmw42
PNG and NEF may be lossless, they probably use different lossless compression algorithms and likely the NEF compression is larger than the PNG compression, so PNG files are larger, since they are not compressed as much. Just my guess!
P.S. You can change the PNG compression amount -- see
http://www.imagemagick.org/script/comma ... hp#quality. I know nothing about NEF.
see
http://www.coolutils.com/Formats/NEF. Perhaps you have 12-14 bit data, but when converted to PNG it becomes 16-bits if on Q16 IM. Also possibly there are some meta data in the NEF that is compressed as well and not compressed in the PNG result.
Again these are all guesses on my part.
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-06T18:26:40-07:00
by glennrp
The D40 Nikon is a 6MP camera. Your NEF file is 5.4Mbytes, which is less than 8 bits per pixel so your "raw"
image is actually compressed. Converting a lossy image to lossless is a losing proposition. You are better off
converting to high-resolution JPEG instead.
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-07T09:28:26-07:00
by nitingeetasagar
what happens when a nef is converted to jpeg? Will Bayers filter affect that as well?
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-07T09:48:01-07:00
by snibgo
Convert to JPEG and you will lose data. (a) JPEG is only 8-bit so you lose nearly half the bits. (b) JPEG is lossy. For low quality, it is very lossy, but needs not much disk space. You can experiment with different "-quality" settings. Very low quality will be smaller than NEF.
I don't see the point of capturing a NEF file and simply converting it to JPEG. Why not tell the camera to save it as JPEG?
Re: NEF to PNG (PNG 6x larger file size)
Posted: 2013-12-07T10:03:05-07:00
by nitingeetasagar
I was just experimenting In conversion from RAW format to jpeg,png and webp. So now only png is greater among the three. I just want to find out the reasons!!
So as PNG will be affected by Bayers filters which causes the mapping of 2 RGBG to a single RGB. Why its not doing the same in JPEG and WEBP?