Getting black images while applying discrete cosine transform (DCT) on image
def perform_dct(image_path):
# Load the image in grayscale
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if img is None:
raise ValueError(f"Image at {image_path} could not be loaded.")
# Resize the image to 224x224 (size expected by ViT model)
img = cv2.resize(img, (224, 224))
# Perform DCT
dct_img = cv2.dct(np.float32(img))
# Normalize the DCT image to the range [0, 1]
dct_img_min = np.min(dct_img)
dct_img_max = np.max(dct_img)
dct_img_normalized = (dct_img - dct_img_min) / (dct_img_max - dct_img_min)
# Convert to 3-channel RGB image
dct_img_normalized = (dct_img_normalized * 255).astype(np.uint8)
dct_img_rgb = cv2.merge([dct_img_normalized, dct_img_normalized, dct_img_normalized])
plt.imshow(dct_img_rgb)
plt.title("DCT of Imagesss")
plt.show()
return dct_img_rgb
Trying to get discrete cosine transform (DCT) image but getting whole black image , I am not able to find error in my code . If you can Please help me