i want to apply different colors to my grayscale image which i want to change in pseducolor but the problem is that, when i create color map generally then when i apply it to the color_coded_img which is created in begin with zeros it show me an error which is ; ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part. i don't know how to resolve it,
`import cv2 import numpy as np from google.colab.patches import cv2_imshow gray_img = cv2.imread('/content/drive/MyDrive/DIP3E_CH06_Original_Images/DIP3E_Original_Images_CH06/Fig0620(a)(picker_phantom).tif') cv2_imshow(gray_img)
def slicing_gray_img_coloring(img,slic_nums): interval_size = img // slic_nums
colors = [(0,0,i*interval_size) for i in range(slic_nums)]
color_coded_img = np.zeros((img.shape[0],img.shape[1],3), dtype=np.uint8) for i in range(slic_nums): lower_bound= i* interval_size
upper_bound = (i + 1) * interval_size if (i + 1) * interval_size <= 255 else 255
upper_bound = np.clip((i + 1) * interval_size, 0, 255)
mask =cv2.inRange(img,lower_bound,upper_bound)
color_coded_img[np.where(mask > 0)] = colors[i]
return color_coded_img
num_intervals = 8 colored_coded_img= slicing_gray_img_coloring(gray_img,num_intervals) cv2_imshow(colored_coded_img) ` i tried this and i want to change my grayscale image to pseduocolor image by color coding