0

我正在尝试制作一个程序,该程序获取各种图像的随机部分,然后将它们重新组合在一起,但是当我尝试访问单个数组元素时,它会以序列的形式出现。

def select_from_image(img):
    factor=rng.uniform(1/20,1/10)
    width=int(np.floor(img.shape[1]*np.sqrt(factor)))
    height=int(np.floor(img.shape[0]*np.sqrt(factor)))
    x=rng.randint(0,img.shape[1]-1-width)
    y=rng.randint(0,img.shape[0]-1-height)
    return img[y:y+height-1:,x:x+width-1:]
imgs=[]
for i in range(len(paths)):
    imgs.append(ig.imread(paths[i]))
selection=[]
for img in imgs:
    selection.append(select_from_image(img))

我已经做了一些测试并推断出问题出在“select_from_image(img)”中,但我就是无法解决问题。这是一个示例输出: https ://imgur.com/a/1Cs8i4J

欢迎任何帮助!

4

1 回答 1

1

我发现了问题,它不是(完全)代码。我使用的图像不是单色的(这意味着 imread 生成的数组中的每个元素都有三个值而不是一个),所以如果有人遇到这样的问题并感到困惑/沮丧,请阅读: https:// brohrer.github.io/convert_rgb_to_grayscale.html 它对我帮助很大!

于 2020-04-15T10:50:28.893 回答