Morphological Open Options

I’m trying to perform a morphological open on a binary image, using a pixel count of 15. In Process->Binary–>Options… the count is constrained to 1-8. I’m wondering if that constraint can be adjusted. I’ve tried unpacking ij-1.52n.jar and inserting an updated Binary.class file that does not check for the constraint, but I can’t avoid corrupting the file. Any advice on how to overcome this constraint? It feels pretty limiting and arbitrary.

Hi @faraguna,

Welcome to the forum.

Implementing morphological operations in a very general way is kind of a pain - here’s the part of the code where you’ll see why it’s limited in this way.

ImageJ Ops has a more general set of tools for morphology.
This script shows how to do it:

You can also “install” that script into your Fiji by copying it into a subfolder of the plugins/Scripts folder.

Post back if you have any questions,

Edit: change recommended script location, re @imagejan 's comment below

1 Like

Note that the recommended location for scripts to appear as menu commands is subfolders of (in particular for scripts that use ImageJ2 functionality), to help separate Java plugins from scripts in the project structure. Nevertheless, the legacy location plugins/Scripts works as well to keep everything backwards-compatible.


Oh, and on another note :slight_smile: :

the recommended syntax for script parameters is the language-agnostic #@ (hash-at) syntax:

#@ OpService ops

It has several advantages over the legacy comment-based syntax, e.g. parameters don’t need to be at the start of your script, you can have comments or a license header before them; and they’re more in line with the script directives #@output, #@script and #@import (some of them not fully implemented yet).

Just trying to bring across the best practices, as I think it’ll have a big impact if influential persons like @bogovicj use those in their examples :wink:

Thanks again @bogovicj for your illustrative examples, much appreciated!

1 Like

Thanks @imagejan,

You’ve mentioned this before, but it will sink in this time, promise!

Will edit the gist shortly :slight_smile:

1 Like

Great guys this is very helpful! I’m gonna implement this now.