problems migrating frpm macros to API

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

problems migrating frpm macros to API

Aryeh Weiss
I am once again trying to work in python, and am encountering difficulties.
I have trouble knowing how to find the methods that correspond to
commands in macros
For commands that appear in the menus, I can use the Command finder, but
I dont know what to do with
something like isOpen(imageTitle), or many other macro features that are
not part of the command menu structure.
WindowManager has a method for returning a list of nonImageWindows, but
where do I get a list of image windows?

Even when I find the method, I dont always know how to handle the
arguments. For example:
IJ.run("Image Sequence...", "open="+inputDirPath+"
file=x"+str(xLoc).zfill(3)+"_y"+str(yLoc).zfill(3)+" sort")
will open an image sequence, appropriately filtering the file names.
When I try to do it with FolderOpener(), I see how to create a filtered
file list (getFilteredList), butI dont see how to pass that filtered list to
openFolder(). So openFolder opens everything in the director (about 275
images instead of 11)

I think that I am not the only one who started with the IJ macro
language, so my main question is, how can I find the methods that
correspond to the macro commands -- particularly the ones that are not
in the menus?

Right now, I hope someone can tell me how to open that sequence with the
filtered list, and which method provides a list of open image window titles.

Thanks in advance for your help.

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: problems migrating frpm macros to API

Graeme Ball-2
Hi Aryeh,

You can use the macro recorder to record java code instead of macro
commands, and translate the java to python. e.g. with
  Plugins > Macros > Record  "Java"
selected, I get the following java code when clicking
  File > Import Image Sequence...

IJ.run("Image Sequence...", "open=/path/to/files autoscale
color_mode=Default quiet view=Hyperstack stack_order=XYCZT number=8
file=filename_pattern sort autoscale color_mode=Default quiet
view=Hyperstack stack_order=XYCZT");


which can be converted to the jython script:

from ij import IJ

IJ.run("Image Sequence...", "open=/path/to/files autoscale
color_mode=Default quiet view=Hyperstack stack_order=XYCZT number=8
file=filename_pattern sort autoscale color_mode=Default quiet
view=Hyperstack stack_order=XYCZT")


If you want a list of open files, try the IJ.WindowManager:

  http://rsb.info.nih.gov/ij/developer/api/

e.g. here is some jython code that prints window titles:


from ij import WindowManager


windowIDs = WindowManager.getIDList()

windowTitles = [WindowManager.getImage(i).getTitle() for i in windowIDs]

for t in windowTitles:

    print t




On Thu, Feb 5, 2015 at 2:28 PM, Aryeh Weiss <[hidden email]> wrote:

> I am once again trying to work in python, and am encountering difficulties.
> I have trouble knowing how to find the methods that correspond to commands
> in macros
> For commands that appear in the menus, I can use the Command finder, but I
> dont know what to do with
> something like isOpen(imageTitle), or many other macro features that are
> not part of the command menu structure.
> WindowManager has a method for returning a list of nonImageWindows, but
> where do I get a list of image windows?
>
> Even when I find the method, I dont always know how to handle the
> arguments. For example:
> IJ.run("Image Sequence...", "open="+inputDirPath+"
> file=x"+str(xLoc).zfill(3)+"_y"+str(yLoc).zfill(3)+" sort")
> will open an image sequence, appropriately filtering the file names.
> When I try to do it with FolderOpener(), I see how to create a filtered
> file list (getFilteredList), butI dont see how to pass that filtered list to
> openFolder(). So openFolder opens everything in the director (about 275
> images instead of 11)
>
> I think that I am not the only one who started with the IJ macro language,
> so my main question is, how can I find the methods that correspond to the
> macro commands -- particularly the ones that are not in the menus?
>
> Right now, I hope someone can tell me how to open that sequence with the
> filtered list, and which method provides a list of open image window titles.
>
> Thanks in advance for your help.
>
> --aryeh
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: problems migrating frpm macros to API

Aryeh Weiss
Thank you for your quick reply.

On 2/5/15 5:24 PM, Graeme Ball wrote:

> Hi Aryeh,
>
> You can use the macro recorder to record java code instead of macro
> commands, and translate the java to python. e.g. with
>   Plugins > Macros > Record  "Java"
> selected, I get the following java code when clicking
>   File > Import Image Sequence...
>
> IJ.run("Image Sequence...", "open=/path/to/files autoscale
> color_mode=Default quiet view=Hyperstack stack_order=XYCZT number=8
> file=filename_pattern sort autoscale color_mode=Default quiet
> view=Hyperstack stack_order=XYCZT");
>
>
> which can be converted to the jython script:
>
> from ij import IJ
>
> IJ.run("Image Sequence...", "open=/path/to/files autoscale
> color_mode=Default quiet view=Hyperstack stack_order=XYCZT number=8
> file=filename_pattern sort autoscale color_mode=Default quiet
> view=Hyperstack stack_order=XYCZT")
>
>

Yes -- I did this, and it works. However, in this case the image stack
opens and is displayed. I did not want that, so I thought that
I could use FolderOpener() to just get the ImagePlus object.

My strategy now is to use getFilteredList() to get the file list that I
need, and then loop through it and create an
ImagePlus array which I will then turn into a stack.



> If you want a list of open files, try the IJ.WindowManager:
>
> http://rsb.info.nih.gov/ij/developer/api/
>
> e.g. here is some jython code that prints window titles:
>
>
> from ij import WindowManager
>
>
> windowIDs = WindowManager.getIDList()
>
> windowTitles = [WindowManager.getImage(i).getTitle() for i in windowIDs]
>
> for t in windowTitles:
>
>     print t
>
>

Thank you for this. I saw the method for getting the windowID list, and
it did nto occur to me to use tha to get the names.
Since two windows might have the same title, it makes sense that the API
provides getIGList because the IDs are unique.

Again, many thanks
--aryeh

>
> On Thu, Feb 5, 2015 at 2:28 PM, Aryeh Weiss <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     I am once again trying to work in python, and am encountering
>     difficulties.
>     I have trouble knowing how to find the methods that correspond to
>     commands in macros
>     For commands that appear in the menus, I can use the Command
>     finder, but I dont know what to do with
>     something like isOpen(imageTitle), or many other macro features
>     that are not part of the command menu structure.
>     WindowManager has a method for returning a list of
>     nonImageWindows, but where do I get a list of image windows?
>
>     Even when I find the method, I dont always know how to handle the
>     arguments. For example:
>     IJ.run("Image Sequence...", "open="+inputDirPath+"
>     file=x"+str(xLoc).zfill(3)+"_y"+str(yLoc).zfill(3)+" sort")
>     will open an image sequence, appropriately filtering the file names.
>     When I try to do it with FolderOpener(), I see how to create a
>     filtered file list (getFilteredList), butI dont see how to pass
>     that filtered list to
>     openFolder(). So openFolder opens everything in the director
>     (about 275 images instead of 11)
>
>     I think that I am not the only one who started with the IJ macro
>     language, so my main question is, how can I find the methods that
>     correspond to the macro commands -- particularly the ones that are
>     not in the menus?
>
>     Right now, I hope someone can tell me how to open that sequence
>     with the filtered list, and which method provides a list of open
>     image window titles.
>
>     Thanks in advance for your help.
>
>     --aryeh
>
>     --
>     Aryeh Weiss
>     Faculty of Engineering
>     Bar Ilan University
>     Ramat Gan 52900 Israel
>
>     Ph:  972-3-5317638
>     FAX: 972-3-7384051
>
>
>     --
>     ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html