hi I have a medical project that want extract a special part(Conjuctiva Puplpebral)my just wanted region to extract of eye image without understanding of its coordinates automatically not manually. my goal is determining anemia from non anemia by counting red pixel in conjuctiva pulpubral. I use masking method(k means) to do that but i wish could do a way that first extract conjuctiva pulpebral directly then use k means to mask the image and find beacause my result will be more accurate. when i use k mean from image segmentation i find another and overlapping red pixel that ruin my accuracy.k_means I also hear about machine learning to use but but after doing machine learning to find near region in images of my patients then i will need to extract conjuctival pulpabral. so i need to codes to extract only and only conjuctival pulpubral.
``import cv2
import numpy as np
# Read the image
image = cv2.imread('c:/users/stk/desktop/d.png')
# Convert the image to HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# Define the lower and upper bounds for the red color
lower_red = np.array([0, 120, 70])
upper_red = np.array([10, 255, 255])
# Create a mask for the red color
mask1 = cv2.inRange(hsv, lower_red, upper_red)
# Define the lower and upper bounds for the red color
lower_red = np.array([170, 120, 70])
upper_red = np.array([180, 255, 255])
# Create a mask for the red color
mask2 = cv2.inRange(hsv, lower_red, upper_red)
# Combine the two masks
mask = mask1 + mask2
# Create a kernel for morphological operations
kernal = np.ones((5, 5), np.uint8)
# Perform morphological operations
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernal)
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernal)
# Apply the mask to the original image
result = cv2.bitwise_and(image, image, mask = mask)
# Save the result
cv2.imwrite('extracted_red_object.png', result)
# Display the result
cv2.imshow('EXTRACTED RED OBJECT', result)
cv2.waitKey(0)
cv2.destroyAllWindows()`
`
i try k_means and kernel but add another unwanted red pixel