Print number of pixels with max and min value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Print number of pixels with max and min value

robin2
Hi,

I'm trying something that is probably pretty easy but I can't get it to work.
I want to process all images within one directory (which is not the problem). The images are 12bit *.pgm out of a laboratory camera.
As output I expect for each image the number of pixel with value 0 and the number of pixel with the maximum value. That basically works fine. But the problem is, if there is no pixel with the maximum possible value (4096) I get an error. Which makes sense. So a solution would be to first check for the maximum value. That can't be hard but I can't get it to work properly

Here my code so far.
Help would be appreciated.

dir = getDirectory("Choose Directory ");
list = getFileList(dir);
setBatchMode(true);
for (i=0; i<list.length; i++) {
    showProgress(i+1, list.length);
    filename = dir + list[i];
    open(filename);
    getHistogram(0, counts, 4096);
    print('"' + getInfo("image.filename") + '",' + counts[0] + ',' + counts[4096]);
    close();
}