Counting value of pixels (please fast it's for my graduation)

Hi to evryone, i need to analize how many pixel have an certain value of my image (it’s for counting the number of dark count in a single photon camera SPC2)


I can explain better my question: i have summed 50000 image with z project, those image are referd to 1024 pixel of my camera, each pixel can detect one phont (value 1) or no photon (value 0), after that i’ve summed 50000 frame i need to count (or better have a graph) how many pixels have a value like 5 or 500 or something like that… or i can need a graph with the percent of pixel with like more than 100 count or less than 10000.
how can i do?
Please if you can answer today would be aswesome because i have my graduation in like one week and i need to terminate my thesis.
Thank you

@Alessandro_Marcia,

In imageJ / fiji Analyze -> Histogram is what you want.
After the window with the graph appears, you can press the “List” button and it will pop up the list that’s on the window to the right of the screenshot below.

The left column is the intensity value, and the right column is the number (count) of pixels having that value.

For example, the list tells you that 1041 pixels have the value 16.

John

Yes i’ve tried that, but what does appear when i click the list button:


i don’t know how to change that

Your image is 32 bit, try converting it to a different type.
What do you expect the values to be?

like 1 2 3 4 5… like your’s in

look, if i use my mouse i can see the value of each pixel:

i would expect to have the same in the hystogram list, now ill try to convert in evry single possible way my image to get that

You can try Image > Type > 16 bit or 8 bit and try histogramming again.
But its good to be careful that none of the pixel values change after you convert.
(at first glance, it looks like conversion to 8bit should be fine)

John

i’ve tried in evry type that’s possible to convert to… nothing to do, the same problem happens… i just then may want a convertitor? like in my image, when bin start is 5.000 his actual value is 5 for 754 pixel, and i’m ok with that , fine, but the problem is that the nexts values are 80.098… what integrer is? it’s 80 or what? the last number in the list is 19154.902 and the software gave me 19230 like maximun value of just one pixel, but now we know that 19154.902 it’s not 19230…

Hello,

Identify your maximum value from the sum image (I used a lookup table to help identify the value, but you can also find this value with the summary statistics presented by your previous histogram).

Use the maximum value plus one as the X max value on your Histogram creation window (see below image). The X min should be 0. In my example, I used a sum image with a maximum value of 6, so I put X max of 7.
histogram_example_0

After this, I had a histogram with a bin width of 1 (my first bin is from 0<=x<1 and my last bin is 6<=x<7 ). In the list output, you can see that most of my pixels had a value of 0 or 1. After this, it may be easier to take this data and use it in Excel to do exploratory calculations. You can save the table (the default is .csv which will can be opened in many other softwares).

Hope that helps!

you have 50.000 frames that each have a 0 or a 1 for every pixel. That means a hot pixel, ON (1) in every frame, occurs 50.000 times. You could create a sparse histogram and then you can gather the sparse entries. Or, because your image has 32x32 pixels (ie. 1024 pixels) only, at most you have 1024 results, a lot less than 50.000, and you can fill your own histogram array.

Build your own twist of a histogram function:
Declare two arrays of 1024 elements (that is the maximum number of grey values if all pixels have a different dark current). One array holds the grey values you have encountered, the other array holds the tally (count) of that grey value. So if the first five pixels have respectively the grey values 125,34,54,125, 125 your first array holds 125, 34, 54. The second array holds 3,1,1.

Now sort the first array and the second accordingly (that is, with the Array.rankPositions function, see an example here) and you have the histogram you want.
You fill the array by getting a pixel value, see if it already is in your array of encountered grey values.
If it has been seen before, you increment the tally.
If it hasn’t been seen before, you put it in the next free entry of your encountered grey values array and set the tally in the other array, at the same index, to 1.

The Array.rankPositions will, given the first array in the above example, return 1,3,2 (the 1 points to 125, the 3 points to 54 and the 2 indicates the smallest of the three is located at position 2). According counts are in the second array at postions [1],[3] and [2].

ok i’ve understood, but how can i create those 2 arrays?

myGreyValues=newArray(1024);
myTally= newArray(1024);

sorry, i’m a new user with imagej, so i don’t know where to write that

Plugins>New>Macro. If you use ImageJ1 (ie. nog FIJI/ImageJ2), you will get a debug menu.
You are supposed to write a macro to get a custom histogram. I’ll see if I can cobble together
a macro for you.

If we can do it together it would be great! because actually i don’t know how to write a macro on imagej

if you need to do some test, here is the file, it’s a set of 50000 frame, to have the summed image i just go on stake, z projetct, sum all 50000 and get my finally image that i have to analyze

Hi @Alessandro_Marcia,

I’ll try your image later on; here is a macro that does what (I think) you need. It uses one of ImageJ’s sample 16-bit images, cuts out a 32x32 piece, does the things I described above and prints the sorted tally of found grey values in the Log window.

For your image, cut out the first two lines, open your summed 32x32 image and run the macro.

Sparse histogram of small 16-bit image
close("*");
run("CT (420K, 16-bit DICOM)");ct=getImageID();
w=32;
h=32;
arraySize = w*h;
makeRectangle(324, 31, w, h);
run("Duplicate...", "title=spaddark.tif");
selectImage(ct);close;
myGreyValues=newArray(arraySize);
myTally=newArray(arraySize);
myGreyValues[0] = getPixel(0,0);//special case for first pixel 
for(x=0;x<w;x++){
	for(y=0;y<h;y++){
		thisGreyVal = getPixel(x,y);
		arrayPtr = 0;
		present = 0;
		do{
			thisArrayEntry = myGreyValues[arrayPtr];
			if(thisArrayEntry == thisGreyVal){
				myTally[arrayPtr] +=1;
				present = 1;
			}
			arrayPtr +=1;
		}while (present == 0 && myGreyValues[arrayPtr-1] != 0 );
		if(!present){
			myGreyValues[arrayPtr - 1]=thisGreyVal;
			myTally[arrayPtr - 1 ]=1;
		}
	}
}
arrayPtr = 0;
Array.show(myGreyValues);
mySortOrder =  Array.rankPositions(myGreyValues);
Array.show(mySortOrder);
sortOrder =  Array.reverse(mySortOrder);
Array.show(mySortOrder);

do{
	orderedEntry=sortOrder[arrayPtr];
	arrayPtr+=1;
}while(arrayPtr < sortOrder.length && myTally[orderedEntry]!=0);
arrayPtr=arrayPtr-2;
mySortOrder = Array.trim(mySortOrder,arrayPtr);
mySortOrder = Array.reverse(mySortOrder);
Array.show(mySortOrder);
for(index=0;index<mySortOrder.length;index++){
	print (myGreyValues[mySortOrder[index]]+"\t"+myTally[mySortOrder[index]]);
}

BTW, how do YOU import that file in ImageJ?

Yes sorry, i import the file with a plug in: SPC2 reader, here i gave you the link


it’s easy to install, here a guide
SPC2 Reader plugin for ImageJ.pdf (308.4 KB)

And, my image is 32 bit not 16

@Alessandro_Marcia,
thx, will try. meanwhile you try the macro, please see if it does what you expect.