Dear Listers,
just to inform you about an issue, which did not happen (to me) previously. Maybe it's a feature, I'd rather consider it as (slightly) buggy - is the case with 1.48b and c (on Win7, 64-bit). I open a series of images, say 20 and run this macro: //snip run("Set Measurements...", "area mean min integrated redirect=None decimal=2"); n=nImages; for(i=0; i<n; i++) { name=getTitle(); Stack.setPosition(2, 1, 1); run("Duplicate...", "title=work channels=1-3"); selectWindow(name); close(); *wait(500);* run("Subtract Background...", "rolling=25 sliding disable"); *wait(500);* run("Measure"); setResult("Description", i, name); updateResults(); selectWindow("work"); close(); *wait(500);* } //snip without the "WAIT(500);" commands, ImageJ does not necessarily waits until the previous operation is finished and already performs the next. In that scenario, I obvioulsy wanted to subtract the background BEFORE measuring integrated densities. Every now and then (10-30% of the processed images), irregularities occured, i.e. suddenly the mean grey value was 10fold higher (in comparable images). Processing the images manually produced expected results. after I added the two middle wait commands, measurement results were ok. But then it happened that, ImageJ did not necessarily wait until the previous "work" image was closed and already started the next iteration. This became obvious as suddenly the NAME variable did not contain the image title of the next image but rather the place-holder "work". Again, adding the wait comman eliminated that problem. cheers, Johannes -- *Dr. Johannes Koch* *Tissue Med Biosciences GmbH* Magnesitstrasse1 | A-3500 Krems T: +43/2732/87470-300 | M: [hidden email] <mailto:[hidden email]> *www.tmbiosciences.com <http://www.tmbiosciences.com/>* Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Information. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte unverzüglich den Absender und vernichten Sie diese E-Mail sofort. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail sind nicht gestattet. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Tuesday 17 Sep 2013 10:56:36 you wrote:
> I open a series of images, say 20 and run this macro: > > //snip > run("Set Measurements...", "area mean min integrated redirect=None > decimal=2"); > > n=nImages; > > for(i=0; i<n; i++) { > name=getTitle(); > Stack.setPosition(2, 1, 1); > run("Duplicate...", "title=work channels=1-3"); > selectWindow(name); > close(); > *wait(500);* > run("Subtract Background...", "rolling=25 sliding disable"); You need to specify this with SelectWindow(your_image_name) just before preforming the Subtract Background command to make sure that the process is on the correct one. The macro above selects an image and immediately closes it on the next line, so which image is the one being processed now? Regards Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks!
It seems I missed the logic. I thought ImageJ takes the next-to-last image (created by the duplicate command) when the last image is closed. This is obviously not (always) the case...but in the majority. Why then had selectWindow() the same effect as the wait() command.... that however, still does not seem to be very logic to me. ... what do I miss here? Johannes *Dr. Johannes Koch* *Tissue Med Biosciences GmbH* Magnesitstrasse1 | A-3500 Krems T: +43/2732/87470-300 | M: [hidden email] <mailto:[hidden email]> *www.tmbiosciences.com <http://www.tmbiosciences.com/>* Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Information. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte unverzüglich den Absender und vernichten Sie diese E-Mail sofort. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail sind nicht gestattet. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Am 17.09.2013 12:34, schrieb Gabriel Landini: > On Tuesday 17 Sep 2013 10:56:36 you wrote: >> I open a series of images, say 20 and run this macro: >> >> //snip >> run("Set Measurements...", "area mean min integrated redirect=None >> decimal=2"); >> >> n=nImages; >> >> for(i=0; i<n; i++) { >> name=getTitle(); >> Stack.setPosition(2, 1, 1); >> run("Duplicate...", "title=work channels=1-3"); >> selectWindow(name); >> close(); >> *wait(500);* >> run("Subtract Background...", "rolling=25 sliding disable"); > [...] > > You need to specify this with SelectWindow(your_image_name) just before > preforming the Subtract Background command to make sure that the process is on > the correct one. > The macro above selects an image and immediately closes it on the next line, > so which image is the one being processed now? > > Regards > Gabriel > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Tuesday 17 Sep 2013 13:16:43 you wrote:
> Thanks! > > It seems I missed the logic. I thought ImageJ takes the next-to-last > image (created by the duplicate command) when the last image is closed. > This is obviously not (always) the case...but in the majority. > > Why then had selectWindow() the same effect as the wait() command.... > that however, still does not seem to be very logic to me. > > ... what do I miss here? I think that you are not selecting the right images >> for(i=0; i<n; i++) { >> name=getTitle(); I bet that this is not cycling through all open images. Perhaps you need to generate an array of titles, then use the variable i to select the ith image name in the array. Cheers G -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Gabriel Landini
Hi Gabriel,
well, in principle, running a macro in ImageJ should be deterministic... The current problem sounds like a race condition to me, a frequent problem due to the multi-threaded nature of Java. The user interface runs in a different thread, thus operations like closing a window are not necessarily synchronous with the remaining code. There are already a lot of fixes for such problems in ImageJ, but there are still unfixed issues. E.g., it sometimes happens to me that the image window decorated as the front window by the operating system (Mac OS X) is different from the foreground image of ImageJ. Diagnosing such issues would be certainly welcome. Anyhow, Johannes, we need one more bit of information: is the macro running in BatchMode or not? Michael ________________________________________________________________ On Sep 17, 2013, at 12:34, Gabriel Landini wrote: > On Sep 17, 2013, at 11:56, Johannes Koch wrote: >> I open a series of images, say 20 and run this macro: >> >> //snip >> run("Set Measurements...", "area mean min integrated redirect=None >> decimal=2"); >> >> n=nImages; >> >> for(i=0; i<n; i++) { >> name=getTitle(); >> Stack.setPosition(2, 1, 1); >> run("Duplicate...", "title=work channels=1-3"); >> selectWindow(name); >> close(); >> *wait(500);* >> run("Subtract Background...", "rolling=25 sliding disable"); > [...] > > You need to specify this with SelectWindow(your_image_name) just before > preforming the Subtract Background command to make sure that the process is on > the correct one. > The macro above selects an image and immediately closes it on the next line, > so which image is the one being processed now? > > Regards > Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Gabriel Landini
On Sep 17, 2013, at 14:43, Gabriel Landini wrote:
> I think that you are not selecting the right images > >>> for(i=0; i<n; i++) { >>> name=getTitle(); > > I bet that this is not cycling through all open images. oops, I agree, I missed this point. You should add something like selectImage(i+1); as a first command in the loop. This assumes no other images are open. Actually, it is surprising why the macro could work anyhow. Michael ___________________________________________________________________ > //snip > run("Set Measurements...", "area mean min integrated redirect=None decimal=2"); > > n=nImages; > > for(i=0; i<n; i++) { > name=getTitle(); > Stack.setPosition(2, 1, 1); > run("Duplicate...", "title=work channels=1-3"); > selectWindow(name); > close(); > *wait(500);* > run("Subtract Background...", "rolling=25 sliding disable"); > *wait(500);* > run("Measure"); > > setResult("Description", i, name); > updateResults(); > > selectWindow("work"); > close(); > *wait(500);* > } > //snip -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
On Tuesday 17 Sep 2013 13:44:59 Michael Schmid wrote:
> well, in principle, running a macro in ImageJ should be deterministic... > > The current problem sounds like a race condition to me, a frequent problem > due to the multi-threaded nature of Java. Yes, deterministic, but results might vary if the initial conditions are note the same ;-) I think the macro might be taking a non-specified image to get the title and process it. As I said I did not run it, just my suggestion from looking at the code. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks Michael and Gabriel for the inputs. As the macro works as
expected (now) I do not want to break off time (and nerve) consuming diagnosis. The only thing is that I am confused that selectWindow had the same effect as a wait command. Maybe it is as Michael wrote, I am running on a i7-3770 @ 3.4GHz with 16GB RAM. Maybe that by selecting the image, the code does not have a chance to wait for the previous operation. To answer your questions: atm, the macro doesn't run in batch mode. I do not cycle through the images, as I close all processed images within the loop (and I annotate the results with the title). No need for keeping them open. In the end, this "macro" is neither very elegant nor was it intended to be. I just have a few hundred images at hand from which I want to extract some information and I was naturally too lazy for manual processing. Since I am not coming from the informatics side-of-life, I unwantedly produced some logic errors (in code-writing). Mistakes, a programmer would not do (even *if* there was a problem with multithreads and/or other things). Anyway, I will keep that in mind for the future! Best, Johannes *Dr. Johannes Koch* *Tissue Med Biosciences GmbH* Magnesitstrasse1 | A-3500 Krems T: +43/2732/87470-300 | M: [hidden email] <mailto:[hidden email]> *www.tmbiosciences.com <http://www.tmbiosciences.com/>* Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Information. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte unverzüglich den Absender und vernichten Sie diese E-Mail sofort. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail sind nicht gestattet. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Am 17.09.2013 15:14, schrieb Gabriel Landini: > On Tuesday 17 Sep 2013 13:44:59 Michael Schmid wrote: >> well, in principle, running a macro in ImageJ should be deterministic... >> >> The current problem sounds like a race condition to me, a frequent problem >> due to the multi-threaded nature of Java. > Yes, deterministic, but results might vary if the initial conditions are note > the same ;-) > I think the macro might be taking a non-specified image to get the title and > process it. As I said I did not run it, just my suggestion from looking at the > code. > > Cheers > Gabriel > > -- > 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 |