示例#1
0
 def test_findpeaks_callable(self):
     """ Check we can call the Octave findpeaks from Python using oct2py. """
     # Load signal packageself.
     octave.eval("pkg load signal")
     (pks, loc) = octave.findpeaks(np.array([0, 2, 4, 9, 5, 3, 6, 11, 5, 1, 6]))
     self.assertEquals(pks[0].tolist(), [11, 9])
     self.assertEquals(loc[0].tolist(), [8, 4])
示例#2
0
 def test_octave_findpeaks_equal_matlab_findpeaks_minpeakheight_2(self):
     """ Check that Octave findpeaks mimics well the original MatLab findpeaks, with minpeakheight filter. """
     # Find peaks on this vector.
     vector = [
         0.000000000000001, 3.651411362475055, 4.347239816515587,
         3.229238311887470, 2.057044119108341, 4.289416174922050,
         4.623656294357088, 16.991500296151141, 23.710596923344340,
         5.194447742667983, 5.392090702263596
     ]
     (pks, loc) = octave.findpeaks(
         np.array(vector),
         'MinPeakHeight', 22, 'MinPeakDistance', 0, 'MinPeakWidth', 0)
     if np.isscalar(pks):
         pks = np.array(pks, ndmin=1)
         loc = np.array(loc, ndmin=1)
     self.assertEqual(
         self.round(pks).tolist(),
         self.round([23.710596923344340]).tolist())
     self.assertEqual(
         loc[0],
         [9])
示例#3
0
 def test_octave_findpeaks_equal_matlab_findpeaks_minpeakheight_1(self):
     """ Check that Octave findpeaks mimics well the original MatLab findpeaks, with minpeakheight filter. """
     # Find peaks on this vector.
     vector = [
         0.000000000000002, 8.065338269152255, 0.345981261752651,
         3.773585143328164, 8.902504869392125, 10.153129735333088,
         9.310914486231075, 52.420530313341835, 21.453422488606648,
         11.328972030373752, 1.811055956166194
     ]
     (pks, loc) = octave.findpeaks(
         np.array(vector),
         'MinPeakHeight', 22, 'MinPeakDistance', 0, 'MinPeakWidth', 0)
     if np.isscalar(pks):
         pks = np.array(pks, ndmin=1)
         loc = np.array(loc, ndmin=1)
     self.assertEqual(
         self.round(pks).tolist(),
         self.round([52.420530313341835]).tolist())
     self.assertEqual(
         loc[0],
         [8])
示例#4
0
 def test_octave_findpeaks_equal_matlab_findpeaks_minpeakheight_3(self):
     """ Check that Octave findpeaks mimics well the original MatLab findpeaks, with minpeakheight filter. """
     # Find peaks on this vector.
     vector = [
         0.000000000000002, 4.304968393969253, 2.524429995956715,
         1.362350996472030, 8.651011827706597, 5.355103964053995,
         4.166135802128525, 7.111434648523146, 41.368426443580518,
         13.753049599045664, 11.652130301046128
     ]
     (pks, loc) = octave.findpeaks(
         np.array(vector),
         'MinPeakHeight', 22, 'MinPeakDistance', 0, 'MinPeakWidth', 0)
     if np.isscalar(pks):
         pks = np.array(pks, ndmin=1)
         loc = np.array(loc, ndmin=1)
     self.assertEqual(
         self.round(pks).tolist(),
         self.round([41.368426443580518]).tolist())
     self.assertEqual(
         loc[0],
         [9])
示例#5
0
 def test_octave_findpeaks_equal_matlab_findpeaks_minpeakheight_minpeakdistance(self):
     """ Check that Octave findpeaks mimics well the original MatLab findpeaks, with minpeakheight and minpeakdistance filter. """
     # Find peaks on this vector.
     vector = [
         0.199196234460946, 0.150971091401259, 0.066830193587158, -0.007815333052105, -0.044616654524390, -0.055795361348227, -0.076137152400651, -0.118170367279712, -0.163440493736020, -0.190516609994619, -0.176483713717207, -0.126265512667095,
         -0.085683530051180, -0.070626701579825, -0.056650272247038, -0.018164912522573, 0.042641790158567, 0.084300842806316, 0.091380642181674, 0.086612641403415, 0.076804338682254, 0.065114059315175, 0.061730123648466, 0.062054559470569,
         0.037808369894233, -0.007903466706924, -0.022105492056923, 0.022875099403569, 0.100256509561853, 0.161610966145234, 0.188078783724511, 0.179791428716887, 0.127483188979423, 0.037101235419981, -0.061551863605861, -0.134872789642774,
         -0.170882136762535, -0.180232519836007, -0.193873842670550, -0.220596208762850, -0.217710728542538, -0.154566709841264, -0.052288376793704, 0.024309953763214, 0.036995233638215, 0.027385387267975, 0.034756425571608, 0.044538621477845,
         0.048179094187324, 0.062762787751685, 0.093756722731978, 0.128746079656537, 0.140220257694886, 0.107177963642096, 0.064168137422344, 0.049034449543362, 0.043561872239351, 0.037112836659310, 0.049484512152412, 0.075511915362878,
         0.082621740035262, 0.059833540054286, 0.025160333364946, -0.011362411779154, -0.059885473889260, -0.116916348401991, -0.160033412094328, -0.186277401172449, -0.227970985597943, -0.293012110994312, -0.316846014874940, -0.235793951154457,
         -0.071213154358508, 0.087635348114046, 0.166528547043995, 0.156622093806762, 0.114536824444267, 0.098795472321648, 0.106794539180316, 0.123935062619566, 0.138240918685253, 0.120041711787775, 0.065711290699853, -0.020477124669418,
         -0.121124845572754, -0.163652703975820, -0.088146112206319, 0.062253992836015, 0.185115302006708, 0.251310089224804, 0.275507327595166, 0.240646546675415, 0.144130827133559, 0.028378284476590, -0.050543164088393, -0.082379193202235,
         -0.108933261445066, -0.149993661967355, -0.188079227296676, -0.184552832746794
     ]
     # Set to 0 the negative values
     # so they don't interfe in peak search,
     # as Octave findpeaks don't ignore negative values by default
     # (in fact it can search for local minima with the DoubleSided mode).
     v = np.array(vector)
     for i in range(0, len(v)):
         if v[i] < 0:
             v[i] = 0
     (pks, loc) = octave.findpeaks(
         v,
         'MinPeakHeight', 0.05, 'MinPeakDistance', 10, 'MinPeakWidth', 0)
     expectedPeaks = [
         0.091380642181674, 0.188078783724511, 0.140220257694886, 0.166528547043995, 0.275507327595166
     ]
     if not np.isscalar(pks):
         pks = pks[0]
         loc = loc[0]
     self.assertEqual(
         self.round(pks).tolist(),
         self.round(expectedPeaks).tolist())
     self.assertEqual(
         loc.tolist(),
         [19, 31, 53, 75, 91])
     
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from oct2py import octave

# Load the Octage-Forge signal package.
octave.eval("pkg load signal")

print("Detect peaks without any filters.")
(_, indexes) = octave.findpeaks(
    np.array(vector), "DoubleSided", "MinPeakHeight", 0, "MinPeakDistance", 0, "MinPeakWidth", 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print("Peaks are: %s" % (indexes))
plot_peaks(np.array(vector), indexes, algorithm="Octave-Forge findpeaks")

print("Detect peaks with minimum height and distance filters.")
(pks, indexes) = octave.findpeaks(
    np.array(vector), "DoubleSided", "MinPeakHeight", 6, "MinPeakDistance", 2, "MinPeakWidth", 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print("Peaks are: %s" % (indexes))
plot_peaks(np.array(vector), indexes, mph=6, mpd=2, algorithm="Octave-Forge findpeaks")
示例#7
0
def find_PPG_peaks(vec):
    cur = np.array(vec)
    octave.eval("pkg load signal")
    peaks, indexes = octave.findpeaks(cur, 'DoubleSided', 'MinPeakHeight', 1000, 'MinPeakDistance', 50, 'MinPeakWidth', 0)
    return indexes
示例#8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from oct2py import octave

# Load the Octage-Forge signal package.
octave.eval("pkg load signal")

print('Detect peaks without any filters.')
(_, indexes) = octave.findpeaks(
    np.array(vector),
    'DoubleSided', 'MinPeakHeight', 0, 'MinPeakDistance', 0, 'MinPeakWidth', 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    indexes,
    algorithm='Octave-Forge findpeaks'
)

print('Detect peaks with minimum height and distance filters.')
(pks, indexes) = octave.findpeaks(
    np.array(vector),
    'DoubleSided', 'MinPeakHeight', 6, 'MinPeakDistance', 2, 'MinPeakWidth', 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
示例#9
0
def handle_image():
    File_List = glob.glob('./images/1/*.png')

    fw = open("./output/output1.txt", "w")

    for n in range(0, 10):
        # load image file
        ImgPath = (File_List[n])
        Img = cv2.imread(ImgPath, cv2.IMREAD_GRAYSCALE)

        count = 0
        fw.write(ImgPath)
        fw.write(' : ')
        fw.write('\n')
        #cv2.imshow(ImgPath, Img)
        print("success: " + os.path.basename(File_List[n]))  # file load check

        # 'px' set for zero
        px = [0] * Img.shape[0]
        s_px = []

        print Img.shape

        # pixel count
        for y in range(0, Img.shape[1]):
            for x in range(0, Img.shape[0]):
                if Img[x, y] == 0:
                    px[x] += 1
        #print (px)

        cb = np.array(px)

        # 1.
        # indexes = peakutils.indexes(cb, thres = 0.02/max(cb), min_dist = 100)
        # interpolatedIndexes = peakutils.interpolate(np.arange(0, len(cb)), cb, ind=indexes)
        #
        # print interpolatedIndexes
        #
        # plt.plot(interpolatedIndexes)

        #2.
        octave.eval("pkg load signal")
        (peaks, indexes) = octave.findpeaks(cb, 'DoubleSided', 'MinPeakHeight',
                                            0.04, 'MinPeakDistance', 100,
                                            'MinpeakWidth', 0)

        #print len(px)
        #fw.write('[')

        # for i in range(len(cb)):
        #     if cb[i] != 0:
        #
        #         fw.write(str(cb[i]))
        #         fw.write(',')
        #         fw.write(' ')
        #         count+=1
        #
        # for i in range(0, 119 - count):
        #     fw.write('0')
        #     fw.write(',')
        #     fw.write(' ')
        #
        # fw.write(']')
        #
        # fw.write(str(n))
        # fw.write('\n')

        #fw.write(str(interpolatedIndexes[0]))
        fw.write('\n')

        #cv2.imshow(ImgPath + 'histo', Histo)

        print count