Skip to content

Instantly share code, notes, and snippets.

@bafu
Last active March 5, 2018 14:39
Show Gist options
  • Save bafu/cf269dae0ce8999b0c52ce70d664b52a to your computer and use it in GitHub Desktop.
Save bafu/cf269dae0ce8999b0c52ce70d664b52a to your computer and use it in GitHub Desktop.
Display RGB values in image's pixels
#!/usr/bin/python3
# Display RGB values in image's pixels.
import sys
import cv2
def main():
fpath = sys.argv[1]
im = cv2.cvtColor(cv2.imread(fpath), cv2.COLOR_BGR2RGB)
h, w, c = im.shape
print('(x, y) R G B')
for i in range(h):
for j in range(w):
print('(%3d, %3d) %3d, %3d, %3d' % (j, i,
im[i][j][0],
im[i][j][1],
im[i][j][2]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment