I'm trying to compute the gradient of an image for sharpness check but the following code throws an error even though it should be pretty straight forward
import os,sys
from PIL import Image
import numpy as np
B = Image.open("C:\\work\\tech\\blur\\blur.jpg")
By, Bx = np.gradient(B)
Bnorm = np.sqrt(Bx**2 + By**2)
Bsharpness = np.average(Bnorm)
print Bsharpness
Error
----> 6 By, Bx = np.gradient(B)
ValueError: too many values to unpack
The documentation for np.gradient says
For two dimensional arrays, the return will be two arrays ordered by axis.
I have checked this question and it doesn't answer mine