Counting Color and Grey Scale in a directory?
Counting Color and Grey Scale in a directory?
I'm not sure if this has been asked before but is it possible to have Image Magic count images in a directory that are color or grey scale without having to open all of the files?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Counting Color and Grey Scale in a directory?
"Without having to open all of the files?" No. There is nothing external to a file that says whether it has colour, unless some software keeps some kind of database.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Counting Color and Grey Scale in a directory?
If all the files are PNG, which distinguishes between RGB and Gray, you can read the colorspace and/or type from the headers, I think. So the raster data would not need to be read, only the headers. This would be quicker. Other tools such as EXIFTOOL, might be faster. Snibgo would know more about all this than I.
For example:
For example:
Code: Select all
convert -ping image -format "%[colorspace]" info:
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Counting Color and Grey Scale in a directory?
Yes, exiftool and ImageMagick can both do the job. They would both open each file and then read metadata, and possibly every pixel.
snibgo's IM pages: im.snibgo.com
Re: Counting Color and Grey Scale in a directory?
for i in *.png;do exiftool "$i"|grep Grayscale ;done|wc -l
Re: Counting Color and Grey Scale in a directory?
Would this still work with .Tif files? I am new to these tools and have not used them before.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Counting Color and Grey Scale in a directory?
I think you can do it with TIFF also. But not JPG. I do not think JPG keeps a record of Grayscale in its header.
Re: Counting Color and Grey Scale in a directory?
Code: Select all
for i in *.jpg;do identify -ping "$i"|grep Grayscale ;done|wc -l
for i in *.tif;do identify -ping "$i"|grep Grayscale ;done|wc -l
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Counting Color and Grey Scale in a directory?
Grep from identify for Grayscale is wrong. It would need to be Graybratpit wrote: ↑2019-09-17T00:04:27-07:00Code: Select all
for i in *.jpg;do identify -ping "$i"|grep Grayscale ;done|wc -l for i in *.tif;do identify -ping "$i"|grep Grayscale ;done|wc -l
convert logo: -colorspace gray logo_gray.jpg
identify logo_gray.jpg
logo_gray.jpg JPEG 640x480 640x480+0+0 8-bit Gray 256c 34253B 0.000u 0:00.001
Re: Counting Color and Grey Scale in a directory?
Yes
But this is some inaccuracy in display fields by identify IMHO.
Output from tif:
convert logo: -colorspace gray logo_gray.tif
logo_gray.tif TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 33344B 0.000u 0:00.000
Both tif and jpg have field
But this is some inaccuracy in display fields by identify IMHO.
Output from tif:
convert logo: -colorspace gray logo_gray.tif
logo_gray.tif TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 33344B 0.000u 0:00.000
Both tif and jpg have field
from full verbose identify output.type:Grayscale
Re: Counting Color and Grey Scale in a directory?
So most safe version with grep for all formats will be Your from previous post:bratpit wrote: ↑2019-09-17T11:13:33-07:00 Yes
But this is some inaccuracy in display fields by identify IMHO.
Output from tif:
convert logo: -colorspace gray logo_gray.tif
logo_gray.tif TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 33344B 0.000u 0:00.000
Both tif and jpg have fieldfrom full verbose identify output.type:Grayscale
Code: Select all
for i in *.jpg;do convert -ping "$i" -format "%[colorspace]" info:|grep Gray ;done|wc -l
for i in *.tif;do convert -ping "$i" -format "%[colorspace]" info:|grep Gray ;done|wc -l
for i in *.png;do convert -ping "$i" -format "%[colorspace]" info:|grep Gray ;done|wc -l
Sorry . I quoted my previous post.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Counting Color and Grey Scale in a directory?
Correct -- Colorspace is Gray and Type is Grayscale.
Re: Counting Color and Grey Scale in a directory?
Yes but I am not telling about that.
I am telling about comparison two identify outputs for tiff and jpg.
logo_gray.jpg JPEG 640x480 640x480+0+0 8-bit Gray 256c 34253B 0.000u 0:00.001
logo_gray.tif TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 33344B 0.000u 0:00.000
For me it is some kind of inconsistency.
Re: Counting Color and Grey Scale in a directory?
Ok, I was able to get both tools working but how do I get it to drill into a multipage Tiff? It seems to be only reading the header information of the file or the initial image.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Counting Color and Grey Scale in a directory?
What was your exact command?