Created
April 1, 2015 21:50
-
-
Save dkohlsdorf/a14e89218479980be189 to your computer and use it in GitHub Desktop.
Extract Local Interest Points from a spectrogram
This file contains 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
package processing.signals; | |
import java.util.ArrayList; | |
/** | |
* Extract all local features from current spectrogram | |
* | |
* @author Daniel Kohlsdorf | |
*/ | |
public class LocalFeatureExtractor { | |
public ArrayList<LocalFeature> keypoints(ArrayList<double[]> spec, int offset, int r, double th) { | |
ArrayList<LocalFeature> points = new ArrayList<LocalFeature>(); | |
int T = spec.size(); | |
for (int t = r; t < T - r; t+= 2) { | |
for (int f = Math.max(r, 0); f < spec.get(t).length - r; f++) { | |
double sumNeighborhoodT = 0; | |
double sumNeighborhoodF = 0; | |
double maxT = 0; | |
for (int d = t - r; d < t + r; d++) { | |
sumNeighborhoodT += spec.get(t)[f]; | |
if(spec.get(d)[f] > maxT) { | |
maxT = spec.get(d)[f]; | |
} | |
} | |
double maxF = 0; | |
for (int d = f - r; d < f + r; d++) { | |
sumNeighborhoodF += spec.get(t)[d]; | |
if(spec.get(t)[d] > maxT) { | |
maxF = spec.get(t)[d]; | |
} | |
} | |
double noise = (1.0 / (2 * r)) * Math.min(sumNeighborhoodT, sumNeighborhoodF); | |
if (spec.get(t)[f] > Math.max(maxT, maxF) || spec.get(t)[f] > noise + th) { | |
points.add(new LocalFeature(t + offset, f)); | |
} | |
} | |
} | |
return points; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment