Benjamin Smith |
*****
To join, leave or search the confocal microscopy listserv, go to: http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy Post images on http://www.imgur.com and include the link in your posting. ***** I found a somewhat serious bug in the ImageJ macro "list" command, that causes it to incorrectly compare values such as returning "true" to the following statement: 32.0 < 6.4 I also posted this bug in the ImageJ forum, along with a minimal block of code showing the bug as well as a temporary workaround: https://forum.image.sc/t/variable-type-bug-in-the-imagej-macro-list-command/28941 I figured I ought to give the confocal listserv a heads-up as well in case this may impact anyone's data analysis. Cheers, Ben Smith -- Benjamin E. Smith, Ph. D. Imaging Specialist, Vision Science University of California, Berkeley 195 Life Sciences Addition Berkeley, CA 94720-3200 Tel (510) 642-9712 Fax (510) 643-6791 e-mail: [hidden email] http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> |
Benjamin Smith |
*****
To join, leave or search the confocal microscopy listserv, go to: http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy Post images on http://www.imgur.com and include the link in your posting. ***** Slight edit to the above post. I thought I had fully read the description in https://imagej.net/developer/macro/functions.html#L, but somehow completely missed that List.get() returns a string. I was thrown off by the the fact that in the macro language comparing a string to a number does not throw an error (such as according to ImageJ "apple" > 2 but "apple" < "pear") and that the string from List.get() can be rounded, but a string such as "1.2" cannot. I have now learned a bit more about the odd quirks of ImageJ and the inconsistent way it handles strings. You can see more details here: https://forum.image.sc/t/imagej-macro-language-seems-inconsistent-in-string-handling/28942 If anyone knows, I would definitely like to hear why "apple" > "pear", "32" < 6.4 while 32 > 6.4, and why the string returned from List.get() can be rounded but the string "1.2" throws an error if you try to round it. Cheers, Ben Smith On Thu, Aug 22, 2019 at 9:33 PM Benjamin Smith <[hidden email]> wrote: > Slight edit to the above post. I thought I had fully read the description > in https://imagej.net/developer/macro/functions.html#L, but somehow > completely missed that List.get() returns a string. The fact that in the > macro language comparing a string to a number does not throw an error (such > as according to ImageJ "apple" > 2 but "apple" < "pear") and that a string > from List.get() can be rounded, but a string such as "1.2" cannot threw me > way off track. I instead have now learned a bit more about the odd quirks > of ImageJ and the inconsistent way it handles strings. > > If anyone knows, I would definitely like to hear why "apple" > "pear", > "32" < 6.4 while 32 > 6.4, and why the string returned from list.get() can > be rounded but the string "1.2" throws an error if you try to round it. > > Cheers, > Ben Smith > > On Thu, Aug 22, 2019 at 8:50 PM Benjamin Smith < > [hidden email]> wrote: > >> I found a somewhat serious bug in the ImageJ macro "list" command, that >> causes it to incorrectly compare values such as returning "true" to the >> following statement: >> 32.0 < 6.4 >> >> I also posted this bug in the ImageJ forum, along with a minimal block of >> code showing the bug as well as a temporary workaround: >> https://forum.image.sc/t/variable-type-bug-in-the-imagej-macro-list-command/28941 >> >> >> I figured I ought to give the confocal listserv a heads-up as well in >> case this may impact anyone's data analysis. >> >> Cheers, >> Ben Smith >> >> -- >> Benjamin E. Smith, Ph. D. >> Imaging Specialist, Vision Science >> University of California, Berkeley >> 195 Life Sciences Addition >> Berkeley, CA 94720-3200 >> Tel (510) 642-9712 >> Fax (510) 643-6791 >> e-mail: [hidden email] >> http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> >> > > > -- > Benjamin E. Smith, Ph. D. > Imaging Specialist, Vision Science > University of California, Berkeley > 195 Life Sciences Addition > Berkeley, CA 94720-3200 > Tel (510) 642-9712 > Fax (510) 643-6791 > e-mail: [hidden email] > http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> > -- Benjamin E. Smith, Ph. D. Imaging Specialist, Vision Science University of California, Berkeley 195 Life Sciences Addition Berkeley, CA 94720-3200 Tel (510) 642-9712 Fax (510) 643-6791 e-mail: [hidden email] http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> |
Philippe CARL |
In reply to this post by Benjamin Smith
*****
To join, leave or search the confocal microscopy listserv, go to: http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy Post images on http://www.imgur.com and include the link in your posting. ***** Dear Benjamin, In the case you have issues or find bugs within ImageJ, there is as well a mailing list specifically dedicated to these questions under: http://imagej.nih.gov/ij/list.html Nevertheless, I looked at your bug under your indicated link: https://forum.image.sc/t/variable-type-bug-in-the-imagej-macro-list-command/28941 And the issue you had is that your parameter BX in your macro isn't interpreted as an int or float but rather as a string. It is very easy to figure out this fact given that a print(BX) gives you the output "32.0" instead of "32". Thus in order to solve your issue you just need to add a parseFloat: https://imagej.nih.gov/ij/developer/macro/functions.html#parseFloat or parseInt: https://imagej.nih.gov/ij/developer/macro/functions.html#parseInt to transform your parameter BX into a float or int. And the round function you were using further: https://imagej.nih.gov/ij/developer/macro/functions.html#round is automatically making the casting of your string into a float which explains why your code worked as you expected it within your second if condition. Hoping that I helped you going further I wish you a nice day. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 ----- Mail original ----- De: "CONFOCALMICROSCOPY automatic digest system" <[hidden email]> À: [hidden email] Envoyé: Vendredi 23 Août 2019 07:00:02 Objet: CONFOCALMICROSCOPY Digest - 21 Aug 2019 to 22 Aug 2019 (#2019-186) Date: Thu, 22 Aug 2019 20:50:21 -0700 From: Benjamin Smith <[hidden email]> Subject: Bug in ImageJ/FIJI macro language ***** To join, leave or search the confocal microscopy listserv, go to: http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy Post images on http://www.imgur.com and include the link in your posting. ***** I found a somewhat serious bug in the ImageJ macro "list" command, that causes it to incorrectly compare values such as returning "true" to the following statement: 32.0 < 6.4 I also posted this bug in the ImageJ forum, along with a minimal block of code showing the bug as well as a temporary workaround: https://forum.image.sc/t/variable-type-bug-in-the-imagej-macro-list-command/28941 I figured I ought to give the confocal listserv a heads-up as well in case this may impact anyone's data analysis. Cheers, Ben Smith -- Benjamin E. Smith, Ph. D. Imaging Specialist, Vision Science University of California, Berkeley 195 Life Sciences Addition Berkeley, CA 94720-3200 Tel (510) 642-9712 Fax (510) 643-6791 e-mail: [hidden email] http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> ------------------------------ End of CONFOCALMICROSCOPY Digest - 21 Aug 2019 to 22 Aug 2019 (#2019-186) ************************************************************************* |
Benjamin Smith |
*****
To join, leave or search the confocal microscopy listserv, go to: http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy Post images on http://www.imgur.com and include the link in your posting. ***** Hey Philippe, Thank you for looking into this. The key issue I was running into was that the variable returned from "List.get()" behaves both as a String and an Int, which I go into more detail here with some examples: https://forum.image.sc/t/imagej-macro-language-seems-inconsistent-in-string-handling/28942 Stefan replied pointing out how "32.0" < 6.4 due to lexicographical sorting. However, that doesn't explain why "32.0" is always treated as a String by the ImageJ macro language, but if the string "32.0" is returned from List.get() then in some contexts that number is treated as a String (such as "32.0" + 1 = "32.01") and in other contexts it is suddenly treated as an int (round("32.0" + 1) = 33). Strings from other contexts don't behave this way in the macro language, only strings returned from the List function for some reason. Here is the macro code I wrote showing the inconsistency: > newImage("Untitled", "32-bit black", 128, 128, 1); > makeOval(32, 37, 61, 61); > List.setMeasurements; > print(List.get("BX")); //Returns 32.0 - acts like string > print(round(List.get("BX"))); //Returns 32 - acts like Int > print(round(List.get("BX")+1)); //Returns 33 - acts like Int > print(List.get("BX")+1); //Returns 32.01 - acts like string > Conversely, if you run the following code with an explicit string: > print(round('32.0')); It will not be treated as an int, and instead you will get the following error: > Macro Error: Number or numeric function expected in line 1 > So I guess the core of my question is why are strings from the List function treated so differently than strings from anywhere else. Also, the simplest solution to my original problem was to use the List.getValue() command, but now I'm really curious what is going on with the List.get() command. Thanks again for any insights, Ben Smith On Fri, Aug 23, 2019 at 1:02 AM CARL Philippe (LBP) < [hidden email]> wrote: > ***** > To join, leave or search the confocal microscopy listserv, go to: > http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy > Post images on http://www.imgur.com and include the link in your posting. > ***** > > Dear Benjamin, > In the case you have issues or find bugs within ImageJ, there is as well a > mailing list specifically dedicated to these questions under: > http://imagej.nih.gov/ij/list.html > Nevertheless, I looked at your bug under your indicated link: > > https://forum.image.sc/t/variable-type-bug-in-the-imagej-macro-list-command/28941 > And the issue you had is that your parameter BX in your macro isn't > interpreted as an int or float but rather as a string. > It is very easy to figure out this fact given that a print(BX) gives you > the output "32.0" instead of "32". > Thus in order to solve your issue you just need to add a parseFloat: > https://imagej.nih.gov/ij/developer/macro/functions.html#parseFloat > or parseInt: > https://imagej.nih.gov/ij/developer/macro/functions.html#parseInt > to transform your parameter BX into a float or int. > And the round function you were using further: > https://imagej.nih.gov/ij/developer/macro/functions.html#round > is automatically making the casting of your string into a float which > explains why your code worked as you expected it within your second if > condition. > Hoping that I helped you going further I wish you a nice day. > My best regards, > Philippe > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > ----- Mail original ----- > De: "CONFOCALMICROSCOPY automatic digest system" <[hidden email]> > À: [hidden email] > Envoyé: Vendredi 23 Août 2019 07:00:02 > Objet: CONFOCALMICROSCOPY Digest - 21 Aug 2019 to 22 Aug 2019 (#2019-186) > > Date: Thu, 22 Aug 2019 20:50:21 -0700 > From: Benjamin Smith <[hidden email]> > Subject: Bug in ImageJ/FIJI macro language > > ***** > To join, leave or search the confocal microscopy listserv, go to: > http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy > Post images on http://www.imgur.com and include the link in your posting. > ***** > > I found a somewhat serious bug in the ImageJ macro "list" command, that > causes it to incorrectly compare values such as returning "true" to the > following statement: > 32.0 < 6.4 > > I also posted this bug in the ImageJ forum, along with a minimal block of > code showing the bug as well as a temporary workaround: > > https://forum.image.sc/t/variable-type-bug-in-the-imagej-macro-list-command/28941 > > > I figured I ought to give the confocal listserv a heads-up as well in case > this may impact anyone's data analysis. > > Cheers, > Ben Smith > > -- > Benjamin E. Smith, Ph. D. > Imaging Specialist, Vision Science > University of California, Berkeley > 195 Life Sciences Addition > Berkeley, CA 94720-3200 > Tel (510) 642-9712 > Fax (510) 643-6791 > e-mail: [hidden email] > http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> > > ------------------------------ > > End of CONFOCALMICROSCOPY Digest - 21 Aug 2019 to 22 Aug 2019 (#2019-186) > ************************************************************************* > -- Benjamin E. Smith, Ph. D. Imaging Specialist, Vision Science University of California, Berkeley 195 Life Sciences Addition Berkeley, CA 94720-3200 Tel (510) 642-9712 Fax (510) 643-6791 e-mail: [hidden email] http://vision.berkeley.edu/?page_id=5635 <http://vision.berkeley.edu/> |
Free forum by Nabble | Edit this page |