Wednesday , October 16 2024

Extracting The Image RGB Values of a Pixel in Python Using OpenCV

3 Extracting the RGB values of a pixel

Extracting The Image RGB Values of a Pixel in Python Using OpenCV

In [2]:
import cv2
img = cv2.imread('machinelearning.png',1)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Get RGB Value of a Single Pixel

In [3]:
img[100,100]
Out[3]:
array([203, 190,  84], dtype=uint8)
In [4]:
B,G,R = img[100,100]
print(B,G,R)
203 190 84
In [5]:
print('Type of the image : ' , type(img))
print()
print('Shape of the image : {}'.format(img.shape))
print('Image Hight {}'.format(img.shape[0]))
print('Image Width {}'.format(img.shape[1]))
print('Dimension of Image {}'.format(img.ndim))
Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (725, 715, 3)
Image Hight 725
Image Width 715
Dimension of Image 3

About Machine Learning

Check Also

Record Video From a Webcam using OpenCV

12 Record Video using OpenCV Record Video From a Webcam using OpenCV¶ cv2.VideoWriter( filename, fourcc, …

Leave a Reply

Your email address will not be published. Required fields are marked *