Convert mat to numpy array , numpy gradient

987 ワード

1.mat to array:
arr = np.asarray(mat)
2.matlab and numpy gradient:
第2列は第1列を減らして、第3列は第1列を減らして2を除いて、第4列は第2列を減らして、......、最後の列は前の列を減らします.(行同理)
import cv2
import numpy as np
...#image read
img = cv2.imread(imgpath)
img_arr = np.asarray(img)   #mat to array
grad = np.gradient(img_arr) #gradient,parameter:edge_order---Gradient is calculated using Nth order accurate difference the boundaries. 
                            #Default: 1. New in version 1.9.1.
print(grad)
#grad[0]---row (Y axis); grad[1]---col(X axis)
print(np.gradient(img_arr),2) #edge_order = 2
reference:
convert:
http://stackoverflow.com/questions/7116751/how-to-convert-cvmat-to-numpy-array
(more)http://stackoverflow.com/questions/3337301/numpy-matrix-to-array
gradient:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.gradient.html