Mercurial > hg > segmentation
comparison novelty.py @ 7:294f66d285af
some previous changes
author | mitian |
---|---|
date | Tue, 05 May 2015 08:54:09 +0100 |
parents | c11ea9e0357f |
children | a34f9c5d0cd9 |
comparison
equal
deleted
inserted
replaced
6:719b4ff8e9c9 | 7:294f66d285af |
---|---|
9 | 9 |
10 import sys, os | 10 import sys, os |
11 import numpy as np | 11 import numpy as np |
12 from scipy.signal import correlate2d, convolve2d | 12 from scipy.signal import correlate2d, convolve2d |
13 import matplotlib.pyplot as plt | 13 import matplotlib.pyplot as plt |
14 from utils.PeakPickerUtil import PeakPicker | |
14 | 15 |
15 # from utils.PeakPickerUtil import PeakPicker | 16 |
16 | 17 peak_picker = PeakPicker() |
18 peak_picker.params.alpha = 9.0 # Alpha norm | |
19 peak_picker.params.delta = 0.0 # Adaptive thresholding delta | |
20 peak_picker.params.QuadThresh_a = (100 - 20.0) / 1000.0 | |
21 peak_picker.params.QuadThresh_b = 0.0 | |
22 peak_picker.params.QuadThresh_c = (100 - 20.0) / 1500.0 | |
23 peak_picker.params.rawSensitivity = 20 | |
24 peak_picker.params.aCoeffs = [1.0000, -0.5949, 0.2348] | |
25 peak_picker.params.bCoeffs = [0.1600, 0.3200, 0.1600] | |
26 peak_picker.params.preWin = 5 | |
27 peak_picker.params.postWin = 5 + 1 | |
28 peak_picker.params.LP_on = True | |
29 peak_picker.params.Medfilt_on = True | |
30 peak_picker.params.Polyfit_on = True | |
31 peak_picker.params.isMedianPositive = False | |
32 | |
17 def getNoveltyCurve(ssm, kernel_size, normalise=False): | 33 def getNoveltyCurve(ssm, kernel_size, normalise=False): |
18 '''Return novelty score from ssm.''' | 34 '''Return novelty score from ssm.''' |
19 | 35 |
20 kernel_size = int(np.floor(kernel_size/2.0) + 1) | 36 kernel_size = int(np.floor(kernel_size/2.0) + 1) |
21 stripe = getDiagonalSlice(ssm, kernel_size) | 37 stripe = getDiagonalSlice(ssm, kernel_size) |
59 else: | 75 else: |
60 kernel[i-1,j-1] = gauss | 76 kernel[i-1,j-1] = gauss |
61 | 77 |
62 return kernel | 78 return kernel |
63 | 79 |
64 def process(ssm, kernel_size, peak_picker, normalise=False, plot=False): | 80 def segmentation(ssm, peak_picker=peak_picker, kernel_size=48, normalise=False, plot=False): |
65 '''Detect segment boundaries in the ssm.''' | 81 '''Detect segment boundaries in the ssm.''' |
82 # peak_picker for the 1st round boudary detection | |
83 | |
84 | |
66 novelty = getNoveltyCurve(ssm, kernel_size, normalise=False) | 85 novelty = getNoveltyCurve(ssm, kernel_size, normalise=False) |
67 smoothed_novelty, novelty_peaks = peak_picker.process(novelty) | 86 smoothed_novelty, novelty_peaks = peak_picker.process(novelty) |
68 | 87 |
69 if plot: | 88 if plot: |
70 plot_detection(smoothed_novelty, novelty_peaks) | 89 plot_detection(smoothed_novelty, novelty_peaks) |