I'm trying to use chunky_png for reading PNG image in Ruby on Rails. the library seems to work fine reading 8-bit PNG image. However, what I actually have is 16-bit grayscale PNG image and I want to retriev pixel brightness value of certain points. All of my attempts on retrieving pixel value always end-up with 8-bit rgba format.
Is there any way to read 16-bit brightness value from grayscale png image using chunky_png? Or should I give up and use some other tools that can do this job instead?
Because of how ChunkyPNG stores color values internally, it doesn't support more than 8 bit colors per channel. It automatically converts channels to 8 bit values when it encounters higher values.
So, this is impossible now, and would require some significant rewrites of the codebase to make this possible (but pull requests are accepted! :)
Related
For a project I'm currently working on, I'm trying to convert a bunch of PNG images to HEIF/HEIC. These images will be used in Xcode's .xcassets, which will then be "compiled" into a .car file.
Compiling the PNGs (~150 total files) results in ~40 MB of Assets.car, which is why I'm trying to convert them to HEIF/HEIC in the first place. I've tried various solutions, such as ImageMagick, "Export as" in GIMP, biodranik/HEIF, libheif's heif-enc, exporting a PNG as 8-bit or 16-bit in Photoshop and doing everything all over again. But everything results in the .heic file being "broken" on iOS. The first image shows the best output I've got so far, but still fringes around the edges. The white rounded rectangle on the right is iOS' Face ID padlock.
The second image is (I think) a 16-bit PNG converted to HEIC using libheif#1.8.0, upgraded through Homebrew. Lossless quality preset, 10-bit output. heif-enc complained about the color space being converted from RGB to YCbCr, stating even though you specified lossless compression, there will be differences because of the color conversion
Is there any way to properly convert PNG files to HEIF/HEIC without such quality loss? Please don't suggest online services to convert files, as I'd like to keep total control of my files.
Note: To get lossless encoding, you need this set of options. Try :-
-L switch encoder to lossless mode
-p chroma=444 switch off color subsampling
--matrix_coefficients=0 encode in RGB color-space
I am new to image processing and a little bit confused with OpenCV Data Types even though I read the documentation (http://docs.opencv.org/modules/core/doc/basic_structures.html).
Which CVType do I have to choose for a standard 24-bit png image with 3 colors + alpha channel?
Why OpenCV using BGR colour space instead of RGB. We all know that RGB is the convenient colour model for most of the computer graphics and also the human visual system works in a way that is similar to a RGB colour space. Is there any reason behind OpenCV BGR colour space?.
"The reason why the early developers at OpenCV chose BGR color format is probably that back then BGR color format was popular among camera manufacturers and software providers. E.g. in Windows, when specifying color value using COLORREF they use the BGR format 0x00bbggrr.
BGR was a choice made for historical reasons and now we have to live with it. In other words, BGR is the horse’s ass in OpenCV."
OpenCV reads in images in BGR format (instead of RGB) because when OpenCV was first being developed, BGR color format was popular among camera manufacturers and image software providers. The red channel was considered one of the least important color channels, so was listed last, and many bitmaps use BGR format for image storage. However, now the standard has changed and most image software and cameras use RGB format, which is why, in programs, it's good practice to initially convert BGR images to RGB before analyzing or manipulating any images.
Why? For historical reasons. In 1987, Microsoft Windows ran on the IBM PS/2, and an early IBM video display controller, VGA, made use of the INMOS 171/176 RAMDAC chip, which was easier to use when images were stored in BGR format.
See details at
Why BGR color order - Retrocomputing Stack Exchange
Many articles shows ways of converting jpeg files to grayscale using canvas+html5 at the client-side. But what I need is to convert an image to 8bit grayscale to reduce its size before uploading to my server.
Is it possible to do it using canvas+html5?
The whatwg specification mentions a toBlob method, which is supposed to convert the canvas to a jpeg or png and give you the binary representation. Unfortunately, it isn't widely supported yet.
So all you can do is use getImageData to get an array of the bytes of the raw image data. In this array, every pixel is represented by 4 bytes: red, green, blue and alpha. You can easily calculate the grayscale values from this (gray = (red + green + blue) / 3 * alpha / 255;). But the resulting array will be completely uncompressed, so it will likely be even larger than the original jpeg, even though it only uses 8 bit per pixel. In order to reduce the size, you will have to implement an image compression algorithm yourself. You might consider to use the DEFLATE algorithm used by PNG instead of JPEG encoding - it's a lot easier to implement, doesn't introduce further artifacts because it's lossless, and performs pretty well on 8bit images.
The boilerplate data to turn this compressed data stream into a vialid PNG/JPEG file should be added on the server (when you need it).
I am using JNA to access openCV, in my application I have one function that returns an array of RGB values to java for display which is fine if the image is actually uses rgb color space but if the image is hsv or a binary image it produces odd behavior artifacts how i can detect what color space it is using and convert everything to rgb before transfer and convert them to rgb if they arent?
You can't detect if an image is rgb or not by direct examination of the the three buffers. You need to know what format it's in before making it available to another process or app.
I suggest you decide to use rgb for all your interprocess buffers and ensure that all the images are converted to rgb in each originating process.
in Opencv use "CvtColor" to get the native bgr into rgb. From other apps - if they don't support image conversion - then you can use cvconvert to get them all into rgb if you need to.
You can also use "Merge" and "Mixchannels" to make simple rgb to bgr without any fuss and in-place.
in 2.2 there is a better rgb to hsv fuinction which uses all 256 values for hue. it is better than the older one.
docs here: http://opencv.willowgarage.com/wiki/