How can I compress in terms of pixels not file size?

Started 2 months ago | Questions thread
NAwlins Contrarian Veteran Member • Posts: 5,955
Re: Very specific suggestion
4

Thank you, yes that was precisely what I was trying to achieve.

You're welcome.

One further question: Do you know if it is possible to take a png file and convert it to its raw components? I know its a very messy and roundabout thing to do, but I don't have access to the original raw files, but since png is lossless compression, each pixel should still be the correct colour, and I need a raw version to illustrate how large the file would be initially.

No, it is categorically impossible to convert a PNG into a raw file. The raw data is not even RGB data, but (typically) R-G-B-G pixels that need to be de-mosaiced and color-balanced. Also, AFAIK the vast majority of PNGs are only 8 bits per channel, but raw files are typically 12 or 14 bits per channel.

If that didn't make sense, to put it another way, I have a 459.2KB png image of 954x954 pixels. The Bit depth is 4-bits per channel/12-bits per pixel. I need a file that represents the full uncompressed data which would be (954 x 954 x 12)/8 Bytes large, which equates to 1,365KB. My working assumption is that is what the 'raw' file means, but all online png to raw converters either do not work or give a result that is even smaller in storage size

You appear to have some misunderstandings about raw files and file sizes. If you have a PNG of 459 KB for a 954x954 pixel image, it is almost certainly compressed, but 8 bits per channel. Just to point out, 4 bits per channel would only give you 4096 possible colors, i.e., very poor image quality by any reasonably-modern standard. If the PNGs are lossless, then very likely you have 8-bit-per-RGB channel data compressed almost 6:1, which I tend to suspect may be lossy.*

As hinted at above, a raw file is something else entirely. It contains (basically) the output of the sensor's analog-to-digital converter for each sensor pixel. But in the vast majority of cameras, each sensor pixel sits behind a red, green, or blue filter, and therefore does not contain full color data. The full color data for each pixel is derived by a process called de-mosaicing, whereby e.g. the red value from the pixel itself is combined with the green and blue values of nearby pixels to estimate the color of that pixel. In the process, the raw converter has to account for the differences in the optical properties of the red, green, and blue filters on different senor pixels. E.g., if you shine a while light on the senor, the ultimate de-mosaiced values for each pixel should all be R = G = B, but the raw data will show different values for each. It's a pretty complicated process, and I'm oversimplifying, but maybe you get the idea why what you want is basically impossible.

*The math works like this: in typical image files like JPEGs and PNGs, the color of each pixel is represented by 1 byte = 8 bits for each of the red, green, and blue channels. For for 954 x 954 pixels x 3 bytes/pixel = 2,730,348 bytes = 2666 KB. If the file size is 459 KB, then there has to be about 5.8:1 compression. My strong suspicion is that any normal image requires lossy compression--albeit not so lossy as to be a big quality problem--to achieve 5.8:1.

 NAwlins Contrarian's gear list:NAwlins Contrarian's gear list
Nikon Coolpix S30 Canon PowerShot S120 Sony Alpha DSLR-A580 Tamron SP AF 90mm F/2.8 Di Macro Tamron SP 70-300mm F/4-5.6 Di USD +5 more
Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark MMy threads
Color scheme? Blue / Yellow