0

I'm using the following code to create mask with the white color. But when I extract it, I want it to be transparent. How can I do it?

 mask = cv2.ellipse(mask, center=(cX, cY), axes=(axesX, axesY), angle=0, startAngle=0, endAngle=360,
                       color=(255, 255, 255), thickness=-1)

inside = np.bitwise_and(image, mask)
outside = np.bitwise_and(image, ~mask)

http://answers.opencv.org/question/25523/extract-an-ellipse-form-from-an-image-instead-of-drawing-it-inside/

enter image description here

enter image description here

jason
  • 3,932
  • 11
  • 52
  • 123
  • Do you want the extracted image to be transparent? Also, post your image as an example. – zindarod Sep 16 '17 at 20:34
  • Use **dst = cv2.addWeighted(img1,0.7,inside,0.3,0)** Where **img1=np.zeros_like(inside)**. – I.Newton Sep 17 '17 at 05:57
  • @Zindarod It's similar to any product image on e-commerce website with white background mostly. It can also be black in some cases. You can pick any product image from amazon – jason Sep 17 '17 at 07:01
  • @I.Newton it's not working – jason Sep 17 '17 at 07:25
  • It would be better if you add your images as to exactly what you want. [Check this](http://docs.opencv.org/trunk/d0/d86/tutorial_py_image_arithmetics.html) – I.Newton Sep 17 '17 at 09:16
  • @I.Newton I've updated the image. I need the image without white color. How can I do that? – jason Sep 17 '17 at 12:33
  • Sorry for the late reply, but if you are saying you need the white portion to be image or the opposite, you need to do operations like inverting the mask and adding to the image or adding their weighted sum etc depending on what the expected output is. The link i gave above shows an example. – I.Newton Sep 19 '17 at 04:37
  • 1
    @I.Newton I found the answer. I'm using pillow for Transparency+Mask : https://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent – jason Sep 19 '17 at 12:23

1 Answers1

0

I've fixed it by using the following code for Tranparency+Mask

Using PIL to make all white pixels transparent?

jason
  • 3,932
  • 11
  • 52
  • 123