Python中的补丁提取

2024-04-26 14:50:08 发布

您现在位置: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:形状

我在网上搜索了一下,什么也没找到。如果有人能在这方面帮助我,我将不胜感激。在

提前谢谢


Tags: from图像imageimport文件夹osextractsklearn
1条回答
网友
1楼 · 发布于 2024-04-26 14:50:08

根据documentation,提取补丁的第一个参数是数组或形状。在

您应该首先从imgFile创建一个数组,以便获取像素,然后将该数组传递给函数。在

import numpy
import PIL

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

相关问题 更多 >