top- hat transform for signal processing

Hello, I want to know how to write matlab code for top-hat and bottom-hat (morphological operation) for signal processing??

Answers (2)

I know imtophat() and imbothat() should work for 1-D signals. They're in the Image Processing Toolbox. Observe:
v = randi(20, 1, 15)
v = 1×15
14 18 16 5 9 7 5 20 18 17 14 2 1 19 1
windowWidth = 3;
v2 = imtophat(v, true(1, windowWidth))
v2 = 1×15
0 4 2 0 4 2 0 3 1 0 0 0 0 18 0
DGM
DGM on 26 Nov 2021
Edited: DGM on 26 Nov 2021
The tophat and bottomhat operations are the difference of the source image and the opening/closing of said image with the selected strel. They represent the changes made -- i.e. the objects removed by opening or the holes filled by closing.
If you're trying to write your own, then:
For binary data, they should be equivalent to
outpict = inpict & ~imopen(inpict,se); % tophat
outpict = ~inpict & imclose(inpict,se); % bothat
For numeric data, they are
outpict = inpict - imopen(inpict,se); % tophat
outpict = imclose(inpict,se) - inpict; % bothat
The same should apply for 1D cases. Ultimately, opening and closing operations can be further reduced to a set of routines based on a simple moving-window maximum filter.

2 Comments

Of course if they have imopen() then they have the Image Processing Toolbox and can call imtophat() directly. I think you might have meant to use movmin() and movmax() which do not require the Image Processing Toolbox.
movmax could be used in the 1D case, but I intentionally was trying to speak generally. To that end, it's worth noting that movmax() is something that I still consider relatively new (though I guess it's in OP's version).
Yes, it's reasonable to assume the availability of included tools once IPT is being used, but I had to consider two things. I don't know if this is just another "how do I reinvent the wheel for my homework problem" question. Additionally, I didn't want to pseudocode something using generic function names like "open()" or "close()" knowing that someone would actually copy and paste them and run them blind.

Sign in to comment.

Products

Release

R2018b

Asked:

on 26 Nov 2021

Commented:

DGM
on 26 Nov 2021

Community Treasure Hunt

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

Start Hunting!