示例#1
0
def dft(drawable: Line, scale=False):
    result = trunc(DiscreteFourierTransform("dft of " + drawable.title,
                                            drawable),
                   values=int(drawable.getN() / 2))
    if scale:
        result.x = scale_array(result.x, right=0.5)
    return result
示例#2
0
 def read_from_wav(self, filepath):
     rate, data = wavfile.read(INPUT_FOLDER + filepath)
     self.last_rate = rate
     x = np.zeros(len(data))
     for i in range(1, len(data)):
         x[i] = x[i - 1] + 1 / rate
     return rate, Line(filepath, x=x, y=data)
示例#3
0
def lesson4():
    xcr = io.read_from_xcr('h400x300.xcr')
    sample_line = Line("line", y=xcr.matrix[100])
    bs_line = bsf_line(sample_line, lowcut=100, highcut=150)
    bs_pic = bsf_pic(xcr, lowcut=100, highcut=150)
    return np.array([(xcr, auto(sample_line)),
                     (xcr, dft(auto(sample_line), scale=True)),
                     (bs_pic, auto(bs_line)),
                     (bs_pic, dft(auto(bs_line), scale=True))])
示例#4
0
def cdf(picture, normalise=True):
    hist = np.array(histogram(picture).y)
    for i in range(1, hist.size):
        hist[i] += hist[i - 1]
    if normalise:
        cdf_m = np.ma.masked_equal(hist, 0)
        cdf_m = (cdf_m - cdf_m.min()) * 255 / (cdf_m.max() - cdf_m.min())
        hist = np.ma.filled(cdf_m, 0).astype('uint8')
        # m = hist.max()
        # for i in range(1, hist.size):
        #     hist[i] = int(hist[i] / m * 255)
    return Line('CDF of ' + picture.title, y=hist)
示例#5
0
 def base(self):
     multiplier = 2 * math.pi * self.f * self.dt
     y = create_array(
         self.getN(), lambda i: math.sin(multiplier * i) * math.exp(
             -self.k * self.dt * i))
     return Line("", x=self.x, y=y)
示例#6
0
def mult_const(drawable, const):
    return Line(drawable.title, y=drawable.y * const)
示例#7
0
 def read_from_csv(self, filepath):
     df = pd.read_csv(INPUT_FOLDER + filepath)
     data = df['Open']
     return Line(filepath, N=len(data), y=data)
示例#8
0
 def read_from_dat(self, filepath):
     with open(INPUT_FOLDER + filepath, 'rb') as input_file:
         array_from_file = input_file.read()
     format = '{:d}f'.format(len(array_from_file) // 4)
     array_from_file = np.array(struct.unpack(format, array_from_file))
     return Line(title=filepath, N=len(array_from_file), y=array_from_file)
示例#9
0
def trunc(drawable, values):
    return Line(drawable.title, N=values, y=drawable.y[:values])
示例#10
0
def delta(interval=200, n=N):
    y = create_array(
        n,
        lambda i: 1 if i % interval == 0 else 0,
    )
    return Line("", y=y)
示例#11
0
def deconv(d1: Line, d2: Line):
    return Line("Deconv of " + d1.title + " and " + d2.title,
                y=_deconv(d1.y, d2.y))
示例#12
0
def lowpass(n=128, dt=0.001, fCut=50):
    return Line("Low Pass Filter", y=low_pass_filter(n, dt, fCut))
示例#13
0
def fft(drawable):
    return absolute(
        trunc(Line("Spectrum", y=np.fft.fft(drawable.y)),
              values=int(drawable.getN() / 2)))
示例#14
0
 def delta(self):
     y = create_array(
         self.getN(),
         lambda i: 1 if i % self.interval == 0 else 0,
     )
     return Line("", x=self.x, y=y)
示例#15
0
def diff(line: Line):
    return Line("diff of " + line.title, y=np.diff(line.y.astype("int32")))
示例#16
0
def absolute(drawable):
    return Line(drawable.title, y=np.abs(drawable.y))
示例#17
0
def sub(drawable, start, end=None):
    end = drawable.getN() if end is None else end
    return Line(drawable.title, N=end - start, y=drawable.y[start:end])
示例#18
0
def bsf_line(line: Line, lowcut, highcut):
    y = _bsf(line.y, lowcut, highcut, fs=len(line.y))
    return Line(title="bsf of " + line.title, y=y)
示例#19
0
def bandpass(n=128, dt=0.001, fCutLower=50, fCutUpper=100):
    return Line("Band Pass Filter",
                y=band_pass_filter(n, dt, fCutLower, fCutUpper))
示例#20
0
def bandstop(n=128, dt=0.001, fCutLower=50, fCutUpper=100):
    return Line("Band Stop Filter",
                y=band_stop_filter(n, dt, fCutLower, fCutUpper))
示例#21
0
def highpass(n=128, dt=0.001, fCut=50):
    return Line("High Pass Filter", y=high_pass_filter(n, dt, fCut))
示例#22
0
def histogram(picture: Picture):
    hist = np.zeros(256)
    for pixel in np.nditer(picture.matrix, op_flags=['readwrite']):
        hist[pixel] += 1
    return Line('histogram of ' + picture.title, y=hist)
示例#23
0
 def build_y(wiener, value):
     y = wiener.calculateY()[offset:]
     y = y - y[0] + value
     print(self.get_description(Line("", y=y)))
     return y
示例#24
0
def reg_deconv(d1: Line, d2: Line, k):
    return Line("Deconv of " + d1.title + " and " + d2.title,
                y=_regularized_deconv(d1.y, d2.y, k))
示例#25
0
def halflowpass(n=128, dt=0.001, fCut=50):
    return Line("Half Low Pass Filter", y=half_low_pass_filter(n, dt, fCut))
示例#26
0
 def get_line(self, index):
     return Line("Pic line" + str(index), y=self.matrix[index])
示例#27
0
 def readFromFile(self, filename):
     x, y = np.loadtxt(INPUT_FOLDER + filename, delimiter=DELIMITER, unpack=True)
     return Line(filename[3:-len(DATA_FORMAT)], x=x, y=y)
示例#28
0
def hpf_line(line: Line, cut):
    y = _hpf(line.y, cut, fs=len(line.y))
    return Line(title="lpf of " + line.title, y=y)
示例#29
0
def base(f=10, k=15, dt=0.005, n=N):
    multiplier = 2 * math.pi * f * dt
    y = create_array(
        n, lambda i: math.sin(multiplier * i) * math.exp(-k * dt * i))
    return Line("", y=y)