Search code examples
c++opencvdetectionhsv

OpenCV HSV weird converted


I am working on project what detect hematoma from skin. I am having issue with color after convertion from RGB to HSV. My algorithm detect hematoma by its color.

With some images I have good results like here:

Original img: https://i.sstatic.net/ec9NC.jpg Result img: https://i.sstatic.net/VrQrO.jpg

But with some images i have bad result like this:

Original img: https://i.sstatic.net/O9deG.jpg Result img: https://i.sstatic.net/F08Mc.jpg

The same original image after convertion to HSV: https://i.sstatic.net/suXbS.jpg

Do you have any ideas how to fix it?

Thanks


Solution

  • Looking at your result image I think that you are only using the H channel of the original image in your algorithm. The false positive detection can inherit from that the some part of the healty skin has quite the same H value than the hematoma has. You can see on the qrey-scale image of H channel that both parts have similar values:

    H channel of original image The difference between the two parts is the saturation value. On the following image you can see the S channel of the original image and it shows perfectly that at the hematoma the saturation is much higher than at other the part of the arm:

    enter image description here This was expected because the hematoma has much stronger color than the healty skin has.

    So, I suggest you to use both H and S channel in your algorithm that is you have to take into account only that parts of H image where the S image contains high saturation values. A possible and simple solution to do that is that you binarize both H and S images and with an AND operation you can execute this filtering:

    H image after binarisation: enter image description here S image after binarisation: enter image description here Image after H&S operation: enter image description here You can see that on the result image only the hematoma part is white (except some noise but you can eliminate easily, for example by size or by morphological filtering).

    EDIT

    Important to note that binarization is one of most important (and sometimes also very complicated) step in the object detection algorithms namely binarization is the first highlight of the objects to detect.

    If the the external conditions (lighting, color of objects etc.) do not change significantly from image to image you can use fix binaraziation thresholds. If this constant environment can not be issured you have to use more complicated methods. There are a lot of possibilies you can use, here you can read some examples:

    Several solutions are based on the histogram analysis: on the histograms with objects there are always more local maximums which positions can vary depend on the environment and if you find them you can adapt the binarization threshold easily.

    For example the histogram of the H channel of the original image is the following: Histrogram The first maximum belongs to the background, the second to the skin and the last to the hematome. It can be supposed that these 3 thresholds can be found in each image only their positions vary depend on the lighting or on other conditions. To put a threshold between the 2nd and the 3rd local maximum it can be a good choice to highlight the hematome.

    Finally I offer you the read the following articel about thresholding in OpenCV: OpenCV - Thresholding