Batch quantify black levels / output histogram data

Associate
Joined
4 Apr 2003
Posts
1,817
Location
Manchester
Ok, bit of a strange request this one but here goes.

I have a series of B&W images (several thousand) and need to quantify the amount of black in each one

They are basically CT scans so I am thinking I need the histogram areas split into 0 to 255 or say the total area between say 0 and 155.

This needs to be per image and output into a common file e.g csv, xls etc so I can quantify it.

I know this is possible manually so hopefully someone has an idea on how to automate/batch process this

Thanks
 
A quick openCV program wouldn't be hard if you can program. Otherwise I know the gimp would allow you to make a script that would do this.

If I wasn't so busy would throw something together myself.
 
Code:
from PIL import Image
import glob, os


for f in glob.glob("*.jpg"):
   im = Image.open(f)
   hist = im.histogram()
   count = hist[0]    # Assume BW image, hist is a list of 256 values, entry 0 is the count for black pixels.
   print "Image ", f, " has [", count, "] many pixels that are all black"



Untested, but that is all you would need in theory in python. Most usable operating systems (linux, unix, MacOSX, BSD) will have python installed at the system level but you might have to install it on windows unless Microsoft have caught up. You will have to install the PIL library, on anything unixy:
Code:
pip install PIL
 
Back
Top Bottom