在 Python 中提取补丁
Patch Extracting In 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
但是我收到以下错误:
属性错误:形状
我通过互联网搜索过,但找不到任何东西。如果有人能帮助我,我将不胜感激。
提前致谢
根据documentation,extract_patches_2d 的第一个参数是数组或形状。
您应该首先从 imgFile 创建一个数组,以便获取像素,然后将该数组传递给函数。
import numpy
import PIL
# Convert Image to array
img = PIL.Image.open("foo.jpg").convert("L")
arr = numpy.array(img)
我有一张图片,我想提取它的补丁,然后将每个补丁作为图像保存在该文件夹中。这是我的第一次尝试:
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
但是我收到以下错误:
属性错误:形状
我通过互联网搜索过,但找不到任何东西。如果有人能帮助我,我将不胜感激。
提前致谢
根据documentation,extract_patches_2d 的第一个参数是数组或形状。
您应该首先从 imgFile 创建一个数组,以便获取像素,然后将该数组传递给函数。
import numpy
import PIL
# Convert Image to array
img = PIL.Image.open("foo.jpg").convert("L")
arr = numpy.array(img)