When converting a color JPG image to grayscale, and saving it back to JPG, one can usually see at least 20% file size reduction, which seems natural.
Question:
Is there a specific "grayscale" format in the JPG specifications? I see this in the JPEG File Interchange Format, but not sure if it's the standard used nowadays
Or is a "grayscale JPG" just usually a color RGB JPG where R = G = B
, and thus the file size reduction results from a compression of 3-times-duplicated numbers?
It seemed to me that it's 2. because in various languages, JPG export functions don't have a grayscale option, for example toDataURL
in Javascript:
var fullQuality = canvas.toDataURL('image/jpeg', 1.0);
var mediumQuality = canvas.toDataURL('image/jpeg', 0.5);
var lowQuality = canvas.toDataURL('image/jpeg', 0.1);
Right-click the picture that you want to change, and then click Format Picture on the shortcut menu. Click the Picture tab. Under Image control, in the Color list, click Grayscale or Black and White.
In digital images, grayscale means that the value of each pixel represents only the intensity information of the light. Such images typically display only the darkest black to the brightest white. In other words, the image contains only black, white, and gray colors, in which gray has multiple levels.
A grayscale (or graylevel) image is simply one in which the only colors are shades of gray. The reason for differentiating such images from any other sort of color image is that less information needs to be provided for each pixel.
A color JPEG has 3 components: Y Cb Cr
A grayscale JPEG has 1 component: Y
You can convert a color JPEG into a grayscale simply by updating the header to indicate 1 component and deleting the Cb and Cr scans.
Is there a specific "grayscale" format in the JPG specifications?
Yes, and it is well supported. It isn't used commonly these days, but most everything can read it.
Or is a "grayscale JPG" just usually a color RGB JPG where R value==G value==B value, and thus the file size reduction results from a compression of 3-times-duplicated numbers?
Not all APIs are going to expose all of the features available. The greyscale handling is specific to the format and isn't available in all other formats. The Canvas API, in particular, tries to standardize over all possible export formats. Therefore, only a subset of features are supported.
When you save an image via the Canvas API, it's likely that you're saving a JPEG with chroma components, and they are effectively null and are compressing well. (That being said, the specific behavior is undefined, and a browser could choose to optimize and save a greyscale JPEG by detecting greyscale is all that's required.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With