0

I am doing the erosion example from the OpenCV3 documentation but the color of the image change to purple yellow instead of black and white despite the fact that I changed while reading the image. The default image is also black and white. Though if I don't change the image to black and white it shows correctly.

img = cv2.imread('j.png', 0)        # 0 for black and white
kernel = np.ones((5,5), np.uint8)
erosion = cv2.erode(img, kernel, iterations=1)
plt.subplot(121), plt.imshow(img), plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.imshow(erosion), plt.title('Erosion')
plt.xticks([]), plt.yticks([])
plt.show()

How it should be

How it is

Coddy
  • 549
  • 4
  • 18
  • 1
    Possible duplicate of [Plot a black-and-white binary map in matplotlib](https://stackoverflow.com/questions/9638826/plot-a-black-and-white-binary-map-in-matplotlib) – Miki Nov 14 '17 at 22:05
  • Yeah it worked. – Coddy Nov 14 '17 at 22:10
  • It doesn't give any option for that? – Coddy Nov 14 '17 at 23:37
  • Can you help me with this question: https://stackoverflow.com/questions/47297146/opencv3-not-getting-the-expected-output-on-morphologically-transforming-image-i – Coddy Nov 14 '17 at 23:43

0 Answers0