Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

imshow จัดการ Alpha Channel กับ Input M x N x 4 อย่างไร? (Matplotlib)

มาดูตัวอย่างเพื่อดูว่า imshow() จัดการ alpha channel กับ input M×N×4 อย่างไร

ขั้นตอน

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • คืนอาร์เรย์ใหม่ที่มีรูปร่างและประเภทที่กำหนด เติมด้วย 1
  • จัดการ alpha channel
  • แสดงข้อมูลเป็นภาพ คือ บน raster 2D ปกติ
  • เพื่อแสดงรูป ใช้เมธอด show()

ตัวอย่าง

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

d = np.ones((100, 100, 4), dtype=np.uint8) * 255
d[:, :, 1] = np.linspace(0, 255, num=100)
plt.imshow(d)
plt.show()

ผลลัพธ์

imshow จัดการ Alpha Channel กับ Input M x N x 4 อย่างไร? (Matplotlib)imshow จัดการ Alpha Channel กับ Input M x N x 4 อย่างไร? (Matplotlib)