Help with output stack of ParticleAnalyzer

Hi guys,

I managed to analyze particles from a stack. The python code return a new stack with the particles, but only the first slice contains “colored” particles, while the result table contains results from all slices. So far I have no real clue, what I am doing wrong here. Here is some part of my python script:

def analyzeParticles(image):

	MINSIZE = 500.0
	MAXSIZE = 1000000
	MINCIRCULARITY = 0.0
	MAXCIRCULARITY = 0.5
	
	options = PA.SHOW_ROI_MASKS \
			+ PA.EXCLUDE_EDGE_PARTICLES \
			+ PA.INCLUDE_HOLES \
			+ PA.SHOW_RESULTS \
	
	results = ResultsTable()
	
	p = PA(options, PA.STACK_POSITION + PA.LABELS + PA.AREA + PA.PERIMETER + PA.CIRCULARITY, results, MINSIZE, MAXSIZE, MINCIRCULARITY, MAXCIRCULARITY)
	p.setHideOutputImage(True)
	stk = ImageStack(image.getWidth(), image.getHeight())
 
	for i in range(image.getStackSize()):
		image.setSliceWithoutUpdate(i + 1)
		p.analyze(image)
		mmap = p.getOutputImage()
		stk.addSlice(mmap.getProcessor())

	return stk

Hi @sebi06,

from my experience it is better to use ParticleAnalyzer.analyze(ImagePlus, ImageProcessor) in a scripting context:

...
ip = image.getProcessor()
p.analyze(image, ip)
...

Best,
Stefan

1 Like

Hi Stefan,

I tried you suggestion but the result is the same. The colored particles are only shown for the 1st slice of the resulting stack, while all of the are contained inside the result table.

Hi @sebi06,

I see a couple of reasons there might be issues.

Uno: Lookup Table and the Brightness and contrast setting for your final image is incorrect

For this you could try using the following command after you put your stk into an ImagePlus

stk = analyzeParticles(imp)

img = ImagePlus("Test", stk)
img.show()
IJ.run(img, "glasbey_inverted", "");

This should color them in such a way that you can see them

Dos: You have more than 256 particles in the first image

Analyze Particles is smart enough to realize that when there are more than 256 particles, he should output a 16-bit image, however the lookup tables can only have 256 colors, so when you display them, any particle above number 256 will have the color of the last bin of the Lookup Table. You can change the display range, but you will still only have 256 colors to assign to your 256+ particles resulting in some colors being duplicated.

My summary search on the creation of >256 lookup tables has yielded no results, maybe some other dev can confirm whether this is possible or not.

Hope this helps

Oli

Hi Oli,

now it works.Thanks a lot

Hi @sebi06,

It would be great if you could tell us what fixed it in the end.

Best
Oli

Hi,

sorry for not mentioning the specific thing that fixed the issue. As far as I can tell it is the usage of the LUT. Now all particles in every frame have a different color.