dear Experts,
i am writing Java code that deletes ROIs from the ROI-manager, based on measurement results in the Results Table. the code below works, but it is slow, i think because it graphically updates the ROI-manager at each step. does one of you happen to have some faster code?! i tried using the method *setSelectedIndexes<http://rsbweb.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#setSelectedIndexes(int[])> *(int[] indexes) to delete multiple particles at once, but i could not get it to work. thanks in advance!! Tischi ---- CODE -------- // declare int i; int iCol; double v; // get number of rows ResultsTable rt = ResultsTable.getResultsTable(); iCol = rt.getColumnIndex(colname); if(iCol == -1) return; // return if there are no entries float[] values = (float[])rt.getColumn(rt.getColumnIndex(colname)); int n = values.length; // get RoiManager RoiManager manager = RoiManager.getInstance(); manager.runCommand("Deselect"); // delete bad particles (not within thresholds) for (i = 0; i < n; i++) { v = rt.getValue(colname,i); // get next value if ( (v > th_max) || (v < th_min) ) { // particle is not good => delete manager.select(i); manager.runCommand("Delete"); rt.deleteRow(i); rt.updateResults(); rt.show("Results"); // update indexes because we have one particle less now n=n-1; i=i-1; } } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Sep 10, 2012, at 9:51 AM, Christian Tischer wrote:
> dear Experts, > > i am writing Java code that deletes ROIs from the ROI-manager, based on > measurement results in the Results Table. > > the code below works, but it is slow, i think because it graphically > updates the ROI-manager at each step. > > does one of you happen to have some faster code?! Here is a JavaScript version of your code that deletes all but 806 of 5097 ROIs from the ROI Manager in a a fraction of a second. It is fast because the image is not displayed (so it does not need updating) and the results table is updated only once. It requires the ImageJ 1.47d daily build, which fixes a bug that caused the RoiManager.select() method to display an error message if no image was open. -wayne IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); IJ.setAutoThreshold(imp, "Default"); IJ.run(imp, "Analyze Particles...", "display clear add"); rt = ResultsTable.getResultsTable(); n = rt.getCounter(); manager = RoiManager.getInstance(); manager.runCommand("Deselect"); for (i=n-1; i>=0; i--) { v = rt.getValue("Area", i); if (v>200 || v<50) { manager.select(i); manager.runCommand("Delete"); rt.deleteRow(i); } } > i tried using the method > *setSelectedIndexes<http://rsbweb.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#setSelectedIndexes(int[])> > *(int[] indexes) > to delete multiple particles at once, but i could not get it to work. > > thanks in advance!! > Tischi > > > ---- CODE -------- > > > // declare > int i; > int iCol; > double v; > // get number of rows > ResultsTable rt = ResultsTable.getResultsTable(); > iCol = rt.getColumnIndex(colname); if(iCol == -1) return; // return if > there are no entries > float[] values = (float[])rt.getColumn(rt.getColumnIndex(colname)); > int n = values.length; > > // get RoiManager > RoiManager manager = RoiManager.getInstance(); > manager.runCommand("Deselect"); > > // delete bad particles (not within thresholds) > > for (i = 0; i < n; i++) { > v = rt.getValue(colname,i); // get next value > if ( (v > th_max) || (v < th_min) ) { // particle is not good => delete > manager.select(i); > manager.runCommand("Delete"); > rt.deleteRow(i); > rt.updateResults(); > rt.show("Results"); > // update indexes because we have one > particle less now > n=n-1; > i=i-1; > } > } > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Wayne,
thanks a lot for the answer! two questions: - how do i update to the daily Imagej build? (i am using FIJI...) - does your code require that there are strictly no windows open or do i have to just somehow deactivate them? the issue being that i have several images open at that point and i need to keep them for further analysis... thanks! Tischi On Mon, Sep 10, 2012 at 9:50 PM, Rasband, Wayne (NIH/NIMH) [E] < [hidden email]> wrote: > On Sep 10, 2012, at 9:51 AM, Christian Tischer wrote: > > > dear Experts, > > > > i am writing Java code that deletes ROIs from the ROI-manager, based on > > measurement results in the Results Table. > > > > the code below works, but it is slow, i think because it graphically > > updates the ROI-manager at each step. > > > > does one of you happen to have some faster code?! > > Here is a JavaScript version of your code that deletes all but 806 of 5097 > ROIs from the ROI Manager in a a fraction of a second. It is fast because > the image is not displayed (so it does not need updating) and the results > table is updated only once. It requires the ImageJ 1.47d daily build, which > fixes a bug that caused the RoiManager.select() method to display an error > message if no image was open. > > -wayne > > IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); > imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); > IJ.setAutoThreshold(imp, "Default"); > IJ.run(imp, "Analyze Particles...", "display clear add"); > > rt = ResultsTable.getResultsTable(); > n = rt.getCounter(); > manager = RoiManager.getInstance(); > manager.runCommand("Deselect"); > for (i=n-1; i>=0; i--) { > v = rt.getValue("Area", i); > if (v>200 || v<50) { > manager.select(i); > manager.runCommand("Delete"); > rt.deleteRow(i); > } > } > > > > i tried using the method > > *setSelectedIndexes< > http://rsbweb.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#setSelectedIndexes(int[]) > > > > *(int[] indexes) > > to delete multiple particles at once, but i could not get it to work. > > > > thanks in advance!! > > Tischi > > > > > > ---- CODE -------- > > > > > > // declare > > int i; > > int iCol; > > double v; > > // get number of rows > > ResultsTable rt = ResultsTable.getResultsTable(); > > iCol = rt.getColumnIndex(colname); if(iCol == -1) return; // return if > > there are no entries > > float[] values = (float[])rt.getColumn(rt.getColumnIndex(colname)); > > int n = values.length; > > > > // get RoiManager > > RoiManager manager = RoiManager.getInstance(); > > manager.runCommand("Deselect"); > > > > // delete bad particles (not within thresholds) > > > > for (i = 0; i < n; i++) { > > v = rt.getValue(colname,i); // get next value > > if ( (v > th_max) || (v < th_min) ) { // particle is not good => delete > > manager.select(i); > > manager.runCommand("Delete"); > > rt.deleteRow(i); > > rt.updateResults(); > > rt.show("Results"); > > // update indexes because we have one > > particle less now > > n=n-1; > > i=i-1; > > } > > } > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Wed, Sep 12, 2012 at 9:07 AM, Christian Tischer <
[hidden email]> wrote: > Dear Wayne, > > thanks a lot for the answer! > > two questions: > > - how do i update to the daily Imagej build? (i am using FIJI...) > > - does your code require that there are strictly no windows open or do i > have to just somehow deactivate them? > the issue being that i have several images open at that point and i need to > keep them for further analysis... > > thanks! > > Tischi > > Hi Tischi, for the first question > - how do i update to the daily Imagej build? (i am using FIJI...) Help > Update ImageJ... and then in the dialog window, click drop-down menu and choose "daily build" at the bottom. Cheers, Kota > > > > > On Mon, Sep 10, 2012 at 9:50 PM, Rasband, Wayne (NIH/NIMH) [E] < > [hidden email]> wrote: > > > On Sep 10, 2012, at 9:51 AM, Christian Tischer wrote: > > > > > dear Experts, > > > > > > i am writing Java code that deletes ROIs from the ROI-manager, based on > > > measurement results in the Results Table. > > > > > > the code below works, but it is slow, i think because it graphically > > > updates the ROI-manager at each step. > > > > > > does one of you happen to have some faster code?! > > > > Here is a JavaScript version of your code that deletes all but 806 of > 5097 > > ROIs from the ROI Manager in a a fraction of a second. It is fast because > > the image is not displayed (so it does not need updating) and the results > > table is updated only once. It requires the ImageJ 1.47d daily build, > which > > fixes a bug that caused the RoiManager.select() method to display an > error > > message if no image was open. > > > > -wayne > > > > IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); > > imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); > > IJ.setAutoThreshold(imp, "Default"); > > IJ.run(imp, "Analyze Particles...", "display clear add"); > > > > rt = ResultsTable.getResultsTable(); > > n = rt.getCounter(); > > manager = RoiManager.getInstance(); > > manager.runCommand("Deselect"); > > for (i=n-1; i>=0; i--) { > > v = rt.getValue("Area", i); > > if (v>200 || v<50) { > > manager.select(i); > > manager.runCommand("Delete"); > > rt.deleteRow(i); > > } > > } > > > > > > > i tried using the method > > > *setSelectedIndexes< > > > http://rsbweb.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#setSelectedIndexes(int[]) > > > > > > *(int[] indexes) > > > to delete multiple particles at once, but i could not get it to work. > > > > > > thanks in advance!! > > > Tischi > > > > > > > > > ---- CODE -------- > > > > > > > > > // declare > > > int i; > > > int iCol; > > > double v; > > > // get number of rows > > > ResultsTable rt = ResultsTable.getResultsTable(); > > > iCol = rt.getColumnIndex(colname); if(iCol == -1) return; // return if > > > there are no entries > > > float[] values = (float[])rt.getColumn(rt.getColumnIndex(colname)); > > > int n = values.length; > > > > > > // get RoiManager > > > RoiManager manager = RoiManager.getInstance(); > > > manager.runCommand("Deselect"); > > > > > > // delete bad particles (not within thresholds) > > > > > > for (i = 0; i < n; i++) { > > > v = rt.getValue(colname,i); // get next value > > > if ( (v > th_max) || (v < th_min) ) { // particle is not good => > delete > > > manager.select(i); > > > manager.runCommand("Delete"); > > > rt.deleteRow(i); > > > rt.updateResults(); > > > rt.show("Results"); > > > // update indexes because we have one > > > particle less now > > > n=n-1; > > > i=i-1; > > > } > > > } > > > > > > -- > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- -------------------------------------------------------------*Dr. Kota Miura* Scientist & IT Engineer Centre for Molecular and Cellular Imaging, European Molecular Biology Laboratory Meyerhofstr. 1 69117 Heidelberg GERMANY Tel +49 6221 387 404 Mobile +49 160 95001177 Fax +49 6221 387 512 http://cmci.embl.de ------------------------------------------------------------- -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Christian Tischer
On Sep 12, 2012, at 3:07 AM, Christian Tischer wrote:
> Dear Wayne, > > thanks a lot for the answer! > > two questions: > > - how do i update to the daily Imagej build? (i am using FIJI...) Use the Help>Update ImageJ command and select "daily build" from the drop down menu. > - does your code require that there are strictly no windows open or do i > have to just somehow deactivate them? > the issue being that i have several images open at that point and i need to > keep them for further analysis... The test code (shown below) runs 12 times slower (2.5 seconds vs 0.2 seconds) if the image is displayed by adding imp.show() at line 3. It runs less than 2 times slower if the image is displayed but the ROI Manager is not is in "Show All" mode, as a result of adding the manager.runCommand("Show None") call in line 11. -wayne IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); imp.show(); IJ.setAutoThreshold(imp, "Default"); IJ.run(imp, "Analyze Particles...", "display clear add"); rt = ResultsTable.getResultsTable(); n = rt.getCounter(); manager = RoiManager.getInstance(); manager.runCommand("Deselect"); manager.runCommand("Show None"); start = System.currentTimeMillis(); for (i=n-1; i>=0; i--) { v = rt.getValue("Area", i); if (v>200 || v<50) { manager.select(i); manager.runCommand("Delete"); rt.deleteRow(i); } } rt.show("Results"); print(System.currentTimeMillis()-start); > On Mon, Sep 10, 2012 at 9:50 PM, Rasband, Wayne (NIH/NIMH) [E] < > [hidden email]> wrote: > >> On Sep 10, 2012, at 9:51 AM, Christian Tischer wrote: >> >>> dear Experts, >>> >>> i am writing Java code that deletes ROIs from the ROI-manager, based on >>> measurement results in the Results Table. >>> >>> the code below works, but it is slow, i think because it graphically >>> updates the ROI-manager at each step. >>> >>> does one of you happen to have some faster code?! >> >> Here is a JavaScript version of your code that deletes all but 806 of 5097 >> ROIs from the ROI Manager in a a fraction of a second. It is fast because >> the image is not displayed (so it does not need updating) and the results >> table is updated only once. It requires the ImageJ 1.47d daily build, which >> fixes a bug that caused the RoiManager.select() method to display an error >> message if no image was open. >> >> -wayne >> >> IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); >> imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); >> IJ.setAutoThreshold(imp, "Default"); >> IJ.run(imp, "Analyze Particles...", "display clear add"); >> >> rt = ResultsTable.getResultsTable(); >> n = rt.getCounter(); >> manager = RoiManager.getInstance(); >> manager.runCommand("Deselect"); >> for (i=n-1; i>=0; i--) { >> v = rt.getValue("Area", i); >> if (v>200 || v<50) { >> manager.select(i); >> manager.runCommand("Delete"); >> rt.deleteRow(i); >> } >> } >> >> >>> i tried using the method >>> *setSelectedIndexes< >> http://rsbweb.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#setSelectedIndexes(int[]) >>> >>> *(int[] indexes) >>> to delete multiple particles at once, but i could not get it to work. >>> >>> thanks in advance!! >>> Tischi >>> >>> >>> ---- CODE -------- >>> >>> >>> // declare >>> int i; >>> int iCol; >>> double v; >>> // get number of rows >>> ResultsTable rt = ResultsTable.getResultsTable(); >>> iCol = rt.getColumnIndex(colname); if(iCol == -1) return; // return if >>> there are no entries >>> float[] values = (float[])rt.getColumn(rt.getColumnIndex(colname)); >>> int n = values.length; >>> >>> // get RoiManager >>> RoiManager manager = RoiManager.getInstance(); >>> manager.runCommand("Deselect"); >>> >>> // delete bad particles (not within thresholds) >>> >>> for (i = 0; i < n; i++) { >>> v = rt.getValue(colname,i); // get next value >>> if ( (v > th_max) || (v < th_min) ) { // particle is not good => delete >>> manager.select(i); >>> manager.runCommand("Delete"); >>> rt.deleteRow(i); >>> rt.updateResults(); >>> rt.show("Results"); >>> // update indexes because we have one >>> particle less now >>> n=n-1; >>> i=i-1; >>> } >>> } >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi,
I am using the macro "serial ext" to access a serial port to both pilot an instrument and read data and status messages associated with image acquisition. The tool works perfectly on WXp 32bits systems while it is unstable on W7 64bits systems. There are no error displayed but the data read on the COM port are corrupted. Note that I have installed the convenient files that has not been updated since 2011 apparently. http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:serial_macro_extensions:start linked with : http://rxtx.qbang.org/wiki/index.php/Download As we must migrate to W7 x64bits systems, I must find a solution for that. Does someone has an idea ? Regards Marc P. -- Marc Picheral Engineer CNRS UPMC LOV 181 Chemin du Lazaret 06230 Villefranche sur mer tel : 33 +4 93 76 38 08 fax : 33 +4 93 76 38 34 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Marc,
I just left a Samsung W7 64-bit system that uses RXTX and the ImageJ serial extension with a collaborator in Italy. During the last few weeks since I installed RXTX on this machine, I haven't noticed any glitches. The commands sent to the external serial device only generated text return values. It would be possible to check with my collaborator and have him send me a copy of the RXTX pieces I installed, which could be forwarded to you. Unfortunately, I just left for home today and won't have a chance to do this until next week. I can tell you that I used a version that uses the gnu.io namespace, but I'm not sure which one. I believe it was a "CloudHopper" version, available via http://www.cloudhopper.com/opensource/rxtx/ but I would want to confirm this before forwarding it. Incidentally, I HAVE had a problem with RXTX on my Macos Lion laptop, in which I've recently installed a different gnu.io namespace version. The problem I encounter there is related to lock files: I can open and close a port exactly once. If I open a port, do some communication over the port, and then close the port, all seems well. But attempts to repeat this fail until I shut down and restart the machine. This is the hallmark of vestigial lock files. I'm still trying to figure out this problem and how to overcome it. hth... Bill Christens-Barry -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
Dear Wayne,
thanks for the suggestions. i think i got everything running now and it really is faster! thanks a lot!! to your code i added: ImagePlus imp = IJ.getImage(); imp.hide(); and an imp.show() in the end Cheers, Tischi On Wed, Sep 12, 2012 at 8:14 PM, Rasband, Wayne (NIH/NIMH) [E] < [hidden email]> wrote: > On Sep 12, 2012, at 3:07 AM, Christian Tischer wrote: > > > Dear Wayne, > > > > thanks a lot for the answer! > > > > two questions: > > > > - how do i update to the daily Imagej build? (i am using FIJI...) > > Use the Help>Update ImageJ command and select "daily build" from the drop > down menu. > > > - does your code require that there are strictly no windows open or do i > > have to just somehow deactivate them? > > the issue being that i have several images open at that point and i need > to > > keep them for further analysis... > > The test code (shown below) runs 12 times slower (2.5 seconds vs 0.2 > seconds) if the image is displayed by adding imp.show() at line 3. It runs > less than 2 times slower if the image is displayed but the ROI Manager is > not is in "Show All" mode, as a result of adding the > manager.runCommand("Show None") call in line 11. > > -wayne > > IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); > imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); > imp.show(); > IJ.setAutoThreshold(imp, "Default"); > IJ.run(imp, "Analyze Particles...", "display clear add"); > > rt = ResultsTable.getResultsTable(); > n = rt.getCounter(); > manager = RoiManager.getInstance(); > manager.runCommand("Deselect"); > manager.runCommand("Show None"); > start = System.currentTimeMillis(); > for (i=n-1; i>=0; i--) { > v = rt.getValue("Area", i); > if (v>200 || v<50) { > manager.select(i); > manager.runCommand("Delete"); > rt.deleteRow(i); > } > } > rt.show("Results"); > print(System.currentTimeMillis()-start); > > > > On Mon, Sep 10, 2012 at 9:50 PM, Rasband, Wayne (NIH/NIMH) [E] < > > [hidden email]> wrote: > > > >> On Sep 10, 2012, at 9:51 AM, Christian Tischer wrote: > >> > >>> dear Experts, > >>> > >>> i am writing Java code that deletes ROIs from the ROI-manager, based on > >>> measurement results in the Results Table. > >>> > >>> the code below works, but it is slow, i think because it graphically > >>> updates the ROI-manager at each step. > >>> > >>> does one of you happen to have some faster code?! > >> > >> Here is a JavaScript version of your code that deletes all but 806 of > 5097 > >> ROIs from the ROI Manager in a a fraction of a second. It is fast > because > >> the image is not displayed (so it does not need updating) and the > results > >> table is updated only once. It requires the ImageJ 1.47d daily build, > which > >> fixes a bug that caused the RoiManager.select() method to display an > error > >> message if no image was open. > >> > >> -wayne > >> > >> IJ.run("Set Measurements...", "area mean redirect=None decimal=1"); > >> imp = IJ.openImage("http://imagej.nih.gov/ij/images/particles.gif"); > >> IJ.setAutoThreshold(imp, "Default"); > >> IJ.run(imp, "Analyze Particles...", "display clear add"); > >> > >> rt = ResultsTable.getResultsTable(); > >> n = rt.getCounter(); > >> manager = RoiManager.getInstance(); > >> manager.runCommand("Deselect"); > >> for (i=n-1; i>=0; i--) { > >> v = rt.getValue("Area", i); > >> if (v>200 || v<50) { > >> manager.select(i); > >> manager.runCommand("Delete"); > >> rt.deleteRow(i); > >> } > >> } > >> > >> > >>> i tried using the method > >>> *setSelectedIndexes< > >> > http://rsbweb.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#setSelectedIndexes(int[]) > >>> > >>> *(int[] indexes) > >>> to delete multiple particles at once, but i could not get it to work. > >>> > >>> thanks in advance!! > >>> Tischi > >>> > >>> > >>> ---- CODE -------- > >>> > >>> > >>> // declare > >>> int i; > >>> int iCol; > >>> double v; > >>> // get number of rows > >>> ResultsTable rt = ResultsTable.getResultsTable(); > >>> iCol = rt.getColumnIndex(colname); if(iCol == -1) return; // return if > >>> there are no entries > >>> float[] values = (float[])rt.getColumn(rt.getColumnIndex(colname)); > >>> int n = values.length; > >>> > >>> // get RoiManager > >>> RoiManager manager = RoiManager.getInstance(); > >>> manager.runCommand("Deselect"); > >>> > >>> // delete bad particles (not within thresholds) > >>> > >>> for (i = 0; i < n; i++) { > >>> v = rt.getValue(colname,i); // get next value > >>> if ( (v > th_max) || (v < th_min) ) { // particle is not good => > delete > >>> manager.select(i); > >>> manager.runCommand("Delete"); > >>> rt.deleteRow(i); > >>> rt.updateResults(); > >>> rt.show("Results"); > >>> // update indexes because we have one > >>> particle less now > >>> n=n-1; > >>> i=i-1; > >>> } > >>> } > >>> > >>> -- > >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > >> > >> -- > >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > >> > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |