2016-10-16 47 views
0

我有一个图像,我想提取它的修补程序,然后将每个修补程序保存为该文件夹中的图像。这是我第一次尝试:Python中的修补程序提取

from sklearn.feature_extraction import image 
from sklearn.feature_extraction.image import extract_patches_2d 
import os, sys 
from PIL import Image 



imgFile = Image.open('D1.gif') 
window_shape = (10, 10) 
B = extract_patches_2d(imgFile, window_shape) 

print imgFile 

,但我得到了以下错误:

AttributeError的:形状

我已经通过互联网搜索,我无法找到任何东西。如果有人能帮助我,我将非常感激。

预先感谢

回答

0

作为每对extract_patches_2d documentation第一个参数是一个数组或形状。

您应该先从imgFile中创建一个数组,然后将该数组传递给该函数。

import numpy 
import PIL 

# Convert Image to array 
img = PIL.Image.open("foo.jpg").convert("L") 
arr = numpy.array(img) 
+0

非常感谢你 – kadaj13