Issues with morphological closing of a binary image?

Hello!
I am currently performing analysis of some images. I had recorded a macro on ImageJ that was able to correctly threshold the input image, as shown below:
For various reasons, I would like to transfer the whole process to Matlab, however, when I try to apply the same procedures I used on ImageJ to Matlab, the image is not correctly thresholded.
The procedure I used in ImageJ was:
run("8-bit");
run("Auto Threshold", "method=Otsu");
run("Morphological Filters", "operation=Closing element=Square radius=10");
The issues I am experiencing with Matlab, is that the Morphological Filtering, closing with a square of size 10 is not effective in filling in the white area left by the light shining on the top of the picture ( I used imclose(), with different structural elements and tried varying the size as well). Does anyone have any idea of why this is happening?
I attached the code and the image.
Thanks!

2 Comments

I'm not sure if you think there's a problem with the thresholding or the closing. But you did not include your thresholding function. Also, your image doesn't seem to come up when I click on it in Firefox. I think it's corrupted. Can you attach the original color image again with either the frame icon or the paperclip icon, or both?
Hello! I think there is a problem with the closing, not with the thresholding. I attached the files requested, thank you!

Sign in to comment.

 Accepted Answer

DGM
DGM on 9 Nov 2021
Edited: DGM on 9 Nov 2021
Did you notice that your thresholded image is inverted? By trying to close the inverted image, you're trying to remove the wrong thing.
You can invert the image and close it, though bear in mind that's the filter width, not radius.
M = ~thresholdLocally(I);
J = imclose(M,strel('square',20 ));
Or you can use something different instead of just closing with a strel. Note that this preserves the edges.
M = thresholdLocally(I);
J = ~bwareaopen(M,10E3);

1 Comment

I did notice it was inverted, and tried inverting the image at some point, but still did something else wrong along the way. Thank you so much for your answer, it's perfect!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!