I am implementing gabor kernels, when I display the kernels while running the code (before saving them) they give me a picture like this
But after saving the kernels as jpg images using cv2.imwrite, I get like that
Any explanations? and how to save the kernels as in the first image?
Advertisement
Answer
There could be different causes. So I have two suggestions:
If you display the first picture with plt.imshow(), export it with plt.savefig(). This should easily be working.
If you still want to export the image with cv2.imwrite() make sure that the picture is correctly rescaled first. (mind that if you have only one channel, you will get a grayscale picture).
If we call the original picture org_img:
img = org_img min_val,max_val=img.min(),img.max() img = 255.0*(img - min_val)/(max_val - min_val) img = img.astype(np.uint8) cv2.imwrite(img,"picture.png")