In [1]:
# Necessary imports
import matplotlib.pyplot as plt
import cv2

%matplotlib inline
 
# Loading our image, and flipping the color channel.
image = cv2.imread('car.jpg', cv2.COLOR_BGR2RGB)

cv2.imshow("Original", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
In [2]:
# Another way to visualize the image
# The color channel was reverse from BGR into RGB
# Since OpenCV reads this color channels in reverse order
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title('Original')
Out[2]:
Text(0.5, 1.0, 'Original')
In [3]:
# Getting the pixel value on (0,0), and storing the color channels
# in a tuple
(b, g, r) = image[0, 0]
print("Pixel at (0, 0) - Red: {}, Green: {}, Blue: {}".format(r,g, b))
Pixel at (0, 0) - Red: 255, Green: 255, Blue: 255
In [4]:
# Manipulate one pixel on the image, by updating the values
# into a new set of values
image[0, 0] = (0, 0, 255)
In [5]:
# Displaying the original image
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title('Updated')
Out[5]:
Text(0.5, 1.0, 'Updated')
In [6]:
# Using indexing we modified some part of the image
# by rewriting the color channels
image[0:100, 0:100] = (0, 255, 0)

plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title('Updated')
Out[6]:
Text(0.5, 1.0, 'Updated')