MATLAB Answers

Can i use imerode() function to perform top-hat transform?

2 views (last 30 days)
Gn Gnk
Gn Gnk on 18 Nov 2020
Edited: Subhadeep Koley on 18 Nov 2020
Hello ,
is it possible to perform top-hat transform without using imtophat() . I was suggested to use only the function imerode().
Can someone explain if is this correct and advice me which arguments should i put into strel() function as well?

  0 Comments

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 18 Nov 2020
Edited: Subhadeep Koley on 18 Nov 2020
You can achieve the same result as returned imtophat function only using imerode and imdilate.
% Load the image
original = imread('rice.png');
% Define the morphological structuring element (you can change it according to your application)
se = strel('disk', 12);
% Perform top-hat filtering without using imtophat(__)
openedImg = imdilate(imerode(original, se), se);
tophatFiltered1 = original - openedImg;
Now, calculate the same using imtophat
% Load the image
original = imread('rice.png');
% Define the morphological structuring element (you can change it according to your application)
se = strel('disk', 12);
% Perform top-hat filtering using imtophat(__)
tophatFiltered2 = imtophat(original, se);
Check if both approaches are giving the same results
isequal(tophatFiltered1, tophatFiltered2)
ans =
logical
1

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!