How to extract conjunctiva portion from eye image
I want to extract the red conjunctiva region using OpenCV (python) and store it as ROI(Region of Interest):
The final image should show only the red region. Using mask and getting the red region does not work always. A more generalized code is required.
Edit: Right now I am able to save the region of the eye containing the conjunctiva region.
Now I need to detect the red area from the 2nd image. That region is my ROI. However, I need to make sure that the code developed should be able to detect such a region always.
My code till now (in Python) is as follows:
import cv2
import numpy as np
def hisEqulColor(img):
ycrcb=cv2.cvtColor(img,cv2.COLOR_BGR2YCR_CB)
channels=cv2.split(ycrcb)
#print (len(channels))
cv2.equalizeHist(channels[0],channels[0])
cv2.merge(channels,ycrcb)
cv2.cvtColor(ycrcb,cv2.COLOR_YCR_CB2BGR,img)
return img
def reduce_size_of_image(img):
height, width = img.shape[:2]
eyebrow_h = int(height / 1.6) ## Can be made ~25%
width_left = int(width / 6)
width_right = int(width / 6)
# img = img[eyebrow_h:height, 0:width] # cut eyebrows out (15 px)
img = img[eyebrow_h:height, width_left:(width - width_right)]
return img
img = cv2.imread("Test_Image_21.jpeg")
eyesCascade = cv2.CascadeClassifier("haarcascade_eye.xml")
eyes = eyesCascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(100, 100))
if len(eyes) != 0:
print("Number of Eyes detected = ", len(eyes))
for (x, y, w, h) in eyes:
eye = img[y:y + h, x:x + w]
ROI = eye
cv2.imwrite("ROI_1.jpg", ROI)
ROI_reduced = cv2.imread('ROI_1.jpg')
ROI_reduced = reduce_size_of_image(ROI_reduced)
cv2.imshow('ROI', ROI)
cv2.waitKey(0)
cv2.imshow('ROI Reduced', ROI_reduced)
cv2.waitKey(0)
cv2.imwrite("ROI_Reduced.jpg", ROI_reduced)
ROI_reduced_1 = cv2.imread('ROI_Reduced.jpg')
ROI_reduced_1 = cv2.cvtColor(ROI_reduced_1, cv2.COLOR_BGR2GRAY)
CANNOT PROCEED FROM HERE ONWARDS!!
#ret,thresh1 = cv2.threshold(ROI_reduced_1,140,255,cv2.THRESH_BINARY_INV)
#kernel = np.ones((3,3),np.uint8)
#opening = cv2.morphologyEx(thresh1, cv2.MORPH_CROSS, kernel)
#closing = cv2.morphologyEx(thresh1, cv2.MORPH_CLOSE, kernel)
#ROI_reduced_1 = cv2.cvtColor(ROI_reduced_1, cv2.COLOR_BGR2GRAY)
#edges = cv2.Canny(ROI_reduced_1, 100, 200)
#threshold = 80
#_, img_thresh = cv2.threshold(ROI_reduced_1, threshold, 255, cv2.THRESH_BINARY)
#cv2.imshow('ROI Reduced after histogram equalization', img_thresh)
#cv2.waitKey(0)
else:
print("\nNo eyes detected!!")
cv2.destroyAllWindows()
show, what you tried, please ( code / images)
I have attached the code and images. Please help me with this @berak
@Sagnik18. This method doesn't detect red eye unless you do
inRange()
.@supra56 can you please share the code using inRange(). Also, I am interested in detecting the red conjunctiva portion and not red eyes.