Counting Color and Grey Scale in a directory?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
ccameron
Posts: 5
Joined: 2019-09-09T13:33:20-07:00
Authentication code: 1152

Re: Counting Color and Grey Scale in a directory?

Post by ccameron »

I was using this command - magick identify *.tif > report.csv. Just to identify all the files and images. It is working. The test file I was using was the problem.

Do you know of any way to identify gray scale and color images in a PDF?
snibgo
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?

Post by snibgo »

IM can read PDF images, via Ghostscript. So you could just use *.pdf in your command.

If you want to extract raster images from PDF files, use pdfimages.
snibgo's IM pages: im.snibgo.com
bratpit
Posts: 17
Joined: 2018-09-16T00:20:21-07:00
Authentication code: 1152

Re: Counting Color and Grey Scale in a directory?

Post by bratpit »

Just simple as previous.

Code: Select all

for i in *.pdf;do pdfimages -list "$i"|grep gray ;done|wc -l
for i in *.pdf;do pdfimages -list "$i"|grep rgb ;done|wc -l
ccameron
Posts: 5
Joined: 2019-09-09T13:33:20-07:00
Authentication code: 1152

Re: Counting Color and Grey Scale in a directory?

Post by ccameron »

Ok, I installed Ghostscript and ran the magick identify *.pdf > report.txt. This is what the results look like.
1046.pdf[0] PDF 605x791 605x791+0+0 16-bit sRGB 13438B 0.016u 0:00.018
1046.pdf[1] PDF 605x791 605x791+0+0 16-bit sRGB 33097B 0.016u 0:00.017
1046.pdf[2] PDF 616x780 616x780+0+0 16-bit sRGB 785431B 0.016u 0:00.017

How do I determine if any of them are grey scale or color? I see RGB in them but I know there isn't color in it.
snibgo
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?

Post by snibgo »

The mere act of rasterizing a PDF doesn't calculate whether each page has any colour. You could:

Code: Select all

magick in.pdf -colorspace HCL -format %[fx:maxima.g]\n info:
This finds the maximum chroma of each page. When this is zero, the page is monochrome.
snibgo's IM pages: im.snibgo.com
Post Reply