简体   繁体   中英

Display the Pixels of Bayer Format Image

I have just started using OpenCv-Python. I want to see the pixel values of an image which is in Bayer format. Using OpenCv-Python, I have written the following code to display the pixel values :

import numpy as np
import cv2
image = cv2.imread("bayer_small.png")
image_data = np.array(image)
print(image_data[50][50])

#Output is printed as " [ 0 0 102]

My expectation is single pixel value : 102

Why is this happening? Since the image is only in Bayer format, I am expecting one component only per pixel.

I understand that output is showing zero for other two components. But I am expecting the data in the bayer format only, for example : BGBGBGBG for first line.

My goal is to implement an algorithm. Hence trying to do step by step.

Edit 1: Is there any in-built function where I can convert a normal image to Bayer format?

While your picure probably contains the data from the Bayer matrix, it obiously still uses the RGB format for containing it. You can probably assume that two channels contain 0 for each pixel; thus you should apply a vectorized sum to the whole picture along the third axis with:

data = np.sum(image_data, axis=2)

in order to normalize it.

By the way, you can access data in a Numpy array with the more concise syntax: data[50, 50] instead of data[50][50] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM