0

I would like to separate the red colour, however faint, from the rest of the image. I can't find a satisfactory method. I have used otsu threshold and adjusted the contrast, but so far I can't find anything satisfactory.  I receive different images, so the colour quantity can vary more or less. It would be necessary for the program to adapt to the image received using a threshoding method.

Do you have an idea?

This is the code I wrote. I get the green channel to be able to separate the colours and then I amplify the different colours with contrast_adjuster to get a better threshold at the end. But I can't get a very good threshold.

green = img[..., 1]

adj_green = contrast_adjuster(green)

ret = cv2.threshold(adj_green, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[0]

mask = cv2.threshold(green, ret, 255, cv2.THRESH_BINARY)[1]

Orange = cv2.bitwise_and(img, img, mask=mask)

Red = img - Orange

Red = cv2.cvtColor(Red, cv2.COLOR_BGR2GRAY)



def contrast_adjuster(img):
    equ = cv2.equalizeHist(img)

    return equ

Michael S.
  • 3,050
  • 4
  • 19
  • 34
cedrik24
  • 31
  • 7

0 Answers0