Pixel counting with x-value

Hi all, I’m trying to count colored particles based on their x distance from the left side of the image. I have tried using the color threshold, getting the pixels I want selected, then saving XY data. For some reason when I open the CSV file, there are three sets of data for each X-Y coordinate. It will give me three different RGB values for each pixel.

I have tried the particle counter but the particles are too close and two particles next to each other are counted as one. Sorry if this is vague, I’m just looking for an easy way to select a group of colored pixels and get their x-value.



vaguely defined tasks and computers don’t go together …

What about posting a typical example image?



Yes sorry about that. Here’s a typical picture

I’d like to be able to get every x position for a green colored pixel. Is selecting the data with threshold and saving xy data the best way?


you could experiment with “Color Threshold”. But I’m still not sure whether you really mean pixels, because the number of green pixels in the image is around half a million.

I guess you mean green objects (pebbles). Counting them will be difficult to impossible because of the overlap.



Do you really need to count by particle?

If you could alternatively count the number of green pixels for each x distance, then this value is proportional to the number of green particles (assuming that particles have roughly the same size).

The workflow in this way would be

  1. split channels
  2. threshold green channel
  3. get sum of white pixels for each x position
  4. optionally, plot the sum vs distance from left side of the image.

It’s macro looks like

tt = getTitle();
run("Split Channels");
selectWindow(tt + " (green)");
setAutoThreshold("Minimum dark");
setOption("BlackBackground", true);
run("Convert to Mask");
integrateY = newArray(getWidth());
for ( i = 0; i < getWidth(); i++){
	for (j = 0; j < getHeight(); j++){
		integrateY[i] += getPixel(i, j);
Plot.create("Title", "Distance", "Count", integrateY);