- Practical Computer Vision
- Abhinav Dadhich
- 203字
- 2021-06-30 18:54:42
Reading an image
An image, stored in digital format, consists of grid structure with each cell containing a value to represent image. In further sections, we will see different formats for images. For each format, the values represented in the grid cells will have different range of values.
To manipulate an image or use it for further processing, we need to load the image and use it as grid like structure. This is referred to as image input-output operations and we can use OpenCV library to read an image, as follows. Here, change the path to the image file according to use:
import cv2
# loads and read an image from path to file
img = cv2.imread('../figures/flower.png')
# displays previous image
cv2.imshow("Image",img)
# keeps the window open until a key is pressed
cv2.waitKey(0)
# clears all window buffers
cv2.destroyAllWindows()
The resulting image is shown in the following screenshot:

Here, we read the image in BGR color format where B is blue, G is green, and R is red. Each pixel in the output is collectively represented using the values of each of the colors. An example of the pixel location and its color values is shown in the previous figure bottom.