I'm trying to convert a grayscale yuv frame (from a video) to an image.
So I extracted the y component, which is a 2D matrix and saved it, but the result was not the image. I guess there should be some kind of transformation in order to get the right image?
Here's my code to extract frames from the video:
def yuv_get_frames_list(grayscale=False, frames_number=50):
width = 1920 # [pixels] - Frame Width
height = 1080 # [pixels] - Frame Height
start_frame = 250
end_frame = start_frame + frames_number
bits_per_color = 8
chroma_sampling = "420"
input_file_name = "externals/Bosphorus_1920x1080_120fps_420_8bit_YUV.yuv"
frames_lst = []
for frame_idx in range(start_frame, end_frame):
frame = yuv_read_frame(input_file_name, width, height, frame_idx, bits_per_color, chroma_sampling, grayscale)
frames_lst.append(frame)
return frames_lst
So then, I take a frame (the first one), extract frame.y
, transpose and save it with Pillow, but here's the result (it should be an image of a wolf):
Note that y.shape is (1920,1080), where cb,cr are of shape y.shape // 2
with values of 128 (for grayscale).
Also note that when I write the frames to y4m, the video is presented correctly.
Thanks for your help :)