簡體   English   中英

使用 TensorFlow 將 RGBA PNG 轉換為 RGB

[英]Convert RGBA PNG to RGB with TensorFlow

我使用模塊tensorflow.imageTensorFlow v2.0.0打開圖像,使用代碼:

import tensorflow as tf
img = tf.image.decode_png(tf.io.read_file("image.png"))

但是這個圖像是RGB-A 我怎樣才能將其轉換為RGB

(最好只使用TensorFlow

function

tf.io.decode_png(
contents, channels=0, dtype=tf.dtypes.uint8, name=None
)

允許您選擇要用於正在導入的圖像的顏色類型 model。

attr channels指示解碼圖像所需的顏色通道數。

可接受的值為:

0:使用 PNG 編碼圖像中的通道數。

1:output一張灰度圖。

3:output RGB 圖像。

4:output RGBA 圖像。

如果要將RGB-A圖像導入為RGB圖像,只需使用代碼:

import tensorflow as tf
img = tf.image.decode_png(tf.io.read_file("image.png"), channels=3)

暫無
暫無

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

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