Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROI selection #229

Open
Dennet02 opened this issue Nov 13, 2023 · 3 comments
Open

ROI selection #229

Dennet02 opened this issue Nov 13, 2023 · 3 comments

Comments

@Dennet02
Copy link

Hello, I really need help, so I have an image in which I must randomly select 50 cell nuclei, I already have all the image nuclei in my ROI manager, and I only want to select 50 of those, how can I do it?

@hansenjn
Copy link

hansenjn commented Nov 13, 2023

Hello, you could realize that with an ImageJ macro.
Here is an example code.
Run this macro after you have all the ROIs in the ROI manager, and only 50 randomly selected ROIs will remain. Note, that this will give you a random selection of 50 ROIs that is different everytime you run the code.

// We need to know how many ROIs there are in total
nrOfRois = roiManager("count");

// Now we create an empty list of 50 numbers
randomNumbers = newArray(50);

// We fill this list with random numbers between 0 and nrOfRois
for (i = 0; i < 50; i++) {
	randomNumbers [i] = round(random * (nrOfRois-1.0));
	print("Selected ROI with index " + randomNumbers [i] + " to be kept.");
}

// Now we shuffle through all ROIs in the ROI manager ... 
for(i = nrOfRois-1; i >= 0; i --){
	keep = false;
	// ... and check whether each ROI is in the list of 50 random numbers
	for(j = 0; j < 50; j++){
		if(randomNumbers [j] == i){
			keep = true;
			break;
		}
	}
	// .. if it is not in the list, we delete the specific ROI
	if(keep == false){
		roiManager("select", i);
		roiManager("delete");
	}
}

To run this macro code in FIJI, go to Plugins > New > Macro. Then paste the Macro code I wrote above into the empty macro and click the Run button.

@Dennet02
Copy link
Author

Thank you so much, it solved it

@Whistleblowe
Copy link

Hello, I really need help, so I have an image in which I must randomly select 50 cell nuclei, I already have all the image nuclei in my ROI manager, and I only want to select 50 of those, how can I do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants