我正在嘗試將影像劃分為補丁并將其可視化,但 matplotlib 一直顯示完全不正確的輸出。
from PIL import Image
import os
def imgcrop(input, xPieces, yPieces):
filename, file_extension = os.path.splitext(input)
im = Image.open(input)
imgwidth, imgheight = im.size
height = imgheight // yPieces
width = imgwidth // xPieces
for i in range(0, yPieces):
for j in range(0, xPieces):
box = (j * width, i * height, (j 1) * width, (i 1) * height)
a = im.crop(box)
np_img = np.asarray(a)
plt.imshow(np_img)
我使用的方法如下:
imgcrop("cats.jpeg", 14, 14)
我有一個16 x 16補丁,但顏色與影像完全不同
代碼信用:#
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/421109.html
標籤:
上一篇:C#物件屬性參考
