Hello,
I would like to write a macro that select several rois, but it seems that the "Shift" key is not taking into account while selecting : roiManager("Select", 1); setKeyDown("shift"); roiManager("Select", 2); this macro will select only roi2, while I would like roi1 and 2 to be selected. Any idea ? thanks. Thomas -- /*****************************************************/ Thomas Boudier, MCU Université Pierre et Marie Curie UMR 7101 / IFR 83. Bat A 328, Campus Jussieu Tél : 01 44 27 35 78 Fax : 01 44 27 25 08 /*****************************************************/ |
Hello Thomas,
> I would like to write a macro that select several rois, but it seems > that the "Shift" key is not taking into account while selecting : > > roiManager("Select", 1); > setKeyDown("shift"); > roiManager("Select", 2); > > this macro will select only roi2, while I would like roi1 and 2 to be > selected. > This code works fine for me (tried with v1.41c and v1.41i on WinXP), i.e. it selects the combination of the two ROIs. I tried only with rectangular ROIs, however. best, jan -- Jan Eglinger PhD Student, Eckhard Lammert group Max Planck Institute of Molecular Cell Biology and Genetics Pfotenhauerstrasse 108 01307 Dresden Germany Tel: +49 351 210 2722 |
Jan Eglinger a écrit :
> Hello Thomas, > >> I would like to write a macro that select several rois, but it seems >> that the "Shift" key is not taking into account while selecting : >> >> roiManager("Select", 1); >> setKeyDown("shift"); >> roiManager("Select", 2); >> >> this macro will select only roi2, while I would like roi1 and 2 to be >> selected. >> > > This code works fine for me (tried with v1.41c and v1.41i on WinXP), > i.e. it selects the combination of the two ROIs. > I tried only with rectangular ROIs, however. Hi, I'm running ImageJ 1.41i on linux with java1.6.0_06, what I would like is to select specifically two rois (to perform some computation on them), when I run this code : roiManager("Select", 0); setKeyDown("shift"); roiManager("Select", 1); roiManager("measure"); I only have one measure instead of two. Not sure if the shift key applies to the list inside roiManager or to Rois in the image where they are combined. Thomas > > best, > jan > -- /*****************************************************/ Thomas Boudier, MCU Université Pierre et Marie Curie UMR 7101 / IFR 83. Bat A 328, Campus Jussieu Tél : 01 44 27 35 78 Fax : 01 44 27 25 08 /*****************************************************/ |
Hi Thomas,
> > I'm running ImageJ 1.41i on linux with java1.6.0_06, what I would like > is to select specifically two rois (to perform some computation on > them), when I run this code : > > roiManager("Select", 0); > setKeyDown("shift"); > roiManager("Select", 1); > roiManager("measure"); > > > I only have one measure instead of two. Not sure if the shift key > applies to the list inside roiManager or to Rois in the image where they > are combined. > When running: roiManager("Select", 0); setKeyDown("shift"); roiManager("Select", 1); the picture ends up with a combination of two ROIs, but when you run the roiManager("measure"); command afterwards, it only measures one selection. Try one of the following: - If you want to have one measurement of the combined ROIs, do: run("Measure"); - If you want to have measurements for all the ROIs in the manager, do: roiManager("deselect"); roiManager("measure"); Interestingly, the "Deselect" command doesn't seem to be recorded by the Macro Recorder. Hth, Jan -- Jan Eglinger PhD Student, Eckhard Lammert group Max Planck Institute of Molecular Cell Biology and Genetics Pfotenhauerstrasse 108 01307 Dresden Germany Tel: +49 351 210 2722 |
In reply to this post by Thomas Boudier
I think the confusion is that you are creating ONE roi - and not two. A
ROI does not have to be contiguous. So, when using the shift key, you are still making ONE roi (in two parts). So, the macro is working just fine, it is measuring the content in that one roi. Since I am not sure what you want to do ... if you want a measure for each roi ... roiManager("Select", 0); roiManager("measure"); roiManager("Select", 1); roiManager("measure"); Thomas Boudier wrote: > Jan Eglinger a écrit : >> Hello Thomas, >> >>> I would like to write a macro that select several rois, but it seems >>> that the "Shift" key is not taking into account while selecting : >>> >>> roiManager("Select", 1); >>> setKeyDown("shift"); >>> roiManager("Select", 2); >>> >>> this macro will select only roi2, while I would like roi1 and 2 to be >>> selected. >>> >> >> This code works fine for me (tried with v1.41c and v1.41i on WinXP), >> i.e. it selects the combination of the two ROIs. >> I tried only with rectangular ROIs, however. > > Hi, > > I'm running ImageJ 1.41i on linux with java1.6.0_06, what I would like > is to select specifically two rois (to perform some computation on > them), when I run this code : > > roiManager("Select", 0); > setKeyDown("shift"); > roiManager("Select", 1); > roiManager("measure"); > > > I only have one measure instead of two. Not sure if the shift key > applies to the list inside roiManager or to Rois in the image where they > are combined. > > Thomas > >> >> best, >> jan >> > > -- John K. Alexander, Ph.D. Post-Doctoral Fellow William Green Laboratory University of Chicago Dept. Neurobiology, Pharmacology, and Physiology 947 East 58th Street Abott Hall 402 Chicago, IL 60637 (off) 773-702-9386 (fax) 773-702-3774 [hidden email] |
There is indeed a problem with selecting multiple ROIs in a macro. This is
more easily seen when trying to use the "Combine" command on two selected ROIs in a macro. Below is a question I sent a few days ago and the response of Wayne Rasband : I would like to select two ROIs in the manager and combine them in a > macro. What is wrong in the following code ? > > newImage("test", "8-bit Black", 128, 128, 1); > makeRectangle(54, 35,10,10); > roiManager("Add"); > makeRectangle(70, 70,10,10); > roiManager("Add"); > roiManager("select",0); > setKeyDown("alt"); > roiManager("select",1); > roiManager("Combine"); > > The composite macro is displayed, but I get the error : "More than one > item must be selected, or none". Using shift as a modifier leads to > the same error. Any ideas ? > Dear Christophe, As far as I know, there is no way in a macro to select a subset of the ROIs in the ROI Manager. There does appear to be a way to programatically select multiple items in an java.awt.List. -wayne So basically it cannot be done... Too bad this java.awt.List seems a bit limited (another gripe is that you cannot expand the ROI manager window to see more ROIs or to see longer names, at least on OSX). Christophe On Tue, Jul 29, 2008 at 16:41, John Alexander <[hidden email]> wrote: > I think the confusion is that you are creating ONE roi - and not two. A > ROI does not have to be contiguous. So, when using the shift key, you > are still making ONE roi (in two parts). So, the macro is working just > fine, it is measuring the content in that one roi. > > Since I am not sure what you want to do ... > > if you want a measure for each roi ... > > roiManager("Select", 0); > roiManager("measure"); > roiManager("Select", 1); > roiManager("measure"); > > > > Thomas Boudier wrote: > > Jan Eglinger a écrit : > >> Hello Thomas, > >> > >>> I would like to write a macro that select several rois, but it seems > >>> that the "Shift" key is not taking into account while selecting : > >>> > >>> roiManager("Select", 1); > >>> setKeyDown("shift"); > >>> roiManager("Select", 2); > >>> > >>> this macro will select only roi2, while I would like roi1 and 2 to be > >>> selected. > >>> > >> > >> This code works fine for me (tried with v1.41c and v1.41i on WinXP), > >> i.e. it selects the combination of the two ROIs. > >> I tried only with rectangular ROIs, however. > > > > Hi, > > > > I'm running ImageJ 1.41i on linux with java1.6.0_06, what I would like > > is to select specifically two rois (to perform some computation on > > them), when I run this code : > > > > roiManager("Select", 0); > > setKeyDown("shift"); > > roiManager("Select", 1); > > roiManager("measure"); > > > > > > I only have one measure instead of two. Not sure if the shift key > > applies to the list inside roiManager or to Rois in the image where they > > are combined. > > > > Thomas > > > >> > >> best, > >> jan > >> > > > > > > -- > John K. Alexander, Ph.D. > Post-Doctoral Fellow > William Green Laboratory > University of Chicago > Dept. Neurobiology, Pharmacology, and Physiology > 947 East 58th Street > Abott Hall 402 > Chicago, IL 60637 > (off) 773-702-9386 > (fax) 773-702-3774 > [hidden email] > |
In reply to this post by Thomas Boudier
This doesn't really answer the original poster's question, but this may address yours, Christophe. Here is a macro function for combining an arbitrary number of selections. There may be a better way, but this seems to work (code below).
toby newImage("test", "8-bit Black", 128, 128, 1); makeRectangle(54, 35,10,10); roiManager("Add"); makeRectangle(70, 70,10,10); roiManager("Add"); rois = newArray(0, 1); index = combineSelections(rois,true); print ("new index = "+index); exit(); // FUNCTIONS BELOW ================================ function combineSelections(rois,deleteOriginals) { // get the mimimum width and height for a scratch image scratchWidth=0; scratchHeight=0; for (i =0; i < rois.length; i++) { roiManager("select",rois[i]); getSelectionBounds(x, y, width, height); if (x+width>scratchWidth) scratchWidth = x+width; if (y+height>scratchHeight) scratchHeight = y+height; } //create scratch image newImage("scratch", "8-bit Black", scratchWidth, scratchHeight, 1); selectWindow("scratch"); // fill and combine the selections for (i =0; i < rois.length; i++) { roiManager("select",rois[i]); run("Add...", "value=255"); } run("Select All"); run("Invert LUT"); run("Create Selection"); roiManager("Add"); //cleanup if (deleteOriginals) { sort(rois); for (i =0; i < rois.length; i++) { roiManager("select",rois[i]-i); roiManager("Delete"); } } selectWindow("scratch"); close(); // return the new selection index newIndex = roiManager("Count")-1; roiManager("select",newIndex); return newIndex; } // wayne's qsort function sort(a) {quickSort(a, 0, lengthOf(a)-1);} function quickSort(a, from, to) { i = from; j = to; center = a[(from+to)/2]; do { while (i<to && center>a[i]) i++; while (j>from && center<a[j]) j--; if (i<j) {temp=a[i]; a[i]=a[j]; a[j]=temp;} if (i<=j) {i++; j--;} } while(i<=j); if (from<j) quickSort(a, from, j); if (i<to) quickSort(a, i, to); } >Date: Tue, 29 Jul 2008 17:12:24 +0200 >From: Christophe Leterrier <[hidden email]> >Subject: Re: roi select two rois > >There is indeed a problem with selecting multiple ROIs in a macro. This is >more easily seen when trying to use the "Combine" command on two selected >ROIs in a macro. Below is a question I sent a few days ago and the response >of Wayne Rasband : > > > I would like to select two ROIs in the manager and combine them in a >> macro. What is wrong in the following code ? >> >> newImage("test", "8-bit Black", 128, 128, 1); >> makeRectangle(54, 35,10,10); >> roiManager("Add"); >> makeRectangle(70, 70,10,10); >> roiManager("Add"); >> roiManager("select",0); >> setKeyDown("alt"); >> roiManager("select",1); >> roiManager("Combine"); >> >> The composite macro is displayed, but I get the error : "More than one >> item must be selected, or none". Using shift as a modifier leads to >> the same error. Any ideas ? >> > >Dear Christophe, > >As far as I know, there is no way in a macro to select a subset of the ROIs >in the ROI Manager. There does appear to be a way to programatically select >multiple items in an java.awt.List. > >-wayne > >So basically it cannot be done... Too bad this java.awt.List seems a bit >limited (another gripe is that you cannot expand the ROI manager window to >see more ROIs or to see longer names, at least on OSX). > >Christophe Toby C. Cornish, M.D., Ph.D. Pathology Resident Johns Hopkins Medical Institutions [hidden email] |
Free forum by Nabble | Edit this page |