如何正确选择液滴内的气泡

如何解决如何正确选择液滴内的气泡

这是Wendy.Image处理相关的问题。 我必须正确选择气泡以分析其大小并计算图像序列之间的速度。

原始图片
enter image description here

图像序列 enter image description here // enter image description here // enter image description here

图片中最大的形状是液滴,液滴内部包含许多微小的气泡。

到目前为止,问题是: 1.由于气泡的形状破裂,几乎没有检测到轮廓。同时,检测到许多边缘。如何将边缘填充为轮廓(像一枚硬币,我只想要每个气泡的轮廓,而又不想让气泡内的线条出现)

当前进度
enter image description here
enter image description here

代码(检测轮廓)

gray=cv2.imread("1000.tif")
blurred = cv2.GaussianBlur(gray,(3,3),0)
edged = cv2.Canny(blurred,5,60)
cv2.imshow('edged ',edged )
cv2.waitKey(0)
contours,hierarchy = cv2.findContours(edged,cv2.RETR_EXTERNAL,cv2.RETR_LIST)
img = gray.copy()
cv2.drawContours(img,contours,-1,(0,255),1)  
cv2.imwrite("contours.tif",img)
cv2.imshow("contours",img)  
cv2.waitKey(0)  

代码(填充孔)

im_floodfill = edged.copy()
h,w = edged.shape[:2]
mask = np.zeros((h+2,w+2),np.uint8)
cv2.floodFill(im_floodfill,mask,0),255)
im_floodfill_inv = cv2.bitwise_not(im_floodfill)
im_out = edged | im_floodfill_inv
cv2.imshow("Thresholded Image",edged)
cv2.imshow("Floodfilled Image",im_floodfill)
cv2.imshow("Inverted Floodfilled Image",im_floodfill_inv)
cv2.imshow("Foreground",im_out)
cv2.waitKey(0)
cv2.imwrite("fill.jpg",im_out)

结果将是
enter image description here

  1. 气泡的速度是我的目标。我试图将二进制图像序列放入Iamgej,并使用“ trackmate”(用于自动和半自动粒子跟踪的工具)。它具有固定的气泡大小设置以进行跟踪,但是,在我的情况下,气泡的大小完全不同,因此是否有任何方法可以跟踪气泡的运动?

如果这还不够清楚,请告诉我,我可以尝试更加具体。谢谢您的时间。

解决方法

这是Python / OpenCV中的一种方法。

  • 阅读输入内容
  • 转换为灰色
  • 阈值
  • 用形态填充孔
  • 获取轮廓和最大轮廓(尽管大概只有一个)
  • 在输入的副本上绘制轮廓
  • 保存结果

输入:

enter image description here

import cv2
import numpy as np

# read image
img = cv2.imread('vapor.jpg')

# convert to grayscale
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# threshold
#thresh = cv2.threshold(gray,5,255,cv2.THRESH_BINARY)[1]
thresh = cv2.threshold(gray,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]

# apply close morphology to fill white circles
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(45,45))
thresh_cleaned = cv2.morphologyEx(thresh,cv2.MORPH_CLOSE,kernel)

# get largest contour
contours = cv2.findContours(thresh_cleaned,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]
big_contour = max(contours,key=cv2.contourArea)

# draw contour
result = img.copy()
cv2.drawContours(result,[big_contour],(0,255),1) 

# save image with points drawn
cv2.imwrite('vapor_thresh.jpg',thresh)
cv2.imwrite('vapor_cleaned_thresh.jpg',thresh_cleaned)
cv2.imwrite('vapor_contour.jpg',result)

cv2.imshow("thresh",thresh)
cv2.imshow("thresh_cleaned",thresh_cleaned)
cv2.imshow("contour",result)
cv2.waitKey(0)
cv2.destroyAllWindows()

阈值图像:

enter image description here

形态填充图像:

enter image description here

轮廓图片:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-