Python - 使用 Matplotlib 處理 PNG 影像
Matplotlib 是 Python 中一個用於 2D 陣列繪圖的出色視覺化庫。Matplotlib 是建立在 NumPy 陣列的基礎上,為配合更廣泛的 SciPy 堆疊而設計的一個多平臺資料視覺化庫。
示例
#applying pseudocolor
# importing pyplot and image from matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as img
# reading png image
im = img.imread('imR.png')
# applying pseudocolor
# default value of colormap is used.
lum = im[:, :, 0]
# show image
plt.imshow(lum)
#colorbar
# importing pyplot and image from matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as img
# reading png image
im = img.imread('imR.png')
lum = im[:, :, 0]
# setting colormap as hot
plt.imshow(lum, cmap ='hot')
plt.colorbar()
#interpolation
# importing PIL and matplotlib
from PIL import Image
import matplotlib.pyplot as plt
# reading png image file
img = Image.open('imR.png')
# resizing the image
img.thumbnail((50, 50), Image.ANTIALIAS)
imgplot = plt.imshow(img)
#bicubic value for interpolation
# importing pyplot from matplotlib
import matplotlib.pyplot as plt
# importing image from PIL
from PIL import Image
# reading image
img = Image.open('imR.png')
img.thumbnail((30, 30), Image.ANTIALIAS)
# bicubic used for interpolation
imgplot = plt.imshow(img, interpolation ='bicubic')#sinc value for interpolation
# sinc value for interpolation
# importing PIL and matplotlib
from PIL import Image
import matplotlib.pyplot as plt
# reading image
img = Image.open('imR.png')
img.thumbnail((30, 30), Image.ANTIALIAS)
# sinc used for interpolation
imgplot = plt.imshow(img, interpolation ='sinc')
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP