Last active
August 29, 2015 14:04
-
-
Save tonyfast/57d5a012866842240145 to your computer and use it in GitHub Desktop.
Peak and Valley finding coarse for N-D Volumetric datasets for N>=1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% Example use of peakfind | |
| A = round( checkerboard( 10 ) ); | |
| [G] = peaks( 61 ); | |
| B = peakfind( G, 'neighborhood', [ 5 5] ); | |
| % B - Boolean matrix of peaks | |
| [x,y] = find( B ); | |
| % x,y - positions of peaks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function P = FindPeaks( T, varargin ) | |
| % Finds the peaks or valleys in the spatial correlation functions. | |
| % Find a Valley in a parabola | |
| % peakfind( linspace(-10,10, 101).^2, 'valley',true) | |
| % Find a Peak in a inverted parabola | |
| % peakfind( linspace(-10,10, 101).^2, 'valley',false) | |
| param = setparam( varargin, numel(T),size(T) ); | |
| % Design the filter | |
| F = ones( param.neighborhood); | |
| F( ceil(numel(F)./2) ) = 0; | |
| if ~param.valley | |
| P = T > imdilate( T, F ); | |
| else | |
| P = T < imerode( T, F ); | |
| end | |
| function param = setparam( varargin, N, sz ) | |
| if sz(2) == 1 & N == sz(1) | |
| r = 1; | |
| else | |
| r = numel( sz ); | |
| end | |
| param = struct( 'neighborhood', 5*ones(1,r),... | |
| 'valley', false); | |
| if numel( varargin ) > 0 | |
| for ii = 1 : 2 :numel( varargin ) | |
| param = setfield( param, varargin{ii}, varargin{ii+1}); | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment