我從外部 api 獲得了以 uint32 元組形式呈現(xiàn)的圖像,其中每個 uint32 由 4 個 uint8 組成,其中包含 r、g、b 和 alpha(始終 = 0),我需要將其轉(zhuǎn)換為格式與我相同的 3d numpy 數(shù)組可以從imageio.imread. 問題是,當我使用numpy.view顏色順序時,顏色順序是相反的。這是我編寫的代碼,可以正常工作,但我想知道是否有更好的轉(zhuǎn)換方法。 frame_buffer_tuple = ... # here we have tuple of width*height length
framebuffer = np.asarray(frame_buffer_tuple).astype(dtype='uint32').view(dtype='uint8').reshape((height, width, 4)) # here I have height x width x 4 numpy array but with inverted colors (red instead of blue) and alpha I don't need
framebuffer = np.stack((framebuffer[:, :, 2], framebuffer[:, :, 1], framebuffer[:, :, 0]), axis=2) # here I've got correct numpy height x width x 3 array我更關(guān)心執(zhí)行時間,然后是內(nèi)存,但由于我可以擁有 7680 × 4320 圖像,因此兩者可能都很重要。謝謝!
添加回答
舉報
0/150
提交
取消