top- hat transform for signal processing
14 views (last 30 days)
Show older comments
Hello, I want to know how to write matlab code for top-hat and bottom-hat (morphological operation) for signal processing??
0 Comments
Answers (2)
Image Analyst
on 26 Nov 2021
I know imtophat() and imbothat() should work for 1-D signals. They're in the Image Processing Toolbox. Observe:
v = randi(20, 1, 15)
windowWidth = 3;
v2 = imtophat(v, true(1, windowWidth))
0 Comments
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
Image Analyst
on 26 Nov 2021
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.
DGM
on 26 Nov 2021
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.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!