Kindly be informed that the OpenCV package in Python will change its behavior according to the type of array you are using in your code:
Thus, if the image is in the format of 8-bit unsigned, then it will get presented as-is.
But, if the picture is in the structure of a 16-bit unsigned or 32-bit integer, then the number of cells of the picture will get divided by 256 that denotes the value range [0,255*256] is composed to [0,255].
And if the picture is in the form of a 32-bit floating-point, then the pixel of the image will get multiplied by 255. That means the value range [0,1] is drafted to [0,255].
Therefore, the below code will all yield the same grayscale image:
s = np.zeros((240, 320), dtype=np.uint8)
s[s==0] = 128
int32:
s = np.zeros((240, 320), dtype=np.int32)
s[s==0] = 128 * 256
float32:
s = np.zeros((240, 320), dtype=np.float32)
s[s==0] = 128 / 256.0
If you are a beginner and want to know more about Python, then do check out the below Python tutorial video that will help you in understanding the topic in a better way: