[Python] How to Mask an image using Numpy/OpenCV?

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have an image I load with:

    im = cv2.imread(filename)


    I want to keep data that is in the center of the image. I created a circle as a mask of the area I want to keep.

    I created the circle with:

    height,width,depth = im.shape
    circle = np.zeros((height,width))
    cv2.circle(circle,(width/2,height/2),280,1,thickness=-1)


    How can I mask out the data outside of the circle from the original image?

    masked_data = im * circle


    does not work.

    Continue reading...

Compartilhe esta Página