WPF:查找图像中的所有封闭区域(C#甚至VB) [英] WPF: Finding all closed areas in an image (C# or even VB)

查看:211
本文介绍了WPF:查找图像中的所有封闭区域(C#甚至VB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为有身体限制的儿童制作一本简单的着色书。
教师将能够在仅由封闭区域组成的程序中插入图片。
然后我需要分析图像并找到所有封闭区域(孩子能够着色的地方)。
我需要这样做,因为所有可以涂漆的区域会一个接一个地发光。
我想我可以通过填充来实现这一点,所以我需要在每个封闭区域内有一个点(X,Y坐标)。

I am working on a simple coloring book for children with physical limitations. Teachers will be able to insert a picture in the program composed of only closed areas. I then need to analyze the image and find all closed areas (the places the child will be able to color). I need to do this because all areas that can be painted will glow up one after the other. I think I can accomplish this with a floodfill so I need a point (X,Y coordinate) inside every closed area.

任何人都做过这样的事情?
一些提示或源代码可用吗?

Anyone ever did something like this? Some tips or source code available?

非常感谢!

推荐答案

我对WPF本身没有多少经验,但我可能会使用这样的算法:

I don't have much experience with WPF per se, but I would probably use an algorithm like this:

首先,我假设图像是严格的单色。也就是说,只有纯黑色(线条)和纯白色(可着色区域)像素。

First, I am assuming the image is strictly monochrome. That is, there are only pure black (line) and pure white (colourable area) pixels.


  1. 将图像转换为真彩色

  2. 检查左上角的像素。

  3. 如果此像素为白色,请使用新的唯一颜色进行填充

  4. 向右移动一个像素(如果超出范围,向下移动一个,一直向左移动)

  5. 转到3

  1. Convert the image to true-colour
  2. Examine the Top-Left pixel.
  3. If this pixel is white, do a flood fill with a new unique colour
  4. Move one-pixel to the right (if out of bounds, move down one and all the way to the left)
  5. Go to 3

现在,图像中的每个区域都有不同的颜色。

Now, every area in the image has a different colour.

这篇关于WPF:查找图像中的所有封闭区域(C#甚至VB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆