Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a grayscale JPG format?

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:

  1. 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

  2. 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);
like image 938
Basj Avatar asked Jun 24 '18 10:06

Basj


People also ask

How do I make a JPEG grayscale?

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.

How does grayscale image look like?

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.

Do grayscale images have colour?

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.


2 Answers

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.

like image 68
user3344003 Avatar answered Sep 18 '22 05:09

user3344003


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.)

like image 27
Brad Avatar answered Sep 22 '22 05:09

Brad