1

Using python2 with opencv 3.3-dev

if i try to do a simple:

gray = imread('img.jpg',cv2.IMREAD_GRAYSCALE)

and try to show the image with

plt.imshow(img), plt.show()

(where plt is matplotlib.pyplot)

the resulting image is not at all gray, and really green and not at all the original colors, or grayscale...

heres what it looks like: enter image description here

Does anybody know whats wrong?

smyslov
  • 1,279
  • 1
  • 8
  • 29
elliot430
  • 13
  • 4
  • Use `plt.show(img, cmap="gray")`? – DavidG Nov 07 '17 at 09:02
  • as a reference can you post the original picture? – Eumel Nov 07 '17 at 09:03
  • plt might recognize the pixels as (gray value, 0, 0), if the first value represents green the picture will be different shades of green – Eumel Nov 07 '17 at 09:04
  • here it is: https://i.imgur.com/iITRlSZ.jpg using cmap="gray" seemed to have solved it, but is this just how the image is displayed? is the image actually in grayscale? – elliot430 Nov 07 '17 at 09:05
  • @elliot430 if you dont specify for plt to show a grayscale image it will pad other colors with 0s – Eumel Nov 07 '17 at 09:10
  • @DavidG well im using opencv for a project that im just starting on, never touched this before so.... you might see me around a lot asking for help in the near future haha – elliot430 Nov 07 '17 at 09:15
  • @Eumel I see, so from my understanding, this is just a problem with the actual "display" part, the image was actually already in grayscale? – elliot430 Nov 07 '17 at 09:16
  • If you didn't want to use openCV, then [this](https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python) will be helpful – DavidG Nov 07 '17 at 09:17

0 Answers0