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

วิธีลบเส้นกริดจากภาพใน Python Matplotlib


เพื่อลบเส้นกริดจากภาพ สามารถทำตามขั้นตอนดังนี้

  • ตั้งค่าขนาดรูปและ padding ระหว่าง subplots
  • โหลดภาพจากไฟล์
  • แปลงสีภาพจาก color space หนึ่งไปอีกอัน
  • ลบเส้นกริดด้วย ax.grid(False)
  • แสดงข้อมูลเป็นภาพ 2D raster ด้วย imshow()
  • แสดงรูปด้วย show()

ตัวอย่าง

from matplotlib import pyplot as plt
import cv2

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

img = cv2.imread('bird.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.grid(False)
plt.imshow(img)
plt.show()

ผลลัพธ์

วิธีลบเส้นกริดจากภาพใน Python Matplotlib