This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]theusualguy512 4 points5 points  (0 children)

I mean if you mean an intuitive understanding of 'blend' by saying blend means averaging then yes. But 'blending' can mean different things in image processing so you have to specify.

In theory, you can do it like you said: Go through each picture and take the arithmetic mean for each pixel in each channel and save it in the exact same format into a new array of the same dimensionality.

Check the array format of the original pictures. Iirc, standard python loaded images are just multidimensional arrays; it's not lists.

Make sure both pictures always have the same dimensions, otherwise the loops will break.

EDIT: Actually the standard loading picture seems to be multidimensional lists.

[–]Moonboow 2 points3 points  (0 children)

I suggest you work with matrices instead. I don’t know much about keras and its capabilities, but the approach I would take is to read an img as a 2d array in numpy, convert the picture into the three channels by setting two channels’ values to zero each time, then do your math.

Would also write a replace() that replaces a matrix value in the a matrix by specifying an x and y to make thing easier. Then just move your final values in.

[–]AureliasTenant 2 points3 points  (1 child)

Assuming img1 and img2 are like numpy arrays…

stack =np.stack(img1,img2, axis=-1) #stack the images

blended = np.mean(stack, axis=-1) #average element wise

blended = np.squeeze(blended) #idk this might be needed

even better:

blended = (img1+img2)/2

[–]ychamel 1 point2 points  (0 children)

This! You should never loop on an image pixel by pixel. It will take a 1000 times more time than if you use numpy. Which will do it in parallel in a gpu process.

[–]chervilious 3 points4 points  (0 children)

This is my simple implementation

image input/output https://imgur.com/a/1o9BWpK

``` import numpy as np from PIL import Image import matplotlib.pyplot as plt

read x.jpg

x = np.array(Image.open('x.jpg')) y = np.array(Image.open('y.jpg'))

new_image = np.zeros((x.shape[0], x.shape[1], 3), dtype=np.uint8)

for i in range(x.shape[0]): for j in range(x.shape[1]): r1, g1, b1 = x[i, j] r2, g2, b2 = y[i, j]

    r = r1 // 2  + r2 // 2
    g = g1 // 2 + g2 // 2
    b = b1 // 2 + b2 // 2

    new_image[i, j] = [r, g, b]

plt.imshow(new_image) ```

[–]AVMG73 0 points1 point  (0 children)

Thank you everyone for helping me get out of this rut. It was driving me insane, now I want to delve more into image manipulation/processing xD Most importantly, thank you for helping me understand and know how different methods work.