ImNotTooGood
ImNotTooGood

Reputation: 21

Trying to access a single array element in numpy accesses a sequence instead

I'm trying to make a program that takes random parts of various images and then adds them back together, but when i then try to access a single array element it comes out as a sequence instead.

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))

I've done some testing and deduced that the problem is in "select_from_image(img)" but i just can't put my finger on it. Here's an example output: https://i.sstatic.net/KNMo9.jpg

Any help is welcome!

Upvotes: 0

Views: 79

Answers (1)

ImNotTooGood
ImNotTooGood

Reputation: 21

I found the problem and it wasn't(entirely) the code. The images i was using weren't monochrome(which meant that each element in the array produced by imread had three values instead of one), so if anyone happens upon a problem like this and get's confused/frustrated read this: https://brohrer.github.io/convert_rgb_to_grayscale.html it helped me quite a bit!

Upvotes: 1

Related Questions