1

I have been looking to copy an image over anotherthis link.

I wrote a very simple python function:

def fromCopyTo(target, destination, x, y):
    h, w = target.shape

    destination[y:y+h,x:x+w] = target

    return destination

the concept is to get an target image and X and Y coordinates and copy the target image to that position - without thinking of the size of the target image (assume the destination image is big enough)

I am using an empty mask to copy to and trying to copy an image with a size 20x20 - the target image is only (0,0,0) and (255,255,255) colors

the problem is that y:y+h, returns maximum of size 11 rather than the size 20.

ValueError: could not broadcast input array from shape (20,20) into shape (11,20)

if I flip the function destination[x:x+w, y:y+h] = target (which as far as I understand is wrong) I get:

ValueError: could not broadcast input array from shape (20,20) into shape (20,0)

by testing I ran print len(destination[y_position:y_position+30, 0]) which returns everything up to 11 but after 11 it just maxes it out to 11. As the example returns 11.

what am I doing wrong ?

Community
  • 1
  • 1
Sparksmith
  • 113
  • 3
  • 8

1 Answers1

0

It turns out that if I try to cut more than there is available in the mask matrix I do not get an error message saying I am overflowing, but rather than that it just limits it to the maximum possible size.

Sparksmith
  • 113
  • 3
  • 8