How can I make empty grayscale image in OpenCV?
Question:
I want to know how to make a empty grayscale image in OpenCV.
First, I know how to make a empty ‘color image’ like this.
import cv2
import numpy as np
blank_image = np.zeros((height,width,3), dtype = np.uint8)
Then, how can I make a empty ‘grayscale’ image with specific height and width?
Answers:
import cv2
import numpy as np
gray_level = 127
gray_image = gray_level * np.ones((height,width,3), dtype = np.uint8)
If you don’t need 3 channels, make that np.ones((height, width), dtype=np.uint8)
import numpy as np
gray_image = np.full((height, width), gray_value, dtype=np.uint8)
I want to know how to make a empty grayscale image in OpenCV.
First, I know how to make a empty ‘color image’ like this.
import cv2
import numpy as np
blank_image = np.zeros((height,width,3), dtype = np.uint8)
Then, how can I make a empty ‘grayscale’ image with specific height and width?
import cv2
import numpy as np
gray_level = 127
gray_image = gray_level * np.ones((height,width,3), dtype = np.uint8)
If you don’t need 3 channels, make that np.ones((height, width), dtype=np.uint8)
import numpy as np
gray_image = np.full((height, width), gray_value, dtype=np.uint8)