Finding Maximum Difference Between Element and All Neighboring Elements in An Arary
Ältere Kommentare anzeigen
Hello, I have an array and I am trying to find the maximum difference between an element and all of its neighboring elements for each element. For example if I have... array = [1 2 3; 4 10 5; 6 7 8 ]; I want to find the maximum difference between each element and any neighboring element to get an output with the maximum difference
output = [3 8 7; 6 9 5; 4 3 3]; Any help would be greatly appreciated!
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 24 Aug. 2017
If you have the Image Processing Toolbox, the best way is to simply call rangefilt():
outputImage = rangefilt(inputImage, ones(3))
Alternatively, you can just subtract the erosion (local min) from the dilation (local max):
outputImage = imdilate(inputImage, ones(3)) - imerode(inputImage, ones(3));
which should do the same thing as rangefilt().
Walter Roberson
am 24 Aug. 2017
1 Stimme
Morphological closing can be used to take the maximum of each block in a sliding block manner. Do that and subtract the original value to get the difference between the value and the local maximum. Now do morphological open which is equivalent to local minimum and subtract that from the original to get the difference in the other direction. Now take the maximum of the two to determine the greatest difference.
1 Kommentar
Image Analyst
am 25 Aug. 2017
Some definitions:
A morphological dilation (not closing) is the local max.
A morphological erosion (not opening) is a local min.
A morphological closing is a dilation followed by an erosion, which enlarges and smooths out bright areas.
A morphological opening is an erosion followed by an dilation, which enlarges dark areas.
A closing minus the original is a top hat filter, which finds bright things on a varying background.
An opening minus the original is a bottom hat filter, which finds dark things on a varying background.
There are functions for all of those in the Image Processing Toolbox: imerode(), imdilate(), imclose(), imopen(), imtophat(), imbothat().
Kategorien
Mehr zu Deep Learning Processor Customization and IP Generation finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!