Extract ROI selection of particles and order according to size

Hi,

I’ve analyzed several particles of different sizes and are now all incorporated into ROI Manager. Is it possible to extract the selection of each particle and somehow order them according to their size? I dont care about the background. It would make my posterior analysis much faster.
Thanks!
example

Hello Inserts -

I’m not aware of any built-in tool that will do this for you.

But it should be straightforward if you are comfortable writing a
script (or macro).

It might be as simple as iterating through the Rois in the
RoiManager, prepending the size of each Roi to its name,
and running “Sort” on the RoiManager.

What do you want the result of ordering the Rois to be? Do
you want them still in the RoiManager? In some other data
structure? Also, what “size” do you want to use? The number
of pixels contained in the Roi? The Roi's diameter?

Thanks, mm

1 Like

Hi @insertsk8,

Getting them vertically centered is left as an excercise for the student :wink:

selectWindow("efbea28d25cbd013e320a90ab0bf26d761e17e04.png");
close("\\Others");
inWinID=getImageID();
if(roiManager("count")>0){roiManager("deselect");roiManager("delete")}
doWand(38, 133);roiManager("Add");
doWand(61, 82);roiManager("Add");
doWand(127, 114);roiManager("Add");
doWand(87, 151);roiManager("Add");
run("Set Measurements...", "area mean min centroid bounding shape skewness redirect=None decimal=2");
roiManager("deselect");
roiManager("multi-measure measure_all");

myNResults = roiManager("count");
areas=newArray(nResults);
sumWidth=0;
maxHeight=0;
for(i=0;i<nResults;i++){
	areas[i]=getResult("Area",i);
	sumWidth=sumWidth+getResult("Width",i);
	thisHeight=getResult("Height",i);
	if(maxHeight<thisHeight){maxHeight=thisHeight;}
}
ranks=Array.rankPositions(areas);
Array.reverse(ranks);
newImage("sorted", "8-bit white", sumWidth, maxHeight, 1);
newImageID=getImageID();
xpos=0;

for(i=0;i<nResults;i++){
	j=ranks[i];
	selectImage(inWinID);
	roiManager("select",j);
	getSelectionBounds(x, y, width, height);
	run("Copy");
	selectImage(newImageID);
	makeRectangle(xpos,0,width,height);
	run("Paste");
	xpos=xpos+width;
}
run("Select All");
setThreshold(0, 25);
1 Like

Right I solved it!

Thanks a lot!!