import numpy as np
import cv2
from scipy.fftpack import dct, idct
def compute_cepstrum(image):
# Compute the 2D DCT (Discrete Cosine Transform)
dct_image = dct(dct(image.T, norm='ortho').T, norm='ortho')
# Compute the log magnitude
log_magnitude = np.log(np.abs(dct_image) + 1e-8)
# Compute the inverse DCT to get the cepstrum
cepstrum = idct(idct(log_magnitude.T, norm='ortho').T, norm='ortho')
return cepstrum
def compute_delta_cepstrum(cepstrum, delta=1):
rows, cols = cepstrum.shape
delta_cepstrum = np.zeros((rows, cols))
for i in range(rows):
for j in range(cols):
if i - delta >= 0:
delta_cepstrum[i, j] = cepstrum[i, j] - cepstrum[i - delta, j]
if j - delta >= 0:
delta_cepstrum[i, j] = cepstrum[i, j] - cepstrum[i, j - delta]
return delta_cepstrum
def compute_shifted_delta_cepstrum(cepstrum, window_size=3, delta=1):
rows, cols = cepstrum.shape
shifted_delta_cepstrum = np.zeros((rows, cols, window_size * 2 + 1))
for shift in range(-window_size, window_size + 1):
shifted_delta_cepstrum[:, :, shift + window_size] = compute_delta_cepstrum(cepstrum, delta + shift)
return shifted_delta_cepstrum
# Load and preprocess the image
image_path = '/content/drive/My Drive/RMC2/Full Clean Run/sample.jpg' # Replace with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
image = image.astype(np.float32) / 255.0
# Compute cepstrum
cepstrum = compute_cepstrum(image)
# Compute shifted delta cepstrum
shifted_delta_cepstrum = compute_shifted_delta_cepstrum(cepstrum)
# Save or process the shifted delta cepstrum as needed
print("Shifted Delta Cepstrum calculation completed.")
i m getting below error:
IndexError Traceback (most recent call last)
in <cell line: 45>()
43
44 # Compute shifted delta cepstrum
—> 45 shifted_delta_cepstrum = compute_shifted_delta_cepstrum(cepstrum)
46
47 # Save or process the shifted delta cepstrum as needed
1 frames
in compute_delta_cepstrum(cepstrum, delta)
21 delta_cepstrum[i, j] = cepstrum[i, j] – cepstrum[i – delta, j]
22 if j – delta >= 0:
—> 23 delta_cepstrum[i, j] = cepstrum[i, j] – cepstrum[i, j – delta]
24
25 return delta_cepstrum
IndexError: index 1740 is out of bounds for axis 1 with size 1740