Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18906

Detect and create mask for color highlighted section on image

$
0
0

May I humbly inquire as to how I may create a highlight mask for an image? I have attempted various methods, however, I have not been able to attain the desired outcome. Might you kindly advise me on how to detect colored sections without any adverse effects on the pink colored section, or any other color such as yellow?

Input

Current Output

Desired output

import cv2import numpy as npdef detect_highlighted_text(image_path):    image = cv2.imread(image_path)    hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)    lower_pink = np.array([150, 50, 50])    upper_pink = np.array([180, 255, 255])    lower_red = np.array([0, 50, 50])    upper_red = np.array([10, 255, 255])    pink_mask = cv2.inRange(hsv_image, lower_pink, upper_pink)    red_mask = cv2.inRange(hsv_image, lower_red, upper_red)    combined_mask = cv2.bitwise_or(pink_mask, red_mask)    highlighted_text = cv2.bitwise_and(image, image, mask=combined_mask)    cv2.imshow("Highlighted Text", highlighted_text)    cv2.waitKey(0)    cv2.destroyAllWindows()detect_highlighted_text("path/to/your/image.jpg")

I tried to use create mask using inRange function, also searched about using findCountors.

Thanks in advance!


Viewing all articles
Browse latest Browse all 18906


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>