Random ROI / results selection for measurement

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Random ROI / results selection for measurement

Ruszkai Ákos
Hello

I've searched through the archives, and I haven't find a clue about this (or
it might be I'm not enough thorough):
Is there an easy/elegant way to random select x ROIs for measurement? Eg. I
have around 230 ROIs, but I need only 200 results for the statistical
analysis. Sure, I could select exactly 200 from the ROI manager, but that
has the opportunity that I might unintendedly "sort" them - this is not
exact randomness.
I think this could be easily done with a macro/plugin, unfortunately I can't
program (though I see in case I'd like to seriously work with this
application I'll need to pick up some Java skills).
Thank you

Regards

Ákos
Reply | Threaded
Open this post in threaded view
|

Re: Random ROI / results selection for measurement

Tiago Ferreira-2
> I've searched through the archives, and I haven't find a clue about this:
> Is there an easy/elegant way to random select x ROIs for measurement? Eg. I
> have around 230 ROIs, but I need only 200 results for the statistical
> analysis.
> Regards
>
> Ákos

Dear Ákos,
this issue has already been discussed here. Have a look at:
<https://list.nih.gov/cgi-bin/wa?A2=ind0902&L=IMAGEJ&P=R27945&I=-3>

As Curtis suggested probably the best way to do it is to use Fisher Yates
shuffle: <http://en.wikipedia.org/wiki/Fisher-Yates_shuffle>.

It could be something like the lines below but have a look at Curtis suggestion

// ---  

k=0; n=roiManager("count"); rois=newArray(n);

for(i=0;i<n;i++)
    rois[i]=k++;

myFisherYates(rois);

sample = getNumber("Size of Sample?", n);

count=1;
for(i=0;i<sample;i++) {
    roiManager("select", rois[i]);
    roiManager("measure");
    print(count++ +"/"+sample+" : Measured ROI:  "+rois[i]);
   
}

function myFisherYates(array) {
    if(array.length!=0) {
        for (i=0;i<array.length ;i++) {
            j = floor(random()*(i+1));
            temp1 = array[i]; temp2 = array[j];
            array[i] = temp2; array[j] = temp1;
        }
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Random ROI / results selection for measurement

Ruszkai Ákos
Hello

Sorry for the late reply, I was very busy with other stuffs at the uni.
Thank you very much for the macro, works like charm! You've made my work
much more easier!

Regards,

Ákos
Reply | Threaded
Open this post in threaded view
|

Re: Random ROI / results selection for measurement

Ruszkai Ákos
Hello

Sorry for the double post. May I ask this macro to be a default tool in a
next release of IJ? I undertsand the the developers don't want to make the
software bloated, but imho this is a very useful and needed tool.

Thank you in advance.

Regards

Ákos
Reply | Threaded
Open this post in threaded view
|

Re: Random ROI / results selection for measurement

Ruszkai Ákos
Hello

Bumping up the thread, as I've discovered an error:
I'm using the macro sent by Tiago (thank you very much again), but there's a
difference between it's output log and ImageJ's results window:
Log says:
1/1 : Measured ROI:  168

ImageJ returns:
1    4f30perc:0008-0169-1039:DSCN9902

The two ROIs are not the same, the log always gives back a ROI number lower
by one. Easy to fix though:

I have to change row 16 of the code:
print(count++ +"/"+sample+" : Measured ROI:  "+rois[i]);

to

print(count++ +"/"+sample+" : Measured ROI:  "+rois[i]+1);

and voila! the two numbers are identical. I've double checked it, it's the
macro that prints out the wrong number, because if I measure the output ROI
manually, I get the same results as the results window returns. I know this
is only a half solution, as it only masks the problem, not really fixes it
(and tbh in science, this is unacceptable), but at least it gives back a
correct value.

Regards,

Ákos
Reply | Threaded
Open this post in threaded view
|

Re: Random ROI / results selection for measurement

Ruszkai Ákos
Hello

Hmm... I realise my previous message could have puzzled some subscribers, so
I was continuing this thread:
https://list.nih.gov/cgi-bin/wa?A2=ind0912&L=IMAGEJ&P=R2594&I=-3
Anyway, I've just upgraded to 1.43r5, and the original macro works fine
too...
Um... so what's changed?

Regards,

Ákos