Update spec_utils.py

This commit is contained in:
aufr33 2021-04-30 08:51:20 +03:00 committed by GitHub
parent 49c9d776f4
commit f3106dffdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -277,21 +277,6 @@ def cmb_spectrogram_to_wave(spec_m, mp, extra_bins_h=None, extra_bins=None):
bands_n = len(mp.param['band']) bands_n = len(mp.param['band'])
offset = 0 offset = 0
if False:
from scipy import ndimage
intersect_h2 = 167
intersect_y2 = 67
intersect_h1 = 62
intersect_y1 = 244
intersect_left = ndimage.zoom(spec_m[0, intersect_y1:intersect_y1+intersect_h1, :].real, zoom=(intersect_h2 / intersect_h1, 1.0), order=3) * 6
intersect_right = ndimage.zoom(spec_m[1, intersect_y1:intersect_y1+intersect_h1, :].real, zoom=(intersect_h2 / intersect_h1, 1.0), order=3) * 6
s = intersect_y2+intersect_left.shape[0]
spec_m[0, intersect_y2:s, :] = np.where(np.abs(spec_m[0, intersect_y2:s, :]) <= np.abs(intersect_left) * 1.5, spec_m[0, intersect_y2:s, :], intersect_left)
spec_m[1, intersect_y2:s, :] = np.where(np.abs(spec_m[1, intersect_y2:s, :]) <= np.abs(intersect_right) * 1.5, spec_m[1, intersect_y2:s, :], intersect_right)
for d in range(1, bands_n + 1): for d in range(1, bands_n + 1):
bp = mp.param['band'][d] bp = mp.param['band'][d]
spec_s = np.ndarray(shape=(2, bp['n_fft'] // 2 + 1, spec_m.shape[2]), dtype=complex) spec_s = np.ndarray(shape=(2, bp['n_fft'] // 2 + 1, spec_m.shape[2]), dtype=complex)
@ -403,6 +388,7 @@ if __name__ == "__main__":
if args.algorithm == 'max_mag': if args.algorithm == 'max_mag':
v_spec_m = np.where(np.abs(y_spec_m) >= np.abs(X_spec_m), y_spec_m, X_spec_m) v_spec_m = np.where(np.abs(y_spec_m) >= np.abs(X_spec_m), y_spec_m, X_spec_m)
if args.algorithm == 'invert':
X_mag = np.abs(X_spec_m) X_mag = np.abs(X_spec_m)
y_mag = np.abs(y_spec_m) y_mag = np.abs(y_spec_m)
v_mag = np.abs(v_spec_m) v_mag = np.abs(v_spec_m)
@ -411,7 +397,6 @@ if __name__ == "__main__":
y_image = spectrogram_to_image(y_mag) y_image = spectrogram_to_image(y_mag)
v_image = spectrogram_to_image(v_mag) v_image = spectrogram_to_image(v_mag)
if args.algorithm == 'invert':
cv2.imwrite('{}_X.png'.format(args.output_name), X_image) cv2.imwrite('{}_X.png'.format(args.output_name), X_image)
cv2.imwrite('{}_y.png'.format(args.output_name), y_image) cv2.imwrite('{}_y.png'.format(args.output_name), y_image)
cv2.imwrite('{}_v.png'.format(args.output_name), v_image) cv2.imwrite('{}_v.png'.format(args.output_name), v_image)