Hello guys,
Anyone knows a plugin or macro for alternating sequential filter (ASF) in imagej.?
Best regards.
Hello guys,
Anyone knows a plugin or macro for alternating sequential filter (ASF) in imagej.?
Best regards.
I don’t know of any existing plugin, but according to this page on Matlab Central, it should be easy to implement using a sequence of morphological open and close operations with increasing window size, e.g. with this plugin:
I took a shot at it and wrote a small Groovy script using ImageJ Ops to achieve this:
// @Img img
// @OpService ops
// @int iterations
// @OUTPUT Img result
import net.imglib2.algorithm.morphology.StructuringElements
i = 0
assert(img.numDimensions() == 2)
while (i < iterations) {
i++
img = ops.run("morphology.open", img, StructuringElements.disk(i, 2))
i++
img = ops.run("morphology.close", img, StructuringElements.disk(i, 2))
}
result = img
You can run this from the script editor (after selecting Groovy as a language), it will work on the currently active image and requires it to be 2-dimensional. Let us know if this is what you need.
Thank you very much. I think that solution is good. I will let you know if I need more clarification,
Hello,
thank you for the script, it will useful to me, too. But, as far as I remember, you should increase the size of the structuring element after the sequence of opening|closing, not between (or before, if you start from 0).
I was roughly following this comment on the cited Matlab Central page:
You might have to increase the windowSize again in between the imclose
and imopen - I’m not sure.
Feel free to adjust the script as you see fit. I didn’t find an “official” definition of ASF.
Hi there,That is the problem. I also search for a proper clear definition on Alternating sequential filter (ASF). But I couldn’t find one. If any one can link some document on this topic it might be helpful to lot of people.
Best regards…!
Here’s one:
https://books.google.ca/books?id=DVpqN_5BYEAC&lpg=PA59&dq=asf%20morphology&hl=fr&pg=PA56#v=onepage&q=asf%20morphology&f=false
The “official” definition guarantees some conditions, like idempotence and order, but most importantly, if the size is increased between opening and closing, I think that some useful details can be lost.
Thanks @Nicolas for the reference.
Given that they mention four types of alternating filters (AF):
AF_{B}(X)=((X \circ B) \bullet B)
AF_{B}(X)=((X \bullet B) \circ B)
AF_{B}(X)=(((X \circ B) \bullet B) \circ B)
AF_{B}(X)=(((X \bullet B) \circ B) \bullet B)
I adjusted my script to account for these cases by offering a parameter choice:
// @Img img
// @OpService ops
// @String(label="Alternating filter type", choices={"OC", "CO", "OCO", "COC"}) type
// @int(label="Number of iterations") iterations
// @OUTPUT Img result
import net.imglib2.algorithm.morphology.StructuringElements
assert(img.numDimensions() == 2)
for (i in 1..iterations) {
se = StructuringElements.disk(i, 2, 0)
switch (type) {
case "OCO":
img = ops.run("morphology.open", img, se)
case "CO":
img = ops.run("morphology.close", img, se)
img = ops.run("morphology.open", img, se)
break
case "COC":
img = ops.run("morphology.close", img, se)
case "OC":
img = ops.run("morphology.open", img, se)
img = ops.run("morphology.close", img, se)
default:
break
}
}
result = img