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: requires("1.38f"); dir = getDirectory("Choose a Directory "); list = getFileList(dir); start = getTime(); setBatchMode(true); for (i=0; i<list.length; i++) { path = dir+list[i]; open(path); w=getWidth(); h=getHeight(); makeOval((w-100)/2, (h-100)/2, 100, 100); run("Add to Manager "); roiManager("Add"); } for (j=0; j<list.length; j++) { path = dir+list[j]; open(path); title = getTitle(); roiManager("Select", j ); roiManager("Rename", title); } |
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 * |
In reply to this post by Jinglei Yang
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 |
Free forum by Nabble | Edit this page |