no classification
no tag
no datas
posted on 2023-11-12 14:30 read(328) comment(0) like(23) collect(4)
I have an image which is as given below and I have created the mask for that image (the red dots are generated from the mask). The points in the mask should ideally cover the entire black dots on the image but as I just have one co-ordinate for each black patch, the resultant image looks as given below.
How do I identify the surrounding pixels (greys and lighter blacks) and mark them as well? Is there any way or method that I can look up and implement.
If I'm understanding you correctly, you want to convert all the surrounding gray and dark pixels to red. If so, here's an approach using OpenCV. The idea is to load the image, convert to grayscale, then Otsu's threshold to obtain a 1-channel binary image. This will give us a mask where we can use np.where
to color pixels red where there are white pixels on the mask. Here's the results:
Binary mask
Result
import cv2
import numpy as np
# Load image, grayscale, Otsu's threshold
image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV)[1]
# Color pixels red where there are white pixels on the mask
image[np.where(thresh==255)] = [0,0,255]
# Display
cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey()
Author:qs
link:http://www.pythonblackhole.com/blog/article/245161/8af0177dbc1a4cd87a30/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!