1

I am trying to compare the two circular areas in Image1 and Image2. My current code gets me a white circle for image1, but falls apart for image2.

Is there another way to find the two circular areas for both images?

import cv2
import numpy as np

img = cv2.imread('Resources/Image2.jpg')
imgHSV = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

lower = np.array([40,28,18])
upper = np.array([70,161,255])

#imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

mask = cv2.inRange(imgHSV, lower, upper)

maskInv = cv2.bitwise_not(mask)
#imgCanny = cv2.Canny(imgBitGrey,150,200)


cv2.imwrite('Resources/Image2_Inv.jpg', maskInv)

#cv2.imshow('Original',img)
#cv2.imshow('Grey',imgGray)
#cv2.imshow('BitGrey',imgBitGrey)
#cv2.imshow('Canny',imgCanny)
#cv2.imshow('InvCanny',imgInvCanny)

cv2.imshow('maskInv',maskInv)
cv2.imshow('Mask',mask)
#cv2.imshow('Invert',imgInvMask)

cv2.waitKey(0)

Original: Original image

Modified: Modified image

Image1_Inv Image2_Inv

  • 5
    What is your actual question? What is the specific issue with your code, error, or task that you are unable to complete? – G. Anderson Sep 29 '20 at 19:10
  • 1
    Get your wound region as white on a black background. Then findContours(). Then contourArea() for each. – fmw42 Sep 29 '20 at 19:19

1 Answers1

0

It is ok to do it with HSV colorspace.

Try these bounds:

Lower: [18, 100, 44]
Upper: [36, 156, 71]

With them you may be able to get image mask as below.

enter image description here

To further improve it you can use connected components with OpenCV function: cv2.connectedComponentsWithStats. You can get the biggest component (which is what you want) by checking this answer

dpetrini
  • 1,169
  • 1
  • 12
  • 25
  • Thanks for your comments. I used different settings to get a more solid black area of interest then converted that to white. But it only works for Image1, not Image2 which is more mottled. – RayzedByRobots Oct 01 '20 at 15:17
  • You need to find other limits for image2. – dpetrini Oct 02 '20 at 16:49
  • Right - I wanted to be able to use one program/settings for all of my images. I will probably be comparing 25-30 images and it will be a super time saver to be able to not have to use custom settings for each image. Any other ways to find the circular areas of images 1 and 2? – RayzedByRobots Oct 04 '20 at 21:55
  • Ok. In these case I think will be hard with features manipulation in open CV. You should go straight to machine learning algorithms for this case that you have this amount of images. Nowadays you could go straight to deep learning models. I'd say that you should try image segmentation with Unet. It should be well fit for your problem. – dpetrini Oct 06 '20 at 10:26