Posted by
Toby Cornish on
Mar 20, 2008; 2:12pm
URL: http://imagej.273.s1.nabble.com/what-s-wrong-with-these-codes-tp3696806p3696808.html
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
Date: Wed, 19 Mar 2008 12:10:49 -0500
From: Jinglei Yang <
[hidden email]>
Subject: what's wrong with these codes?
Dear ImageJ friends,
I'm a very beginner for ImageJ programming.
I write some codes to batch select a circle ROI centered in each image and rename the ROI with the same name of the image.
The codes are shown below. The question is there are always several images that cannot be selected with circle ROI, e.g., I have 35 images in a folder but only 28 or sometime 25 images are selected. I have to copy others to another folder to repeat this process.
It is so weird for me.
Can anybody help?
Many thanks,
Jinglei @ UIUC
Codes:
* snipped *