Login  Register

Re: what's wrong with these codes?

Posted by Jinglei Yang on Mar 20, 2008; 2:53pm
URL: http://imagej.273.s1.nabble.com/what-s-wrong-with-these-codes-tp3696806p3696807.html

Dear Toby,

Thank you so much.
You are right! I do have several images with the same size and roiManager processes only one and then skips others. Is this an issue for roiManager?
Anyway, now what I can do is to change the image size or just duplicate the ROIs manually. Any other suggestions?

-Jinglei

---- Original message ----

>Date: Thu, 20 Mar 2008 10:12:22 -0400
>From: Toby Cornish <[hidden email]>  
>Subject: Re: what's wrong with these codes?  
>To: [hidden email]
>
>Dear Jinglei,
>
>I tested out your code, and it seems to me (after setting batch mode to false) that the roiManager("Add") statement is not adding the ROI under very specific circumstances. I may be wrong, but I found that if the list contains two consecutive images of the exact same size (thus the ROI is exactly the same in two consecutive images), the second ROI just doesn't get added.  This would result (the way your script is written) in fewer ROIs in the manager than you have images and in the second loop, an out of bounds error when the roiManager("Select", j) is attempted.
>
>I rewrote your code to make it more obvious by combining the loops.
>
>just set up a directory with four test files:
>
>file000.tif size A
>file001.tif size B
>file002.tif size B  <-- should crash here with index 2 is outside range blah, blah, blah
>file003.tif size C
>
>then run:
>
>  requires("1.38f");
>   dir = getDirectory("Choose a Directory ");
>   list = getFileList(dir);
>   start = getTime();
>
>   setBatchMode(false);
>
>   roiManager("reset");
>   for (i=0; i<list.length; i++) {
>            path = dir+list[i];
>            open(path);
>            title = getTitle();
>            w=getWidth();
>            h=getHeight();
>            makeOval((w-100)/2, (h-100)/2, 100, 100);
>
>            roiManager("Add");
>            roiManager("Select",i );
>            roiManager("Rename", title);
>            close();
>     }
>
>Any other opinions on this?  I could tell you how to work around it, but if this is the reason it fails, it looks like a bug to me.
>
>Toby