0

Image 1

the pixel values are 0 for background and 2 for white area

Image 2

the pixel values are 0 for background and 1 for white area

how do i combine them to a new image 3 such that -every area in image 2 that is pixel value 0 remains 0 in new image -every area in image 2 that is pixel value 1 remains 1 -every area in image 1 that is pixel value 2 remains 2 in new image (including areas that are 1 in image 2)

Basically the output should look similar to the one below

Image 3

I used the | method in python since im dealing with ndarrays (h,w) image3=img1|img2

Im getting new pixel values ranging from 0 1 2 and 3 What i want is only 0, 1 and 2 All images are displayed using plt.imshow(img, cmap="gray") which is why they look contrasted.

1 Answers1

0

If the 2 Images are the same size i would add them both together and then replace all 3s by 2s.

fexplorer
  • 1
  • 1
  • how can i convert all 3's to 2's? – saalim k Sep 22 '21 at 11:05
  • I haven't worked with numpy for a while. Maybe this helps: https://stackoverflow.com/questions/19666626/replace-all-elements-of-python-numpy-array-that-are-greater-than-some-value – fexplorer Sep 22 '21 at 11:44
  • Thank you soo much The link was very helpful For future reference this can be used to convert pixels arr[arr > 255] = x – saalim k Sep 22 '21 at 15:09