I am trying to analyze the red wells with different intensities from the attached image.
I want to analyze how the intensity of each red colored well differs from the others.
Does anyone have a solution without using the following code:
import numpy as np
import argparse
import cv2
# Construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help="path to the image")
args = vars(ap.parse_args())
# Load the image
image = cv2.imread(args["image"])
# Define the list of boundaries
boundaries = [
([17, 15, 100], [50, 56, 200]),
([86, 31, 4], [220, 88, 50]),
([25, 146, 190], [62, 174, 250]),
([103, 86, 65], [145, 133, 128])
]
# Loop over the boundaries
for (lower, upper) in boundaries:
# Create NumPy arrays from the boundaries
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")
# Find the colors within the specified boundaries and apply the mask
mask = cv2.inRange(image, lower, upper)
output = cv2.bitwise_and(image, image, mask=mask)
Assume we want to automatically find the red wells.
Assume we know that the wells are circular, and that the color is red (reddish).
We also know that the wells are not tiny, but we don't want to overfit the solution too much...
We may use the following stages:
Convert from BGR to HSV, and find the pixels in range that is considered red.
According to the post there are "lower_red" and "upper_red" ranges (we are keeping the ranges without tuning).
Iterate the contours.
Skip small contours (assumed to be noise).
cv2.minEnclosingCircle
as described here.Draw a filled circle for each contour, to form a mask, and use
cv2.bitwise_and
as used in your question.Code sample:
Results:
Image after bilateral filter:

raw_mask
:mask
:output0.png
:output1.png
:output2.png
:output3.png
:output4.png
:In case the circles are too large, we can reduce the radius, and get only the center of each well.