I am working with images through numpy. I want to set a chunk of the image to its average color. I am able to do this, but I have to re-index the array, when I would like to use the original view to do this. In other words, I would like to use that 4th line of code, but I'm stuck with the 3rd one.
I have read a few posts about the as_strided function, but it is confusing to me, and I was hoping there might be a simpler solution. So is there a way to slightly modify that last line of code to do what I want?
box = im[x-dx:x+dx, y-dy:y+dy, :] avg = block(box) #returns a 1D numpy array with 3 values im[x-dx:x+dx, y-dy:y+dy, :] = avg[None,None,:] #sets box to average color #box = avg[None,None,:] #does not affect original array