如何找到单个图像中存在的两个物体的强度?

How to find intensity of two object present in single image?

我正在 python 工作并使用公开的简历。我想找到图像中存在的两个物体的平均强度。 我想我可以制作轮廓,然后通过将每个轮廓视为不同的对象来找到强度。但是,我不知道该怎么做。 到目前为止我的代码是

img = cv2.imread('F:\Multispectral Imaging\Readings\Reading to find intensity of two samples in one image\image0.bmp'
blur = cv.GaussianBlur(img,(5,5),0)
ret,thresh = cv.threshold(blur,50,255,cv.THRESH_BINARY)
contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

这之后我可以做什么来找到两个白点的强度? 下面是图片。

.

我正在使用下面的代码。然后我计算图像中每个对象的平均强度。

import cv2
import numpy as np

img = cv2.imread('img.png')
gray= cv2.cvtColor(img , cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)

#thresh = cv2.adaptiveThreshold( blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV , 201, 11)
_,thresh = cv2.threshold( gray, 20, 255, cv2.THRESH_BINARY )
thresh = cv2.erode( thresh, np.ones((5,5)))
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL , cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
    mask = np.zeros_like(gray)
    cv2.drawContours(mask,[cnt],0, 255, -1)
    res = cv2.bitwise_and(gray,gray,mask=mask)
    idx = np.where( mask==255)
    print('mean:',np.mean(gray[idx]))
    print('max:',np.max(gray[idx]))

    cv2.imshow('object', res)
    cv2.waitKey(0)

mean = 193 max = 255

mean = 40 max=111