Opening .tif image inside an ImageJ1 Macro node

Hello KNIP community,

I recently tried to open a .tif image inside an ImageJ1 Macro, and found that I could not. To be clear, what I mean by this is that I generated a dummy image for the input of the ImageJ1 Macro, and then in the ImageJ1 Macro I put the filepath that I wanted to open, and tried to open it. I tried with the standard open function, and I also tried with the Bio-Formats import function. I used the recorder when opening the file in Fiji/ImageJ, to double check the commands, and I see no reason it shouldn’t work.

I tried with a small test file that I can open easily in Fiji/ImageJ, and I can also load this file into KNIME using the Image Reader nodes. In case the file actually was being opened but I just couldn’t see it, I tried saving the file with a different name from inside the macro. I did not see any output from this attempt.

I can open a text file from inside an ImageJ1 macro, telling me it can do file I/O operations. Am I missing something to be able to open a .tif file inside an ImageJ1 macro?

Thanks!

  • Jeff

Hi @JeffB,

The process is a little complicated (that’s my understatement of the day…): The images in the input table (ImgLib2-based) have to be registered with ImageJ1(!!) through the imagej-legacy project for execution and made the active window so that the macro is executed on the correct image. Unfortunately, there is a lot that can go wrong in the whole process.

That surprises me, to be honest! The last open image should be available at the top port of the ImageJ Macro node… Have you have done this test with an image opened inside of the ImageJ macro?

Best,
Stefan

PS: Is there another reason why you want to load an image inside the ImageJ macro, besides that you can’t open your images (as described in Image Reader nodes limited to 4GB for .tif files?)?

Hi Stefan,

Thanks for your reply. I was surprised by this as well. I have full access to the interactive Dialog functionality within the ImageJ1 Macro node, and I can open text files and access, manipulate, and write them easily, so I figured opening images would not be a problem. I had to put in some effort to figure out how to pass variables into an ImageJ1 Macro node, which I can do for a single variable by making it the title of the dummy image I’m reading in and then reading the image title inside the macro. To output variables generated inside the ImageJ1 Macro I have to write them to the results table and make sure I update the table, otherwise they are not accessible to downstream nodes. Maybe I have to do something similar for images? In your first response section you mention it is a matter of the active window when the macro executes, that gives me ideas about the problem, is there a place you can direct me to where people are working on this and I might be able to lend a hand?

As for why I want to load images inside the ImageJ1 macro node, yes, the proximal reason was to see if it could handle larger files than the KNIME nodes. Agreed, not terribly logical, but testing is cheap so it’s worthwhile to see if it can do it. Turns out I cannot get it to open a .tif file at all, which seems strange to me, so I thought I would report it. I think Fiji/ImageJ provides an intuitive interface for exploring biological microscopy data, one that most biologists who do imaging are familiar with. I think being able to access aspects of Fiji/ImageJ inside of KNIME could increase adoption and usage of KNIME by biologists. Also, I am proficient in Fiji/ImageJ, but new to KNIME, so I’m looking for ways to efficiently translate and make progress.

  • Jeff
1 Like

Hi Jeff,

I’ve used the image macro node at some point also to open images and for me it did work for 2D as well as for 3D images. If your tif is an RGB image it will not open (in that case you would need to separate into channels before I guess). As Stefan pointed out already there is a lot that can go wrong with the ImageJ macro node. I’ve prepared a small workflow that you could try on your images. Let me know if it works for you.

Best,
Christian

open image macro.knar.knwf (20.7 KB)

3 Likes

Thanks for sharing that workflow, Christian!

The important thing that Christian’s workflow highlights is, that you can programmatically generate the entire ImageJ macro code in KNIME. That’s what he is doing in the Java Snippet node, where filenames are derived from flow variables.

I am curious: What kind of information are you looking to use?

We completely agree:

Best,
Stefan

I have opened https://github.com/knime-ip/knip-imagej2/issues/36 to track progress on making this easier.

Hi Christian and Stefan,

Thank you for your replies, sorry for my delay.

First let me apologize, I have found that I can open images inside the ImageJ Macro node. I really thought I tested small files, but it appears not because I now have no problem opening a 60 MB two color channel movie.

Thank you Christian for sharing the workflow; I confirm that it does work to open images with the ImageJ Macro node fed by a Java Snippet node. I have added to this workflow an alternative path where the filepath is input into the ImageJ Macro node as the title of a dummy image, and then the file is opened inside the ImageJ Macro node. I also included an example of outputting the filepath from inside the node using the results table, in case it is helpful. I do find that both pathways fail to open a 2.5 GB file, so it appears there is a reduced file size when opening inside the macro node. Most of the files I work with are at least 2.5 GB multi-channel movies or Z-stacks, so this may be why I concluded it couldn’t open any, but I swear I tested a single image plane as a tiny sample. Anyway, both pathways do successfully open a 60 MB two color channel movie, but I have not tested any other sizes to see exactly where it fails.

Thanks Stefan for sharing the paper. I’m embarrassed that I am only coming across it now; I could have done a journal club instead of preparing a lab meeting earlier this month. Thanks for opening an issue tracker for this, there is a flow variable port in the ImageJ1 Macro node labeled ‘flow_variable_controlable_code’ that I think was intended to be able to pass variables into the node (I can’t find the post now), but I have never been able to figure out how to access it in the code of the node.

As for what other information I would be looking to output from the ImageJ Macro node, I could see any number of possibilities, including measurements calculated in the node or metadata from text files that are read in and parsed in the node. I’ll give you that this is likely not the most efficient way to do things, but I come from an experimental biology background, and I taught myself programming by writing ImageJ and Matlab scripts, so for me it is more efficient to work in the ImageJ Macro language than in Java. I’m enjoying figuring out how to get KNIME to do things, and the ability to use a language that I am comfortable in while learning these new things is great for productivity and adoption of the new software.

Thanks for the beautiful work you all are doing, it is great to have these powerful tools to just use and build with!

1 Like