Threshold an image, add ROI to another, in javascript

81 views
Skip to first unread message

Nicoco

unread,
May 3, 2016, 3:07:49 AM5/3/16
to Icy imaging
Hello all,

As the title states, I'd like to threshold the channel 0 of an image, and add the obtained ROI to another sequence.
I'm encountering several problems doing that, probably due to my being completely new to javascript.

First, I don't understand how to use a fixed threshold.
If I try:
cells = Thresholder.threshold(groundtruth, 0, 100)
I'm getting
Can't find method plugins.adufour.thresholder.Thresholder.threshold(icy.sequence.Sequence,number,number)

I can circumvent this using
thresh = KMeans.computeKMeansThresholds(groundtruth, 2)
cells = Thresholder.threshold(groundtruth, 0, thresh)
but this is not really satisfying, as I know the threshold value I want to use.

Second part, I'd like to add the ROI obtained this way to a sequence. So here's what I tried:
seq.addROI(cells)
but I'm getting this error:
Can't find method icy.sequence.Sequence.addROI([Licy.roi.ROI;).

I'm guessing this a type issue, but after unsuccessfully trying a lot of different combinations, I'm turning to the community for help.

Thanks!

Stephane

unread,
May 3, 2016, 5:54:34 AM5/3/16
to Icy imaging
Hi Nicoco,

The difficult point is that ThresHolder is taking double array for the threshold level and returns ROI array as result.
Also you can have ambiguous call so you have to define manually which method you want to use.
Here's a script which does what you want to do :

importPackage(Packages.plugins.adufour.thresholder)
importClass
(Packages.plugins.adufour.thresholder.Thresholder)

seq
= getSequence()
// get the methode we want to use and store it in 'meth'
meth
= Packages.plugins.adufour.thresholder.Thresholder["threshold(icy.sequence.Sequence,int,double[])"]
// do threshold
rois
= meth(seq, 0, [100])
// if we have at least 1 roi, add it to sequence
if (rois.length > 0)
  seq
.addROI(rois[0])

Cheers,

- Stephane

Nicoco

unread,
May 3, 2016, 7:20:08 AM5/3/16
to Icy imaging
Thanks for your help, everything works fine this way.

You said Thresholder returns a ROI array as a result, so why do you check its length?
Doesn't it returns a list of boolean array, each nth-element being the thresholded image for the nth-threshold?
Put another way, on your piece of code, is it possible that rois.length is different than 1?

Sorry if I'm not being clear, I've only done image processing with MATLAB and Python before.

Stephane

unread,
May 3, 2016, 8:54:13 AM5/3/16
to Icy imaging
I added the test just as a security but i think you're right, it returns an array of ROI based of the number of value specified in the threshold value array. It is just that i was not sure anymore but indeed now you are speaking about i think it behaves as you described (so here rois.length us always equal to 1).

- Stephane
Reply all
Reply to author
Forward
0 new messages