簡體   English   中英

使用 PIL 庫從 YCbCr 到 RGB 的色彩空間轉換?

[英]Color space conversion from YCbCr to RGB using PIL library?

如何使用 python PIL 庫執行以下操作

  • 從 rgb 轉換為 YCrCb,反之亦然
  • 從 numpy 數組創建圖像
  • 將 y, cr , cb 組件合並回 ycrcb 圖像

from PIL import Image rgb_img=Image.open("image_path")

rgb_image 應該是 PIL 圖像

yuv_img = rgb_img.convert('YCbCr') # to convert from YCrCb/yuv to rgb 
y, cb, cr = yuv_img.split() # to get individual components 

從 YCrCb 轉換為 rgb

if yuv_img.mode != 'RGB':
    rgb_img = yuv_img.convert('RGB')

從數組制作圖像

    Image.fromarray(arr)

將 y, cr , cb 組件合並回 ycbcr 圖像

y, cr , cb 應該是圖像

merged_ycbcr=Image.merge('YCbCr', (y, cb, cr))  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM