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?
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?
Experimentally, taking this picture, and saving four JPEGs:
The single grayscale one is easily identified:
file
utility reports only one component (three in the others)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.
identify
belongs to ImageMagick.
\$\endgroup\$
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
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).
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\$