Counting particles inside miltiple ROIs

//Counting dots inside each roi 
	numberOfNuclei = roiManager("count");
	for(i=0; i<numberOfNuclei; i++){
		roiManager("Select", i);
			run("Set Measurements...", "area perimeter display redirect=None decimal=3");
			run("Analyze Particles...", "size=0-Infinity display include summarize add in_situ");

C=0 - Bu286_ni_4dpi (40X) DAPi_Fibrillarin_stack_1.lsm - - Max Intensity_Simple Segmentation.tiff|attachment (89.9 KB)
C=2 - Bu286_ni_4dpi (40X) DAPi_Fibrillarin_stack_1.lsm - - Max Intensity_Simple Segmentation.tiff|attachment (55.7 KB)

Background

Hi,
I’m trying to count particles in many ROIs, as I understand Fiji has to count them one-by-one.
Firstly, I segment nuclei to acquire the ROIs I need; then, I want to count particles that I have on a different channel. I’m trying to use a code snippet that I found on @aklemm macro from the NEUBIAS webinar.
The code stops after the first ROI, I’m missing something, and I don’t know what.
C=0 is the DAPI (nuclei) channel (where I extract the ROIs).
C=2 is the red channel (with the particles of interest).

How I achieve nuclear ROIs:

//Made for segmentation images made by ilastik
orgName = getTitle();
selectWindow(orgName);
run(“Duplicate…”, “title=” + orgName + “copy”);

//Making nuclei value = 1, Background = 0
run(“Invert”);

//Making an 8-bit from 32-bit (made by ilastik)
run(“8-bit”);

//Making whole nuclei
run(“Fill Holes”);
run(“Dilate”);

//Counting nuclei
run(“Set Measurements…”, “area perimeter display redirect=None decimal=3”);
run(“Analyze Particles…”, “size=200-Infinity display exclude clear include summarize add in_situ”);

How I’m trying to count my particles:

//Made for segmentation images made by ilastik
orgName = getTitle();
selectWindow(orgName);
run(“Duplicate…”, “title=” + orgName + “copy”);

//Making nuclei value = 1, Background = 0
run(“Invert”);

//Making an 8-bit from 32-bit (made by ilastik)
run(“8-bit”);

//Making whole nuclei
run(“Fill Holes”);
run(“Dilate”);

//Counting dots inside each roi
numberOfNuclei = roiManager(“count”);
for(i=0; i<numberOfNuclei; i++){
roiManager(“Select”, i);
run(“Set Measurements…”, “area perimeter display redirect=None decimal=3”);
run(“Analyze Particles…”, “size=0-Infinity display include summarize add in_situ”);

Currently, I’m trying to do some of the work manually by keeping the ROI manager open after finishing the DAPI channel and then showing ROIs on the red channel.

Any ideas?

Thanks,
Daniel

Just to check, if that is your script it should error out. There is no closing bracket for your for loop.

Also, when presenting scripts on the forum, they are easiest to read if formatted appropriately.
image
I went ahead and formatted the first bit of code as a demonstration.

1 Like

You also may want to take a look at the script here, which is doing something similar. Reporting the results of sub-structures within an ROI.

2 Likes

Thanks for emphasizing the proper format.

The code doesn’t give an error. But it stops counting after ROI #1.

I pasted the for loop from another working code, but I’ll look into the bracket issue you mentioned.

Yes, you were right, damn typos!!!

Thanks for the attention!

have a great day

1 Like