牛顿环简单处理

'''

牛顿环图案的中心暗点代表真实接触面积(RCA)。

法一:径向搜索法

    - 首先,确定牛顿环分布的质心。

    - 然后,根据质心任意绘制两个同心圆,其中一个比估计的RCA边界小,另一个比估计的RCA边界大。这两个圆圈之间包含所寻求的RCA边界所在的感兴趣区域。

    - 从质心开始的径向搜索线。当强度急剧增加并超过预先选择的阈值水平时,确定RCA边界点。

    - 然后用一个圆(使用圆形边缘检测函数拟合RCA的这些边界点,该函数的半径表示RCA的平均半径。

法二:拟合多边形法

    - 通过大于最大+大律法,找到最佳阈值

    - 对图像进行膨胀、腐蚀等,消除杂质

    - findContours()函数找到轮廓------>如何找到我们需要的圆形边界?限定半径?

    - 消除牛顿环

法三:霍夫找圆法

    - 通过大于最大+大律法,找到最佳阈值

    - 对图像进行膨胀、腐蚀,闭操作,消除小面积--->可以调节内核矩阵大小,闭操作次数

    - 霍夫找圆法:HoughCircles()函数找到圆心,画圆------>需要调节半径找到合适的圆

    - 消除牛顿环

法四:高阶条纹平均法

    To reduce this error, the image being analyzed is averaged with the image taken directly before and directly after the image of interest.

    Higher order, non-contact fringes will change as a result of a displacement of the rubber ball toward or away from the optical flat.

    If there is a change in the separation distance in the near contact zones, then the higher order fringes occupy different pixels from frame to frame.

    Consequentially, higher order dark fringes will not overlap throughout the three images as shown in Fig. 2b.

    This effectively removes higher order fringes, but does not remove impurities in the surface of the glass that result in false contact pixels.

    由于橡胶球朝向或远离光学平面,高阶非接触条纹(牛顿环)将发生变化。如果近接触区的分离距离发生变化,则高阶条纹在帧与帧之间占据不同的像素。高阶暗条纹在三幅图像中不会重叠

    - 一张待分析图像

    - 一张待分析图像之前和一张待分析图像之后拍摄的图像(球与玻璃距离发生改变)

    - 平均三幅图,得到接触区域,消除牛顿环

    - 没有加载时,拍摄一张图像,得到图像信息

    - 待分析图像减去背景图像------->消除背景杂质

'''

import numpy as np
import imutils
from cv2 import cv2 as cv
from matplotlib.patches import Circle

# 导入背景,前景图片
bg = cv.imread("D:/ZZ_WS_HFUT/05_Program/NewtonRing/Fig/background.jpg")
fg = cv.imread("D:/ZZ_WS_HFUT/05_Program/NewtonRing/Fig/TIR_red_30000.jpg")
# 灰度化处理
bgGray = cv.cvtColor(bg, cv.COLOR_BGR2GRAY)
fgGray = cv.cvtColor(fg, cv.COLOR_BGR2GRAY)
# 背景减法
sub = bgGray.astype("int32") - fgGray.astype("int32")
sub = np.absolute(sub).astype("uint8")

# 对图像进行阈值处理,以找到相减图像中像素差异较大的区域
thresh = cv.threshold(sub, 0, 255,
                        cv.THRESH_BINARY | cv.THRESH_OTSU)[1]

# perform a series of erosions and dilations to remove noise erode ,dilate 降噪处理
thresh = cv.erode(thresh, None, iterations=1)
thresh = cv.dilate(thresh, None, iterations=1)
# cv.imshow("handle_thresh", thresh)

# 发现边界
# our bounding box regions that contains the *entire* region of motion
cnts = cv.findContours(thresh.copy(), cv.RETR_EXTERNAL,
                        cv.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)

for c in cnts:
    (centerx, centery), r = cv.minEnclosingCircle(c)
    if r > 20:
        center = (int(centerx), int(centery))
        radius = int(r)
        contours = c
# draw a rectangle surrounding the region of motion
# 绘制长方形
# cv.rectangle(fg, (minX, minY), (maxX, maxY), (0, 255, 0), 1)
# cv.circle(fg, center, radius+5, (0, 255, 0), 1)
# 掩膜
# mask = np.zeros(copy_img.shape[:2], dtype=np.uint8)
# mask = cv.circle(mask, center, (int)(radius+0.01*radius), (255, 0, 255),-11)
# image = cv.add(copy_img, np.zeros(np.shape(copy_img), dtype=np.uint16), mask=mask,dtype=cv.CV_8UC3)
# image[mask == 0] = (255, 255, 255)
# show the output image
# 输出图形
thresh = cv.bitwise_not(thresh)
cv.imshow("original_img_thresh", thresh)
cv.imshow("original_img", fg)
# cv.imshow("bg", bg)
# cv.imshow("copy_img", copy_img)
# cv.imshow("ROI_img", image)
# cv.imwrite("./img/result1.jpg", image)
# # image2 =image.astype("uint8")
# # thresh_img = cv.threshold(image2, 0, 255,
# #                        cv.THRESH_BINARY | cv.THRESH_OTSU)[1]


# image_result = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
# t, dst = cv.threshold(image_result, 0, 255,cv.THRESH_BINARY | cv.THRESH_OTSU)
# binary = cv.adaptiveThreshold(image_result,255,cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY,3, 2)
# print("对截取图像进行阈值处理后的阈值:t ={}".format(t))
# cv.imshow("ROI_img_thresh", dst)
# cv.imshow("ROI_img_adaptiveThresh", binary)
cv.waitKey(0)

稍加修改代码

 

可以提取圆形接触区,其他不规则轮廓需要自定义限定条件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值