Basic operations on images
Let's perform a few basic operations, such as splitting and combining the channels of a color image and adding a border to an image. We will continue this demonstration in interactive mode. Let's import OpenCV and read a color image, as follows:
>>> import cv2 >>> img = cv2.imread('/home/pi/book/dataset/4.1.01.tiff', 1)
For any image, the origin—the (0, 0) pixel—is the pixel at the upper-left corner. We can retrieve the intensity values for all the channels by running the following statement:
>>> print(img[10, 10]) [34 38 44]
These are the intensity values of the blue, green, and red channels, respectively, for pixel (10, 10
). If you only want to access an individual channel for a pixel, then run the following statement:
>>> print(img[10, 10, 0]) 34
The preceding output, 34
, is the intensity of the blue channel. Similarly, we can access the green and red channels with...