Step-by-Step Explanation
Create a Black Image
img = np.zeros((100, 100, 3), dtype=np.uint8)
np.zeros((100, 100, 3), dtype=np.uint8) creates a black image of size 100x100 pixels.
The 3 at the end means it has 3 color channels (Blue, Green, Red - BGR).
Since it's all zeros, the image is completely black.
Convert to Grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) converts the BGR image to grayscale.
Grayscale images have only 1 channel instead of 3.
Each pixel in grayscale has an intensity value (0 to 255) instead of 3 separate color values.
Print the Shape
print(gray.shape)
The original image (img) has a shape of (100, 100, 3), meaning 3 color channels.
The converted grayscale image (gray) now has a shape of (100, 100), because it has only one channel (intensity values instead of color).
Final Output
(100, 100)
This confirms that the grayscale image has only height and width dimensions, with no color channels.
0 Comments:
Post a Comment