简体   繁体   English

如何圈出/突出显示/矩形化图像的某些区域?

[英]How to circle/highlight/rectangle certain regions of an image?

I have a grayscale image with various regions that need to be circled in a WPF C# program. 我有一个需要在WPF C#程序中圈出的带有各个区域的灰度图像。 An example of such an image would be this: 这样的图像的示例如下:

在此处输入图片说明

The regions I'm looking to circle are the white ones, in this manner: 我要圈出的区域是白色的,以这种方式:

在此处输入图片说明

So far what I'm trying to do is make an array of bytes, consisting of the intensity of each pixel (0 being black and white being 4000 and upwards.) I then pass each byte through a threshold test to see if its a pixel with part of the region in it or not (for example, if bytes have lengths beyond 3500, consider it as part of the region, else it's not.) 到目前为止,我要做的是创建一个字节数组,该数组由每个像素的强度组成(0为黑白,4000为以上)。然后,我将每个字节通过阈值测试以查看其像素是否是否具有该区域的一部分(例如,如果字节的长度超过3500,则将其视为该区域的一部分,否则就没有。)

I am stumped as what to do after this. 在这之后我该做什么。 So far one of my ideas is to find the first pixel of a region within a row, then find the last pixel of a region of row on the bottom of a region (so top left and bottom right.) Then I'd find the distance in between both pixels and use that to get the center point (from which I could use to get the coordinates needed to draw circle.) Issues with this method I think would be noise that would either cause many circles to appear on the image or misinformed circles. 到目前为止,我的想法之一是找到行中某个区域的第一个像素,然后找到该区域底部(即左上角和右下角)的行区域的最后一个像素。两个像素之间的距离,并使用该距离来获取中心点(从中可以获取绘制圆所需的坐标。)这种方法的问题是噪声会导致很多圆出现在图像上或误会的圈子。 I guess I could use thresholds to eliminate small circles though. 我想我可以使用阈值来消除小圆圈。

These images are actually frames of a video (information is obtained as a byte array and then written to a WriteableBitmap) , so I don't know if too many manipulations with the data would lag the footage. 这些图像实际上是视频的帧(信息以字节数组的形式获取,然后写入到WriteableBitmap中),因此我不知道对数据进行过多的操作是否会滞后于素材。 I'm also a newbie with C#, bytes and CS in general, but this project is something I took up during my winter break to learn how to program. 我也是一个使用C#,字节和CS的新手,但是这个项目是我在寒假期间学习的程序。 Any answers or resources would be much appreciated, especially in pseudocode or C#. 任何答案或资源将不胜感激,尤其是在伪代码或C#中。

From what you said it sounds like a Computer Vision problem to me. 从你所说的对我来说,这听起来像是计算机视觉的问题。 I used to develop couple of CV problem applications based on C#. 我曾经开发过一些基于C#的CV问题应用程序。 Basic idea is using GDI+ to marshal Bitmap.Lockbits() object into Byte[] and do the manipulation, or simply use Bitmap.SetPixel() Bitmap.GetPixel() , but they are tolerably slower. 基本思想是使用GDI +将Bitmap.Lockbits()对象编组为Byte[]并进行操作,或者简单地使用Bitmap.SetPixel() Bitmap.GetPixel() ,但是它们的速度慢得多。

A great choice is to use EmguCV . 一个很好的选择是使用EmguCV A OpenCV wrapper for .NET 2.0 and up. .NET 2.0及更高版本的OpenCV包装器。 Thus making writing C# to solve CV problem much eaiser. 从而使编写C#来解决CV问题变得更加轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM