提取图像感兴趣区域

Welcome to the second post in this series where we talk about extracting regions of interest (ROI) from images using OpenCV and Python.

欢迎来到本系列的第二篇文章,我们讨论使用OpenCV和Python从图像中提取感兴趣区域(ROI)。

As a recap, in the first post of this series we went through the steps to extract balls and table edges from an image of a pool table. We used simple OpenCV functions like inRange, findContours, boundingRect, minAreaRect, minEnclosingCircle, circle, HoughLines, line etc to achieve our objective.

回顾一下,在本系列的第一篇文章中,我们完成了从台球桌图像中提取球和桌边的步骤。 我们使用了简单的OpenCV函数(例如inRange,findContours,boundingRect,minAreaRect, minEnclosingCircle,circle,HoughLines,line等)来实现我们的目标。

For beginners in OpenCV, I would recommend to go through that post in order to get familiar with the usage of the above functions.

对于OpenCV初学者,我建议您仔细阅读该文章 ,以熟悉上述功能的用法。

In this post we will look at a somewhat more complex problem and explore some methods which we can use to obtain the desired results.

在这篇文章中,我们将研究一个更为复杂的问题,并探索一些可用于获得所需结果的方法。

Our task today is to extract the desired segments from an image which contains a snapshot of a patients brain activity map. The extracted segments can then be used in numerous applications e.g. in a Machine Learning model which can diagnose any health anomalies.

今天的任务是从包含患者大脑活动图快照的图像中提取所需的片段。 然后,可以将提取的段用于多种应用程序,例如可以诊断任何健康异常的机器学习模型。

So let us start by looking at the input image itself. It is a typical report generated by medical instruments used in the field of Neurological Science which use sensors to detect signals from a patients brain and display them as colored maps. Typically there are four maps, all of which depict a certain feature and are analyzed together for diagnosis (further details are out of current scope).

因此,让我们从查看输入图像本身开始。 这是由神经科学领域的医疗仪器生成的典型报告,该仪器使用传感器检测来自患者大脑的信号并将其显示为彩色地图。 通常,有四张地图,所有地图都描绘了某个特征并一起分析以进行诊断(更多详细信息不在当前范围内)。

From the above image, we want to extract only the regions corresponding to the four maps (head scans) leaving everything else out. So lets get going.

从上面的图像中,我们只想提取与四个地图(头部扫描)相对应的区域,而将其他所有内容都排除在外。 因此,让我们开始吧。

The first step is detecting the edges of the segments we want to extract. This is a multi step process as mentioned below:

第一步是检测我们要提取的片段的边缘。 这是一个多步骤过程,如下所述:

  1. Convert the RGB image to gray-scale using “cvtColor()”

    使用“ cvtColor()”将RGB图像转换为灰度

  2. Remove noise from the gray-scale image by applying a blurring function “GaussianBlur()”

    通过应用模糊函数“ GaussianBlur()”来消除灰度图像中的噪声

  3. Finally applying the “Canny()” function to the blurred image to obtain the edges

    最后将“ Canny()”函数应用于模糊图像以获得边缘

The output of the edge detection process looks something like this:

边缘检测过程的输出如下所示:

Edge detection output using Canny algorithm (image source author)
使用Canny算法的边缘检测输出(图像源作者)

Notice that although the brain map segments are identified, there are a lot of unwanted edges which need to be eliminated and some of the edges have gaps in between which need to be closed.

请注意,尽管已识别出脑图片段,但仍有许多不需要的边缘需要消除,并且某些边缘之间有间隙需要封闭。

A common method applied for such purpose is Morphological Transformation which involves using a succession of dilations and erosions on the image to remove unwanted edges and close gaps.

用于此目的的常用方法是形态转换 ,它涉及在图像上使用一系列的扩张和腐蚀来去除不需要的边缘和闭合间隙。

We use OpenCV functions “dilate()” and “erode()” over multiple iterations to get an output as below.

我们通过多次迭代使用OpenCV函数“ dilate()”和“ erode()”来获得如下输出。

Some enhancements in the edges using OpenCV (image source author)
使用OpenCV(图像源作者)对边缘进行了一些增强

As you can see, the edges are now complete and much smoother than before.

如您所见,边缘现在已经完成并且比以前光滑得多。

Now we can extract the contours in this image using OpenCV function “findContours()” and select only those contours which have the following properties:

现在,我们可以使用OpenCV函数“ findContours()”提取该图像中的轮廓,并仅选择具有以下属性的轮廓:

  1. Geometry is circle or oval shaped几何形状是圆形或椭圆形
  2. Area is above a certain threshold (the value 7000 works fine for this example).面积大于某个阈值(在此示例中,值7000可以正常工作)。

For the first part, we will detect the bounding rectangle of each contour using OpenCV “boundingRect()” and check whether the aspect ratio (height to width ratio) is close to 1.

对于第一部分,我们将使用OpenCV“ boundingRect()”检测每个轮廓的边界矩形,并检查纵横比(高宽比)是否接近1。

It may appear that our task is finished but there is a little bit of fine tuning required.

看来我们的任务已经完成,但需要进行一些微调。

It is often the case that multiple overlapping contours are detected over a segment whereas we are interested in only one.

通常情况是在一个片段上检测到多个重叠的轮廓,而我们只对一个感兴趣。

This problem is solved using Non Maxima Suppression, i.e. we look at all overlapping contours and select the one with the maximum area as the final candidate. The logic is pretty straightforward hence we do not need any inbuilt OpenCV or Python functions.

使用非最大抑制可以解决此问题,即,我们查看所有重叠的轮廓,然后选择面积最大的轮廓作为最终候选轮廓。 逻辑非常简单,因此我们不需要任何内置的OpenCV或Python函数。

Another important logic is to identify the four segments separately i.e. Top-Left, Top-Right, Bottom-Left and Bottom-Right.

另一个重要的逻辑是分别识别四个段,即左上,右上,左下和右下。

This is also pretty straightforward and involves identifying the image center coordinates as well as the centroid of each of our detected segments. Centroid detection of a segment contour requires applying the OpenCV “moments()” function on the contour and then calculating the center X, Y coordinates using the formula below: center_x, center_y = (int(M[“m10”] / M[“m00”]), int(M[“m01”] / M[“m00”]))

这也非常简单,涉及识别图像中心坐标以及每个检测到的片段的质心。 对段轮廓进行质心检测需要在轮廓上应用OpenCV “ moments()”函数,然后使用以下公式计算中心 X,Y坐标: center_x,center_y =(int(M [“ m10”] / M [” m00”]),int(M [“ m01”] / M [“ m00”]))

Comparing the segment centroid coordinates with the image center coordinates lets us place the four segments in their respective positions.

将线段质心坐标与图像中心坐标进行比较,可以将四个线段放置在各自的位置。

Now that we have the four segments identified, we need to build the image mask which will allow us to pull out the desired features from the original image.

现在我们已经确定了四个部分,我们需要构建图像蒙版,这将使我们能够从原始图像中提取所需的特征。

We will use the OpenCV function “drawContours()” using color as White (R,G,B=255,2555,255) and thickness as FILLED (-1) to draw all four segment contours over a black background. The result looks like below:

我们将使用OpenCV函数“ drawContours()”,将颜色用作白色(R,G,B = 255,2555,255),将厚度用作FILLED(-1)在黑色背景上绘制所有四个线段轮廓。 结果如下所示:

Mask for extracting our ROIs (image source author)
用于提取我们的ROI的蒙版(图像来源作者)

Applying this mask on the original image gets us the desired segments over a background of our choice (e.g. Black or White).

在原始图像上应用此蒙版可以在我们选择的背景(例如黑色或白色)上为我们提供所需的分段。

For a black background we create a black canvas and then draw upon it using the OpenCV function “bitwise_and()” with the previously obtained mask.

对于黑色背景,我们创建一个黑色画布,然后使用OpenCV函数“ bitwise_and()”以及先前获得的蒙版在其上进行绘制。

Extracted ROIs over a black background (image source author)
在黑色背景上提取的ROI(图像源作者)

For a white background we first create a white canvas and then create a color inverted mask as below by drawing contours with OpenCV function “drawContours()” in black color (R,G,B = 0,0,0) and thickness as FILLED (-1).

对于白色背景,我们首先创建一个白色画布,然后通过使用OpenCV函数“ drawContours()”绘制轮廓为黑色(R,G,B = 0,0,0)并且厚度为FILLED的颜色,如下所示创建颜色反转的蒙版(-1)。

An alternative Inverted mask for ROI extraction (image source author)
用于ROI提取的备用倒置掩模(图像源作者)

We then add this inverted mask with the previously obtained black background using OpenCV “add()” function and achieve the same result but with white background.

然后,我们使用OpenCV “ add()”函数将此反向蒙版添加到先前获得的黑色背景中,并获得相同的结果,但使用白色背景。

Extracted ROIs over a white background (image source author)
在白色背景上提取的ROI(图像源作者)

This concludes the current post in which we looked at few methods using which we can easily extract regions of interest from images.

到此为止,我们在当前文章中总结了几种方法,可以轻松地从图像中提取感兴趣区域。

It should be noted that the methods used above may undergo modifications in case of other images with varying complexity. However the basics discussed above would lay the groundwork for any advanced techniques that may be required to solve such problems.

应当注意,在具有变化的复杂度的其他图像的情况下,上面使用的方法可以进行修改。 但是,以上讨论的基础将为解决此类问题所需的任何高级技术奠定基础。

翻译自: https://towardsdatascience.com/extracting-regions-of-interest-from-images-dacfd05a41ba

提取图像感兴趣区域


http://www.taodudu.cc/news/show-3189578.html

相关文章:

  • OpenCV实战(3)——图像感兴趣区域
  • 什么是兴趣点 (POI)
  • 计算机病毒可以破坏网络吗,计算机病毒的主要危害
  • DNS劫持有什么危害?
  • 简述xss漏洞原理及危害?xss漏洞有哪些类型?xss漏洞哪个类型危害最大?如何防御xss漏洞
  • 二层环路危害
  • 安全网络架构
  • 常见Web漏洞危害及整改建议
  • 【计算机网络】BitTorrent技术对网络的潜在危害
  • 网络监听概述
  • 网络层基础
  • 破坏计算机网络信息罪,破坏计算机信息系统危害网络安全怎么量刑
  • 拒绝服务攻击是对计算机网络的哪种,信息安全技术题库:DoS攻击是一种对网络危害巨大的恶意攻击,其中,具有代表性的攻击手段包括SYN洪泛、ICMP洪泛、UDP洪泛等。()...
  • 网络安全十大威胁的防范方法
  • 网络的便利与危害
  • 知乎:您的帐号由于存在异常行为暂时被知乎反作弊系统锁定怎么解封?
  • 知乎申请B乎商标,这一波算自黑吗
  • 抖音知乎推文项目怎么申请关键词
  • Python爬虫——爬取知乎(实践)
  • 查找知乎的真实IP地址
  • 知乎的彩蛋
  • 知乎数据的抓取
  • 知乎口碑营销方式有几种?知乎口碑营销可靠性高吗?
  • python爬取知乎话题广场_用于爬取知乎某个话题下的精华问题中所有回答的爬虫...
  • python requests cookie保存_Python爬虫教程:爬取知乎网
  • Scrapy分布式爬虫打造搜索引擎 - (三)知乎网问题和答案爬取
  • 知乎的技术方案
  • 罗克韦尔定时器的一些应用
  • 罗克韦尔自动化收购网络安全公司
  • 罗克韦尔自动化发展简史

提取图像感兴趣区域_从图像中提取感兴趣区域相关推荐

  1. PDF提取页面方法,如何从PDF文件中提取页面

    现在科技与时代的进步与发展人们所接触的都提升了,就连我们日常使用的文件类型也多样性了,现在使用很多的文件是PDF文件,那么有小伙伴们知道该怎么从PDF文件中提取页面吗,PDF提取页面的方法是什么呢,今 ...

  2. 2.2 获取图像感兴趣区域_几何变换图像裁剪

    基于FPGA图像的裁剪 1 几何变换介绍 几何变换:从新规定图像内像素的几何排列方式. 几何变换包括:缩放.旋转.平移等.这些变换一般用于校正图像处理引起的空间失真,或者通过将图像配准到一个预定义的坐 ...

  3. 外星人图像和外星人太空船_卫星图像:来自太空的见解

    外星人图像和外星人太空船 By Christophe Restif & Avi Hoffman, Senior Software Engineers, Crisis Response 危机应对 ...

  4. python图像特征提取与匹配_[OpenCV-Python] OpenCV 中图像特征提取与描述 部分 V (二)...

    部分 V 图像特征提取与描述 34 角点检测的 FAST 算法 目标 • 理解 FAST 算法的基础 • 使用 OpenCV 中的 FAST 算法相关函数进行角点检测 原理 我们前面学习了几个特征检测 ...

  5. 基于几何学习图像的三维重建发展_立体图像的三维重建-对极几何

    本文中我们准备探索允许3D重建在实践中工作的核心概念.具体来说,我们将了解多视图或对极几何的基础知识. 让我们来看一下现代针孔相机的功能.当一幅图像被拍摄时,它的信息呈现在二维平面上,在二维平面上,每 ...

  6. 图像 异常检测算法_检测图像异常的算法

    图像 异常检测算法 Modern applications are generating enormous amounts of image data. And in the last years, ...

  7. 睡眠 应该用 a加权 c加权_在神经网络中提取知识:学习用较小的模型学得更好...

    在传统的机器学习中,为了获得最先进的(SOTA)性能,我们经常训练一系列整合模型来克服单个模型的弱点. 但是,要获得SOTA性能,通常需要使用具有数百万个参数的大型模型进行大量计算. SOTA模型(例 ...

  8. python音频 降噪_从视频中提取音频数据,然后应用傅里叶对音频降噪(python)...

    视频准备 QQ有热键 然后随便打开一个视频网站进行录屏 我选择B站 从视频中提取音频 需要安装包moviepy pip install moviepy 提取代码 from moviepy.editor ...

  9. access查询出生日期格式转换_从身份证中提取出生日期的3个方法和计算年龄和星座的方法...

    在我们日常的工作当中,经常会遇到通过身份证来获取出生年月日的需求,今天就给大家介绍三种可以从身份证中提取出生年月日的方法. 我们都知道身份证不同的区域是有不同的含义的,代表出生年月日的数字是第7位到第 ...

最新文章

  1. Read correction for non-uniform coverages 读校正非均匀覆盖
  2. .NET 面试题总结 (附有参考答案) 第1部分
  3. CISCO交换机配置命令大全
  4. 学习Python3:201701030
  5. Xshell 连接本地的Linux 系统,提示:Could not connect to '192.168.182.128' (port 23): Connection failed
  6. js获取cookie获取不到问题 vue获取cookie以及获取不到问题
  7. kotlin 查找id_Kotlin程序查找平行四边形的区域
  8. Client访问Tomcat简单流程(Struts2)
  9. java中去除文件名的后缀名_Java程序在最后一个点后去除其扩展名的文件名
  10. 软件人员kpi制定模板_软件科技公司绩效考核办法模板
  11. 使用Log4j进行日志操作
  12. Java反编译工具-luyten
  13. AndroidStudio选中代码后,光标自动变粗,自动变成ins模式的解决方法
  14. 无线射频识别技术开发与应用学习视频
  15. 怎么通过服务器性能计算tpmc,如何对服务器性能计算的公式参考(tpmc-tpcc)...pdf
  16. pda扫描枪屏幕_PDA扫描枪的介绍
  17. 有了这些组件和模板,天下没有难做的移动端驾驶舱
  18. mysql 分库备份_如何分表分库备份及批量恢复?MySQL
  19. 排序算法--选择篇(简单选择,树形选择,堆排序)
  20. c语言用while实现输出加法口诀表,「加法口诀」C语言编写一个加法口诀表 - 金橙教程网...

热门文章

  1. 邮箱POP3和SMTP的服务器地址
  2. 如何让java程序执行一段时间后停止
  3. 成都敏之澳电商:拼多多电商裂变玩法怎么做?
  4. 图像归一化概念和作用
  5. ZW20-12/630-25
  6. 为什么2019年这么拼命工作,却摆脱不了“穷”
  7. PYTHON 黑帽资料
  8. 回到无镜世界 ---- 自动变焦的电子眼镜
  9. 小发猫物联网平台搭建与应用模型
  10. idea 隐藏XML tag has empty body警告