Reputation: 79
I am trying to find contrast in an image using greycomatrix here is the code:
import cv2
import numpy as np
from scipy import misc
from skimage.feature import greycomatrix, greycoprops
img=cv2.imread('leaf2.jpg')
g=greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4])
print (g)
contrast = greycoprops(g, 'contrast')
print(contrast)
Here is the error: "The image must be a 2-D array" How to convert the image to a 2-D array, suitable for the function?
Upvotes: 1
Views: 1405
Reputation: 1
you can directly load in grayscale by doing img=cv2.imread('leaf2.jpg',0)
Upvotes: 0
Reputation: 4542
Add img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
after you load the image to make it a one-channel, grayscale image.
Or you could load it as grayscale directly by doing img = cv2.imread('leaf2.jpg', cv2.IMREAD_GRAYSCALE)
.
Upvotes: 3