O
O
one__for__one2019-01-12 20:44:31
Python
one__for__one, 2019-01-12 20:44:31

How to correctly recognize white (and its shades) in an image?

Hello.
It is required to recognize "blots" of white color (and its shades) on the image: highlight the areas of "blots" on the image and calculate the area of ​​"blots" as a percentage of the total size of the image.
5c3a2609740ce891630063.jpeg5c3a260fc66b7043143097.jpeg

import cv2 as cv
import numpy as np
h_min = np.array((50, 50, 50), np.uint8)
h_max = np.array((255, 255, 255), np.uint8)
img = cv.imread(r'C:\\1.jpg')
hsv = cv.cvtColor( img, cv.COLOR_BGR2HSV )
thresh = cv.inRange( hsv, h_min, h_max )
contours, hierarchy = cv.findContours( thresh.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
cv.drawContours( img, contours, -1, (255,0,0), 3, cv.LINE_AA, hierarchy, 1 )
cv.imshow('result', img)
cv.waitKey(234234)

The blob is always surrounded by a black border.
In this case, what is the best way to proceed, to carry out morphological processing of the image in order to smooth out the noise for a better search for blobs? Although the "blot" is in shades of white, it is not monophonic. How to take into account only the blobs that are surrounded by a black border, look for black objects, and then only look inside them for my "blobs"?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question