Batch thresholding macro

Hey guys,

I am new here and have no experience with programming. I just want to create a macro to set threshold values and create masks in the specified channels in my images. I figured it would run something like this:

  1. Open my images
  2. Split channels
  3. set threshold in channel 1 (100, 255)
  4. set threshold in channel 2 (100, 255)

I am not sure how complicated it is to split the channels and then select the correct channels via a macro. Also my microscope images are LIF. files, so I suppose I should convert them to TIF. directories first.

Please let me know if there something like this around already that I can play around with.
Thanks!

Dear @dmott92,

your approach sounds reasonable. You can check the Scripting with Fiji presentation to learn about the macro recorder and the basics of how to write a macro. There is also more information on the topic on the ImageJ wiki.

Please note that the Split channels command will create images with titles like C1-InputImage, C2-InputImage, … for an image called InputImage. You can use selectWindow(title) to make an image with a specific title the active one.

Best,
Stefan

2 Likes

Hi @dmott92,

I implemented your approach as an example workflow using KNIME Image Processing for KNIME. It uses “nodes” to perform image processing tasks.
The first two nodes are for reading the images. Then the images are split using the splitter node, after that different levels of thresholding can be applied.

Splitter_Thresholder_Example.knwf (1.1 MB)
Download the Workflow and KNIME with the Image Processing Extension to run it.

Feel free to ask more questions!

Best,
Jonas

3 Likes

Thanks Jonas,

I think that I figured out how to work it for the most part, just unsure what to do after I run the workflow. I can see some of the images in the “image viewer,” but I’m not sure how to save them or open them with Image J. It also doesn’t seem to be compatible with Lif files so I will have to convert them all to Tif files first.

Thanks again,
Dan

Hi Dan,

use the “Image Writer” node to save the resulting images, you can add it from the node repository.
You can do all of your image analysis tasks in KNIME as well, take a look at the examples on the homepage or ask more questions either here or on the KNIME Image Processing Forum.

Best,
Jonas

Hi @dmott92

I just tried to open a .lif file with KNIME Image Processing and it worked for me.

I used the mouse kidney example image from this source: https://loci.wisc.edu/software/sample-data

Hey Tibuch,

When I try and use my Lif. file I get the following error message:

ERROR Image Reader (Table) 0:52:0:4 Execute failed: Encountered duplicate row ID “C:\Users\danmo\knime-workspace\Splitter_Thresholder_example\data\17.9.11.lif” at row number 5

Not sure why it isn’t working, but I can get it to work for TIF files.

Dan

Somehow you got a duplicated Row-ID. One row represents one data-instance and has to have a unique ID.

You could try to use “List Files”-Node followed by “Image Reader (Table)” or replace the “Image Reader” with another instance.

Hi Dan,

I updated the workflow and added the image writer node. It worked using the example image provided by tibuch.
If you want you can share your image so I can try with your data.

Splitter_Thresholder_Example_v2.knwf (1.1 MB)

Jonas

Thanks again for all of the help. I think the problem may be that my LIF file is actually a collection of imaged that I got off the microscope. I can’t upload the LIF file to this post since its not supported, otherwise I would give it up to you. Is there another way that I can send it to you?

I don’t have an issue with a similar LIF files, i.e. multiple positions in one file: rows get a suffix (_1, _2, …) to make them unique.

Did you acquire the images recently?

Yeah I got them a few weeks ago.

Did you try with the updated workflow? You can zip the LIF file and upload it here.

Yes I did updated it, but I still can’t get it to work. My file was still too large, but I uploaded a smaller similar one.
17.8.2.zip (21.9 MB)

Just tried with your file and it worked without any problems. Do you still get the same error message in the second workflow?

Yeah… are there any settings that I need to change?

I just tried it on the file that I uploaded and it worked. There must be a problem with my other file. Thanks!

The file I sent you worked because it only included images in a single plane. My other files contain Z-stacks. That seems to be the issue.

The file tibuch posted also contains Z-stacks, so that should not be a problem.Can you upload the file to a dropbox or something like that?