Hi, I'm Ramu. Suddenly, I belong to an image processing laboratory. In my laboratory, I have to teach my juniors about image processing methods in seminars from next month.
To be honest, I feel that I can't implement or explain basic image processing due to lack of study recently. So I decided to try imori_imori's 100 knocks on image processing.
Here, I will implement image processing one by one and explain it lightly. Please note that python has just started recently, so please understand the coding ability.
The first image processing to commemorate is channel switching. A color image has three color components, red, blue, and green, that is, three channel components. When reading using openCV, the order is blue, green, and red, but this time, this is replaced in the order of red, green, and blue.
reverseChannel.py
import cv2
import matplotlib.pyplot as plt
def reverseChannel(img):
#Image copy
dst = img.copy()
#Channel replacement
dst[:, :, 0] = img[:, :, 2]
dst[:, :, 2] = img[:, :, 0]
return dst
#Image reading
img = cv2.imread('image.jpg')
#Channel replacement
img = reverseChannel(img)
#Save image
cv2.imwrite("result.jpg ", img)
#Image display
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.show()
The image on the left is the input image, and the image on the right is the output image. The red color of the sashimi has changed to blue due to the replacement of the red and blue components.
I would like to output like this. If you have any questions, please feel free to contact us. By the way, the official answer is posted on Github, the official website for 100 image processing knocks, so please check that as well.
Recommended Posts