2
\$\begingroup\$

Is there a simple utility to organize photos simply by colour or monochrome? I thought it would be easy, but I havent found anything.

Initially I thought it could be a simple metadata tag. Searching has found nothing suitable.

Any ideas?

\$\endgroup\$
7
  • 1
    \$\begingroup\$ For the record: monochrome is not equivalent to black and white! \$\endgroup\$ Mar 5, 2023 at 14:32
  • \$\begingroup\$ Also you can check this answer: superuser.com/a/508476/409497 \$\endgroup\$ Mar 5, 2023 at 14:39
  • \$\begingroup\$ It could be a difficult task. A grayscale image could be really a grayscale image or only an unsaturated color image. Also, there could be unsaturated subjects or thematic ones. Seeing the trend in AI applications probably soon we will get one that can analyze the context and parameters of your classification. \$\endgroup\$
    – Rafael
    Mar 5, 2023 at 19:39
  • 1
    \$\begingroup\$ I don't think it would be a difficult task at all. A simple "brute force" loop through pixels of an image to see if any have some value where R==G==B is not true. I could do it in Processing pretty easily I reckon, and I'm sure there are more efficient ways to do it. \$\endgroup\$
    – osullic
    Mar 5, 2023 at 19:51
  • \$\begingroup\$ If they were taken as Monochrome photos in-camera, many camera makers will record the "Monochrome" (or their equivalent name) picture style in the maker notes section of the EXIF info. Not all EXIF info is displayed by most EXIF readers. In fact, much of it is not displayed by some of the most popular EXIF readers and imaging apps. Adobe Products, for instance, display almost none of the maker notes section. Just because an application does not display the info does not mean it isn't there. \$\endgroup\$
    – Michael C
    Mar 6, 2023 at 4:07

3 Answers 3

2
\$\begingroup\$

Experimentally, taking this picture, and saving four JPEGs:

  • one with full color
  • one with dulled colors (saturation=50%)
  • one with all colors reduced to grayscale (saturation=0%)
  • one which is really single-channel grayscale (not shown below)

enter image description here

The single grayscale one is easily identified:

  • the file utility reports only one component (three in the others)
  • ImageMagick's identify command reports a Gray colorspace (sRGB for the others)

For the other three, a main differentiator is to count the unique colors, by design a grayscale JPEG image (whether true grayscale or RGB image with R=G=B) can have at most 256 colors when others are usually in the hundred thousands[*]. Using identify

$ for f in *.jpg ; do printf "%14s: %6d\n" $f $(identify -format "%k" $f) ; done
Chroma-000.jpg:    256
Chroma-050.jpg: 126123
Chroma-100.jpg: 345665
 Grayscale.jpg:    256

Using this it is easy (at least on OSX or Linux) to build a small script to move files depending on color count, for instance:

find . -name '*.jpg' -exec bash -c 'count=$(identify -format "%k" $1) ; [[ $count -le 256 ]] && exit 0 ; exit 1 ;' _ {} \;  -print

only print the names of the grayscale picture, and something like

find . -name '*.jpg' -exec bash -c 'count=$(identify -format "%k" $1) ; [[ $count -le 256 ]] && exit 0 ; exit 1 ;' _ {} \;  -exec mv -t /path/to/dir {} +

will move them to directory /path/to/dir.

[*] This may not be true for formats with high bit depths, for instance a grayscale 16-bit PNG could have 65536 colors (but 16-bot PNG aren't that frequent and can be discriminated with the file command or else). This is still less than the colors in the average photo. This also couldn't be true for CGI, but then we are on the Photography site.

\$\endgroup\$
4
  • 4
    \$\begingroup\$ It might be worth mentioning that identify belongs to ImageMagick. \$\endgroup\$
    – luator
    Mar 6, 2023 at 10:56
  • \$\begingroup\$ @luator Good remark, fixed \$\endgroup\$
    – xenoid
    Mar 6, 2023 at 11:24
  • \$\begingroup\$ Great analysis thanks, I appreciate you detailed reply, I will experiment as you suggest \$\endgroup\$
    – BwCol
    Mar 6, 2023 at 20:47
  • 1
    \$\begingroup\$ @BwCol I see in the comment to you original post that they are scans of B&W prints, so we are taking of "almost" grayscale images (with R/G/B close but not necessarily equal)? \$\endgroup\$
    – xenoid
    Mar 6, 2023 at 21:35
0
\$\begingroup\$

If you are not afraid of writing a bit of Python, there was a similar question on Stackoverflow, the method I gave would allow you to also detect almost grayscale images: https://stackoverflow.com/questions/74888295/detect-almost-grayscale-image-with-python/74903803#74903803

\$\endgroup\$
0
\$\begingroup\$

If your monochrome images are grayscale, they'll generally be approximately 1/3 the file size of RGB images saved with the same compression parameters, though desaturated RGB files will compress much more than color ones, so there'll be less difference between a desaturated RGB file and a true monochrome (one-channel) file. Variation in compression (which depends on many factors such as sharpness, contrast, and for RGB files, color variations) may make desaturated files in a compressed format (especially a lossy one like .jpg) compress nearly as much as true grayscale (potentially even more). Uncompressed files, however, will always show this variation in file size.

This is because grayscale images only need a single brightness value per pixel (typically 16 bits wide with modern cameras or scanners and software), while color images will have three similar width brightness values for each pixel (in some formats, potentially a fourth for gamma). This results in the uncompressed files being exactly one third (or one fourth) the size for grayscale as they would be for RGB, and most compression methods will effect similar levels of file size reduction for color or for grayscale images.

Note that this only works if the image has been saved as grayscale vs. saved as desaturated RGB (still with three color channels, but with the values of all three channels locked together for each pixel).

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Experimentally, actually for a JPG, full color is 4.1MB,, and the grayscale version is 3.4MB, which is within the size variations induced by content randomness. \$\endgroup\$
    – xenoid
    Mar 5, 2023 at 20:37
  • \$\begingroup\$ @xenoid As noted, this only works for a file that has been saved as single channel grayscale. Your result suggests you simply desaturated, but saved as RGB/RGBA. In GIMP (my familiar image editor) there's an option to convert to single channel, and a separate option to desaturate that leaves the color channels in place. \$\endgroup\$
    – Zeiss Ikon
    Mar 7, 2023 at 12:07
  • \$\begingroup\$ Even then... Files from my answer: Full RGB: 4224K, half-desaturated: 3900K, grayscale RGB: 3448K, single-channel 3372K (from Image > Mode > Grayscale in Gimp), so that 20% less for the single channel. JPEG sizes from my camera have a lot more variation even during the same shooting session (1:2 is frequent, 1:3 is not so rare). In fact being slightly out of focus does more for the file size reduction than the single channel. \$\endgroup\$
    – xenoid
    Mar 7, 2023 at 12:50
  • \$\begingroup\$ Desaturated files will compress more than those with three distinct color channels, so this similarity isn't out of line for .jpg compression. I'll see if I can edit to make this more clear in my answer. \$\endgroup\$
    – Zeiss Ikon
    Mar 7, 2023 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.