NumPy สำหรับรูปภาพ

การประมวลผลภาพด้วย Python

Rebeca Gonzalez

Data Engineer

NumPy สำหรับรูปภาพ

  • พื้นฐานเทคนิคการประมวลผลภาพ
    • การพลิกภาพ
    • การดึงและวิเคราะห์ฟีเจอร์

สุนัขน่ารักกำลังเดินในสวน

สุนัขน่ารักที่พลิกแนวนอน

การประมวลผลภาพด้วย Python

รูปภาพในรูป NdArray

อาคารในมาดริด

# Loading the image using Matplotlib
madrid_image = plt.imread('/madrid.jpeg')

type(madrid_image)
<class 'numpy.ndarray'>
การประมวลผลภาพด้วย Python

สีด้วย NumPy

ภาพองุ่นและภาพแสดงช่องสีทั้ง 3 ช่อง

การประมวลผลภาพด้วย Python

สีด้วย NumPy

# Obtaining the red values of the image
red = image[:, :, 0]

# Obtaining the green values of the image
green = image[:, :, 1]

# Obtaining the blue values of the image
blue = image[:, :, 2]

ช่องสีของภาพที่แสดงแยกกัน

การประมวลผลภาพด้วย Python

สีด้วย NumPy

ช่องสีของภาพผู้หญิงที่แสดงแยกกันด้วย gray colormap

plt.imshow(red, cmap="gray")    
plt.title('Red')
plt.axis('off')
plt.show()
การประมวลผลภาพด้วย Python

Shape ของภาพ

อาคารในมาดริด

# Accessing the shape of the image
madrid_image.shape
(426, 640, 3)
การประมวลผลภาพด้วย Python

ขนาดของภาพ

อาคารในมาดริด

# Accessing the shape of the image
madrid_image.size
817920
การประมวลผลภาพด้วย Python

การพลิกภาพ: แนวตั้ง

# Flip the image in up direction
vertically_flipped = np.flipud(madrid_image)

show_image(vertically_flipped, 'Vertically flipped image')

ภาพมาดริดที่พลิกแนวตั้ง

การประมวลผลภาพด้วย Python

การพลิกภาพ: แนวนอน

# Flip the image in left direction
horizontally_flipped = np.fliplr(madrid_image)

show_image(horizontally_flipped, 'Horizontally flipped image')

ภาพมาดริดที่พลิกแนวนอน

การประมวลผลภาพด้วย Python

ฮิสโตแกรมคืออะไร?

ฮิสโตแกรมของภาพมืด ฮิสโตแกรมของภาพสว่าง

การประมวลผลภาพด้วย Python

ฮิสโตแกรมสี

ฮิสโตแกรมของภาพสีผู้หญิง แสดงฮิสโตแกรมแยกตามแต่ละสี

การประมวลผลภาพด้วย Python

การประยุกต์ใช้ฮิสโตแกรม

  • การวิเคราะห์
  • การทำ Thresholding
  • ความสว่างและความคมชัด
  • การปรับสมดุลภาพ

ภาพที่ผ่านการทำ Thresholding

การประมวลผลภาพด้วย Python

ฮิสโตแกรมใน Matplotlib

ฮิสโตแกรมของสีแดง

# Red color of the image
red = image[:, :, 0]

# Obtain the red histogram plt.hist(red.ravel(), bins=256)
การประมวลผลภาพด้วย Python

การแสดงฮิสโตแกรมด้วย Matplotlib

blue = image[:, :, 2]

plt.hist(blue.ravel(), bins=256)
plt.title('Blue Histogram')
plt.show()

ฮิสโตแกรมของสีน้ำเงินของภาพ

การประมวลผลภาพด้วย Python

มาฝึกกันเถอะ!

การประมวลผลภาพด้วย Python

Preparing Video For Download...