> On Oct 27, 2019, at 12:40 PM, kefe <[hidden email]> wrote:
> > Dear everyone, > > I want to write a mini macro to -more or less- analyse my pictures > automatically. I recorded what I want to do with the according plugin and > now just needed to generalise the image name. I think that part worked but > somehow now the selectWindow command does not work anymore. You can avoid problems with selectWindow(title) by instead using selectImage(n), where ’n’ is the image index (one-based). The following example opens a 129 image stack, converts the stack to images and then uses selectImage(n) to activate each of the 129 images. close("*"); //close all images setBatchMode(true); run("T1 Head (2.4M, 16-bits)"); //open 129 image stack run("Stack to Images"); for (n=1; n<=nImages; n++) { selectImage(n); //select n'th image print(n, getTitle); } -wayne > (However, if I > run the command with the specific name as I recorded it, it works.) > The debug window says a ")" is missing in the selectWindow line. > > Here is my "code": > > imageTitle=File.nameWithoutExtension > > run("Stack to Images"); > > selectWindow("c:2/3 - "imageTitle" "); > > setAutoThreshold("Default"); > //run("Threshold..."); > setThreshold(150, 65535); > setThreshold(150, 65535); > setOption("BlackBackground", false); > run("Convert to Mask"); > run("Watershed"); > run("Set Measurements...", "area mean min integrated redirect=[c:1/3 - > "imageTitle" ] decimal=3"); > run("Analyze Particles...", "size=50-Infinity display exclude clear"); > > Thanks for your help! -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Wayne,
thank you very much for your suggestion that is related to a hint of Michael Schmid. Yes, this approach appears being the best if one can be sure that no other images are open, which depends on what is to be obtained in the end. Apart from this approach it remains a sad fact that the naming of slice images after calling run("Stack to Images"); is unreliable and, as far as I can judge it, this situation is not a problem of ImageJ. I still should like to hear the opinion of the BioFormats-group about their different naming strategy and about the more than strange file-name prefix. Thanks again and kind regards Herbie ::::::::::::::::::::::::::::::::::::::::::: Am 28.10.19 um 21:45 schrieb Wayne Rasband: >> On Oct 27, 2019, at 12:40 PM, kefe <[hidden email]> wrote: >> >> Dear everyone, >> >> I want to write a mini macro to -more or less- analyse my pictures >> automatically. I recorded what I want to do with the according plugin and >> now just needed to generalise the image name. I think that part worked but >> somehow now the selectWindow command does not work anymore. > > You can avoid problems with selectWindow(title) by instead using selectImage(n), where ’n’ is the image index (one-based). The following example opens a 129 image stack, converts the stack to images and then uses selectImage(n) to activate each of the 129 images. > > close("*"); //close all images > setBatchMode(true); > run("T1 Head (2.4M, 16-bits)"); //open 129 image stack > run("Stack to Images"); > for (n=1; n<=nImages; n++) { > selectImage(n); //select n'th image > print(n, getTitle); > } > > -wayne > > >> (However, if I >> run the command with the specific name as I recorded it, it works.) >> The debug window says a ")" is missing in the selectWindow line. >> >> Here is my "code": >> >> imageTitle=File.nameWithoutExtension >> >> run("Stack to Images"); >> >> selectWindow("c:2/3 - "imageTitle" "); >> >> setAutoThreshold("Default"); >> //run("Threshold..."); >> setThreshold(150, 65535); >> setThreshold(150, 65535); >> setOption("BlackBackground", false); >> run("Convert to Mask"); >> run("Watershed"); >> run("Set Measurements...", "area mean min integrated redirect=[c:1/3 - >> "imageTitle" ] decimal=3"); >> run("Analyze Particles...", "size=50-Infinity display exclude clear"); >> >> Thanks for your help! > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Herbie & everyone,
you can also have a version of the macro for selecting the images from "Stack to Images" in the presence of other open images. It only requires that there is no process creating a new image in a parallel thread. run("Blobs (25K)"); //any pre-existing images may be open setBatchMode(true); run("T1 Head (2.4M, 16-bits)"); //open 129 image stack stackSize = nSlices(); run("Stack to Images"); lastID = getImageID(); firstID = lastID + (stackSize - 1); for (n=0; n<stackSize; n++) { selectImage(firstID - n); //select n'th image print(n, getTitle); } The macro makes use of the fact that ImageIDs are negative numbers assigned in descending sequence. So, after "Stack to Images", getImageID(); gets the ID of the current foreground (active) image, which is the one created last (the most negative one). The image created immediately before that has an ID that is higher by one, etc. By the way, I would not say that the image naming of "Stack to Images" is unreliable. To me it is perfectly logical to use the slice labels (if existing) as titles. E.g. if I use "Images to Stack" to combine images to a stack (with the default setting "Use Titles as Labels"), then do some operation on the stack (so I don't need to do it on each image one by one), and split the images with "Stack to Images", the images retain their original titles. Michael ________________________________________________________________ On 29.10.19 09:11, Herbie wrote: > Dear Wayne, > > thank you very much for your suggestion that is related to a hint of > Michael Schmid. Yes, this approach appears being the best if one can be > sure that no other images are open, which depends on what is to be > obtained in the end. > > Apart from this approach it remains a sad fact that the naming of slice > images after calling run("Stack to Images"); is unreliable and, as far > as I can judge it, this situation is not a problem of ImageJ. > > I still should like to hear the opinion of the BioFormats-group about > their different naming strategy and about the more than strange > file-name prefix. > > Thanks again and kind regards > > Herbie > > ::::::::::::::::::::::::::::::::::::::::::: > Am 28.10.19 um 21:45 schrieb Wayne Rasband: >>> On Oct 27, 2019, at 12:40 PM, kefe <[hidden email]> wrote: >>> >>> Dear everyone, >>> >>> I want to write a mini macro to -more or less- analyse my pictures >>> automatically. I recorded what I want to do with the according plugin >>> and >>> now just needed to generalise the image name. I think that part >>> worked but >>> somehow now the selectWindow command does not work anymore. >> >> You can avoid problems with selectWindow(title) by instead using >> selectImage(n), where ’n’ is the image index (one-based). The >> following example opens a 129 image stack, converts the stack to >> images and then uses selectImage(n) to activate each of the 129 images. >> >> close("*"); //close all images >> setBatchMode(true); >> run("T1 Head (2.4M, 16-bits)"); //open 129 image stack >> run("Stack to Images"); >> for (n=1; n<=nImages; n++) { >> selectImage(n); //select n'th image >> print(n, getTitle); >> } >> >> -wayne >> >> >>> (However, if I >>> run the command with the specific name as I recorded it, it works.) >>> The debug window says a ")" is missing in the selectWindow line. >>> >>> Here is my "code": >>> >>> imageTitle=File.nameWithoutExtension >>> >>> run("Stack to Images"); >>> >>> selectWindow("c:2/3 - "imageTitle" "); >>> >>> setAutoThreshold("Default"); >>> //run("Threshold..."); >>> setThreshold(150, 65535); >>> setThreshold(150, 65535); >>> setOption("BlackBackground", false); >>> run("Convert to Mask"); >>> run("Watershed"); >>> run("Set Measurements...", "area mean min integrated redirect=[c:1/3 - >>> "imageTitle" ] decimal=3"); >>> run("Analyze Particles...", "size=50-Infinity display exclude clear"); >>> >>> Thanks for your help! >> >> -- >> 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 |
Thanks Michael,
of course there are solutions but they are clumsy... > By the way, I would not say that the image naming > of "Stack to Images" is unreliable. My test stack (two channels or slices) has no labels and produces different channel or slice names after applying "Stack to Images" depending on whether the stack is opened by "Plain ImageJ" or by "Bio Formats Importer". Consequently and if you are not aware of the way a stack was opened (as it is often the case when using Fiji), the naming *appears* unreliable. Because I don't use "Bio Formats Importer" on a regular basis, I wasn't aware of the fact that it introduces labels and therefore changes the slice names. Again, the problem *is* that opening a stack with the two standard methods leads to different slice namings after applying "Stack to Images". Frankly, this is *not* to be expected. The problem is not in the first place that labels are always used for slice names, except that they should not contain slashes and colons... Perhaps I could make things a bit clearer. Kind regards Herbie :::::::::::::::::::::::::::::::::::::::::::: Am 29.10.19 um 10:45 schrieb Michael Schmid: > Hi Herbie & everyone, > > you can also have a version of the macro for selecting the images from > "Stack to Images" in the presence of other open images. > It only requires that there is no process creating a new image in a > parallel thread. > > run("Blobs (25K)"); //any pre-existing images may be open > setBatchMode(true); > run("T1 Head (2.4M, 16-bits)"); //open 129 image stack > stackSize = nSlices(); > run("Stack to Images"); > lastID = getImageID(); > firstID = lastID + (stackSize - 1); > for (n=0; n<stackSize; n++) { > selectImage(firstID - n); //select n'th image > print(n, getTitle); > } > > The macro makes use of the fact that ImageIDs are negative numbers > assigned in descending sequence. So, after "Stack to Images", > getImageID(); gets the ID of the current foreground (active) image, > which is the one created last (the most negative one). The image created > immediately before that has an ID that is higher by one, etc. > > By the way, I would not say that the image naming of "Stack to Images" > is unreliable. To me it is perfectly logical to use the slice labels (if > existing) as titles. > E.g. if I use "Images to Stack" to combine images to a stack (with the > default setting "Use Titles as Labels"), then do some operation on the > stack (so I don't need to do it on each image one by one), and split the > images with "Stack to Images", the images retain their original titles. > > > Michael > ________________________________________________________________ > On 29.10.19 09:11, Herbie wrote: >> Dear Wayne, >> >> thank you very much for your suggestion that is related to a hint of >> Michael Schmid. Yes, this approach appears being the best if one can >> be sure that no other images are open, which depends on what is to be >> obtained in the end. >> >> Apart from this approach it remains a sad fact that the naming of >> slice images after calling run("Stack to Images"); is unreliable and, >> as far as I can judge it, this situation is not a problem of ImageJ. >> >> I still should like to hear the opinion of the BioFormats-group about >> their different naming strategy and about the more than strange >> file-name prefix. >> >> Thanks again and kind regards >> >> Herbie >> >> ::::::::::::::::::::::::::::::::::::::::::: >> Am 28.10.19 um 21:45 schrieb Wayne Rasband: >>>> On Oct 27, 2019, at 12:40 PM, kefe <[hidden email]> wrote: >>>> >>>> Dear everyone, >>>> >>>> I want to write a mini macro to -more or less- analyse my pictures >>>> automatically. I recorded what I want to do with the according >>>> plugin and >>>> now just needed to generalise the image name. I think that part >>>> worked but >>>> somehow now the selectWindow command does not work anymore. >>> >>> You can avoid problems with selectWindow(title) by instead using >>> selectImage(n), where ’n’ is the image index (one-based). The >>> following example opens a 129 image stack, converts the stack to >>> images and then uses selectImage(n) to activate each of the 129 images. >>> >>> close("*"); //close all images >>> setBatchMode(true); >>> run("T1 Head (2.4M, 16-bits)"); //open 129 image stack >>> run("Stack to Images"); >>> for (n=1; n<=nImages; n++) { >>> selectImage(n); //select n'th image >>> print(n, getTitle); >>> } >>> >>> -wayne >>> >>> >>>> (However, if I >>>> run the command with the specific name as I recorded it, it works.) >>>> The debug window says a ")" is missing in the selectWindow line. >>>> >>>> Here is my "code": >>>> >>>> imageTitle=File.nameWithoutExtension >>>> >>>> run("Stack to Images"); >>>> >>>> selectWindow("c:2/3 - "imageTitle" "); >>>> >>>> setAutoThreshold("Default"); >>>> //run("Threshold..."); >>>> setThreshold(150, 65535); >>>> setThreshold(150, 65535); >>>> setOption("BlackBackground", false); >>>> run("Convert to Mask"); >>>> run("Watershed"); >>>> run("Set Measurements...", "area mean min integrated redirect=[c:1/3 - >>>> "imageTitle" ] decimal=3"); >>>> run("Analyze Particles...", "size=50-Infinity display exclude clear"); >>>> >>>> Thanks for your help! >>> >>> -- >>> 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 |
The recent flap over a Python scripting bug that invalidated hundreds of published results illustrates the general principle that you should NEVER assume that functions you call will always work the same way (unless it is written in stone in the specifications). Much less two *different* functions, both of which have specifications that are silent on the issue.
If you *need* labels to be in a specific form - then you must assign them yourself. This is not "clumsy" - it is sound programming practice. If the specs are silent on the format of slice labels, you cannot assume *anything* about what they will look like. Running your script once and observing the result is *not* sufficient. Building a script to deal with *one* method of import, and then expecting all others to conform is unreasonable. -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by kefe
> On Oct 27, 2019, at 12:40 PM, kefe <[hidden email]> wrote:
> > Dear everyone, > > I want to write a mini macro to -more or less- analyse my pictures > automatically. I recorded what I want to do with the according plugin and > now just needed to generalise the image name. I think that part worked but > somehow now the selectWindow command does not work anymore. Upgrade to the latest ImageJ daily build (1.52s1) and the selectWindow() macro function, when used after run("Stack to Images”), should work more reliably. The "Stack to Images” command no longer uses the slice label as the file name if the slice label contains “/“ or “ “. In any case, it is better to use selectImage(n), where ’n’ is the n'th opened image. This example opens a 129 image stack, converts the stack to images and then uses selectImage(n) to activate each of the 129 images. close("*"); //close all images setBatchMode(true); run("T1 Head (2.4M, 16-bits)"); //open 129 image stack run("Stack to Images"); for (n=1; n<=nImages; n++) { selectImage(n); //select n'th image print(n, getTitle); } -wayne > (However, if I > run the command with the specific name as I recorded it, it works.) > The debug window says a ")" is missing in the selectWindow line. > > Here is my "code": > > imageTitle=File.nameWithoutExtension > > run("Stack to Images"); > > selectWindow("c:2/3 - "imageTitle" "); > > setAutoThreshold("Default"); > //run("Threshold..."); > setThreshold(150, 65535); > setThreshold(150, 65535); > setOption("BlackBackground", false); > run("Convert to Mask"); > run("Watershed"); > run("Set Measurements...", "area mean min integrated redirect=[c:1/3 - > "imageTitle" ] decimal=3"); > run("Analyze Particles...", "size=50-Infinity display exclude clear"); > > Thanks for your help! > > Cheers > > > > -- > Sent from: http://imagej.1557.x6.nabble.com/ > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Kenneth Sloan-2
Kenneth,
you may be right in many respects but what I'm struggling with is that a stack without labels sometimes gets labels attributed and sometimes not. My opinion is that if I deal with a stack without labels it should stay without labels, except in cases where I attribute labels to it. ImageJ doesn't attribute labels to a stack without labels... BTW, what I called clumsy was a totally different affair. I hope this makes things even clearer. Regards Herbie ::::::::::::::::::::::::::::::::::::::::::: Am 29.10.19 um 15:54 schrieb Kenneth Sloan: > The recent flap over a Python scripting bug that invalidated hundreds of published results illustrates the general principle that you should NEVER assume that functions you call will always work the same way (unless it is written in stone in the specifications). Much less two *different* functions, both of which have specifications that are silent on the issue. > > If you *need* labels to be in a specific form - then you must assign them yourself. This is not "clumsy" - it is sound programming practice. > > If the specs are silent on the format of slice labels, you cannot assume *anything* about what they will look like. Running your script once and observing the result is *not* sufficient. Building a script to deal with *one* method of import, and then expecting all others to conform is unreasonable. > > -- > Kenneth Sloan > [hidden email] > Vision is the art of seeing what is invisible to others. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Wayne Rasband-2
Thanks Wayne,
as always a very wise decision! Kind regards Herbie ::::::::::::::::::::::::::::::::::::::::::: Am 29.10.19 um 16:29 schrieb Wayne Rasband: >> On Oct 27, 2019, at 12:40 PM, kefe <[hidden email]> wrote: >> >> Dear everyone, >> >> I want to write a mini macro to -more or less- analyse my pictures >> automatically. I recorded what I want to do with the according plugin and >> now just needed to generalise the image name. I think that part worked but >> somehow now the selectWindow command does not work anymore. > > Upgrade to the latest ImageJ daily build (1.52s1) and the selectWindow() macro function, when used after run("Stack to Images”), should work more reliably. The "Stack to Images” command no longer uses the slice label as the file name if the slice label contains “/“ or “ “. > > In any case, it is better to use selectImage(n), where ’n’ is the n'th opened image. This example opens a 129 image stack, converts the stack to images and then uses selectImage(n) to activate each of the 129 images. > > close("*"); //close all images > setBatchMode(true); > run("T1 Head (2.4M, 16-bits)"); //open 129 image stack > run("Stack to Images"); > for (n=1; n<=nImages; n++) { > selectImage(n); //select n'th image > print(n, getTitle); > } > > -wayne > > >> (However, if I >> run the command with the specific name as I recorded it, it works.) >> The debug window says a ")" is missing in the selectWindow line. >> >> Here is my "code": >> >> imageTitle=File.nameWithoutExtension >> >> run("Stack to Images"); >> >> selectWindow("c:2/3 - "imageTitle" "); >> >> setAutoThreshold("Default"); >> //run("Threshold..."); >> setThreshold(150, 65535); >> setThreshold(150, 65535); >> setOption("BlackBackground", false); >> run("Convert to Mask"); >> run("Watershed"); >> run("Set Measurements...", "area mean min integrated redirect=[c:1/3 - >> "imageTitle" ] decimal=3"); >> run("Analyze Particles...", "size=50-Infinity display exclude clear"); >> >> Thanks for your help! >> >> Cheers >> >> >> >> -- >> Sent from: http://imagej.1557.x6.nabble.com/ >> >> -- >> 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 |