GarudaAiacos
GarudaAiacos

Reputation: 181

replacing white part of an image with another image

for i in range(25, 665):
  for j in range(55, 690): 
    pixel = background[i,j]
    whitePixel = [255,255,255]
    if np.array_equal(pixel,whitePixel):
      background[i,j] = rightsize[i-25,j-55]

when I do this code I get an image with ugly edges like this-

enter image description here

does anyone know how I can fix this and get it right? I dont understand Why it is doing this I have even tried adjusting the area of the rectangle so it was a little bigger than the white area and it still did this-

original background image-

enter image description here

now, the other image (rightsize) is just an image of the coin, which I cropped out in a perfect square around the coin, and resized to try and fit perfectly in a same sized square around that white circle, and replace the white parts with the coin, but for some reason the edges turn out like that. I have had this same problem before when doing a double loop like this to replace pixels.

Upvotes: 0

Views: 427

Answers (1)

Sunreef
Sunreef

Reputation: 4552

It looks like your problem comes from image compression. The borders of your circle are not exactly white. This happens when you load a jpeg image into your program.

What you could do is to threshold your image and search white pixels on this thresholded image.

Upvotes: 1

Related Questions