Image sequence - % of colors in each image

batch-processing
Tags: #<Tag:0x00007fd5405bb8d8>

#1

So, as with everything, it isn’t that simple…
I have 12 sets of 4000 sequenced images, in predominantly black and white colors. I’m saying predominately because the “white” color may change.
Say the image is 2400 x 2400 pixels, I want to be able to break the image into thirds;
top (0, 800 x 0, 2400),
middle (801, 1600 x 0, 2400),
and bottom (1601, 2400 x 0, 2400),
and then export a text-based table that tells me the % of colors in each image.
I’ve tried using ImageJ, but not sure how to setup breaking the image into thirds.
Any help would be greatly appreciated.


#2

Good day,

here is a macro that may help you getting started:

n = 3;
w = getWidth();
h = round( getHeight() / n );
for ( i=0; i<3 ; i++ ) {
makeRectangle( 0, 0, w, h );
getHistogram( 0, counts, 256 );
for ( j=0; j<counts.length; j++ ) {
setResult( "Section "+i, j, counts[j] );
}
}
run(“Select None”);

The macro creates a table with the gray value histograms of n=3 equally sized vertically stacked parts of an 8bit image.

Because there are 256 gray levels with an 8bit image, you get 256 values for each selection that tell you how many pixels show the correspondig value. If you prefer to see the percentage you need to divide the (number of pixels per gray value) by the (number of pixels in the selection) — easy. If you like to save the results table, then please look into the documents and the great many macro examples available.

HTH

Herbie


#3

Thank you Herbie. I’ll review your macro later this afternoon. I appreciate your help.
Jeff


#4

Unfortunately, this didn’t work. My images are rather dynamic (top may have 30% 255, and the bottom may have 85% 255) but the results that this macro shows are exactly the same per each “Section”.
Any thoughts on the above macro?


#5

Any thoughts on the above macro?

Sure!

The index for the vertical shift was missing — no?

Try

n = 3;
w = getWidth();
h = round( getHeight() / n );
for ( i=0; i<3 ; i++ ) {
makeRectangle( 0, i*h, w, h );
getHistogram( 0, counts, 256 );
for ( j=0; j<counts.length; j++ ) {
setResult( "Section "+i, j, counts[j] );
}
}
run("Select None");

Sorry

Herbie