[Python] OpenCV filter image by red and green

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to filter the image below into green and red. The aim of filtering the image is to be able to count the red and green cells in the image. I am using OpenCV to filter the image but the outcome isn't as expected please see images in Red and green filter. The filtered image seems to include more cells in either color, which will lead to an incorrect count. Is there anything I could do in the code to improve this, please? Many Thanks in advance.

    import cv2

    image = cv2.imread('2020-03-Sequence-p4-Day-0_Position070.png')

    b = image.copy()
    # set green and red channels to 0
    b[:, :, 1] = 0
    b[:, :, 2] = 0


    g = image.copy()
    # set blue and red channels to 0
    g[:, :, 0] = 0
    g[:, :, 2] = 0

    r = image.copy()
    # set blue and green channels to 0
    r[:, :, 0] = 0
    r[:, :, 1] = 0


    # RGB - Blue
    cv2.imshow('B-RGB', b)

    # RGB - Green
    cv2.imshow('G-RGB', g)

    # RGB - Red
    cv2.imshow('R-RGB', r)

    cv2.waitKey(0)


    Original[​IMG] image converted_images [​IMG]

    Continue reading...

Compartilhe esta Página