A quick example of using LoadImageM to load an image file directly into cvmat :
import cv path = 'stack.png' mat = cv.LoadImageM(path, cv.CV_LOAD_IMAGE_UNCHANGED) x, y = 42, 6 print type(mat) print mat[y, x]
Output:
<type 'cv.cvmat'> (21.0, 122.0, 254.0)
A quick example showing how several or more color channels are 0.5 :
for x in xrange(mat.cols): for y in xrange(mat.rows): # multiply all 3 components by 0.5 mat[y, x] = tuple(c*0.5 for c in mat[y, x]) # or multiply only the red component by 0.5 b, g, r = mat[y, x] mat[y, x] = (b, g, r * 0.5)
source share