News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

How to identify nearby pixels with similar intensities in image?

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.

enter image description here

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.


solution


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

enter image description here

Result

enter image description here

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()


Category of website: technical article > Q&A

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.

23 0
collect article
collected

Comment content: (supports up to 255 characters)