process_gray_image.py
Go to the documentation of this file.
1 import cv2
2 import matplotlib.cm as cm
3 import numpy as np
4 
5 
6 def spectral_subtract(img, noise):
7  spectrogram_subtracted = img.transpose() - noise
8  # Spectral subtraction method
9  spectrogram_subtracted = np.where(spectrogram_subtracted > 0,
10  spectrogram_subtracted,
11  noise * 0.01)
12  spectrogram_subtracted = spectrogram_subtracted.transpose()
13  return spectrogram_subtracted
14 
15 
16 def smooth_gray_image(raw_img):
17  """
18  Blur to gray image
19  input: cv2 32FC1 image
20  output: cv2 32FC1 image
21  """
22  return cv2.blur(raw_img, (5, 5))
23 
24 
26  """
27  Convert input gray image to 8FC1 gray image.
28  At this time, each pixel is normalized between 0 ~ 255.
29  input: cv2 image
30  output: cv2 image
31  """
32  dtype = img.dtype
33  _max = img.max()
34  _min = img.min()
35  ret = (img - _min).astype(np.float64) / (_max - _min) * 255.0
36  return ret.astype(dtype)
37 
38 
39 def img_jet(img):
40  """
41  Convert input to jet image if input is mono image.
42  input : cv2 8UC1 image
43  output: cv2 8UC3 image
44  """
45  if len(img.shape) == 2:
46  normalized_img = img / 255.0
47  jet = np.array(cm.jet(1 - normalized_img)[:, :, :3] * 255, np.uint8)
48  else:
49  jet = img
50  return jet
sound_classification.process_gray_image.smooth_gray_image
def smooth_gray_image(raw_img)
Definition: process_gray_image.py:16
sound_classification.process_gray_image.normalize_gray_image
def normalize_gray_image(img)
Definition: process_gray_image.py:25
sound_classification.process_gray_image.img_jet
def img_jet(img)
Definition: process_gray_image.py:39
sound_classification.process_gray_image.spectral_subtract
def spectral_subtract(img, noise)
Definition: process_gray_image.py:6


sound_classification
Author(s):
autogenerated on Fri May 16 2025 03:12:55