简体   繁体   English

迷宫图像处理,修剪空白

[英]Maze Image Manipulation, Trimming whitespace

迷宫

The problem i am having is the 2 pixel width pathways (the white parts). 我遇到的问题是2个像素宽度的通道(白色部分)。

In the top-left of the image (the darker black part) i have manually gone over the white parts that were 2 pixels in width/height; 在图像的左上角(较黑的黑色部分)中,我手动遍历了宽度/高度为2像素的白色部分;

there are two solutions (that i can think of). 有两种解决方案(我能想到)。

  1. to programmatically edit it so that pathways are 1x1; 以编程方式对其进行编辑,以使路径为1x1;
  2. to find a way of dealing with paths that are larger than 1x1. 找到一种处理大于1x1的路径的方法。

any suggestions, the maze-solving algorithm (tremaux) i have implemented works for 1x1 pathways but i am trying to adapt it to this larger maze. 任何建议,迷宫解决算法(tremaux)我已经实现了1x1路径的作品,但我正在尝试使其适应更大的迷宫。

preferably looking for a solution that is adaptable to a maze where the pathway widths can be any size as i have already written a tool where i can take an image and turn it into a monochrome int[][] array for maze solving. 最好寻找一种适合迷宫的解决方案,因为通道宽度可以是任何大小,因为我已经编写了一个工具,可以在其中拍摄图像并将其转换为单色int [] []数组以解决迷宫。

Just looking for hints/steps in the right direction since I'm not sure if I'm looking at this correctly or if I'm heading down the correct path (no pun intended). 只是在寻找正确方向的提示/步骤,因为我不确定自己是在正确看待还是在朝正确的方向走(没有双关语)。

Thanks 谢谢

So your grid is effectively repeating (1,2) = 3 pixels, 1 wall 2 paths. 因此,您的网格有效地重复了(1,2)= 3像素,1条墙2条路径。 Just remove every 3th row. 只需删除第3行。 Then remove every 3th column. 然后删除每第3列。

Think of the image as being divided up into 3x3 blocks, with the top-left corner being always wall, the top row and left column being the optional walls and the rest being path, like this: 可以将图像划分为3x3的块,左上角始终是墙,顶行和左列是可选墙,其余是路径,如下所示:

W w w
w P P
w P P

W = always wall
w = possible wall
P = always path

You need to convert each of those 3x3 blocks into a 2x2 block like this: 您需要将每个3x3块转换为2x2块,如下所示:

W w
w P

If you're trying to thin the paths just to make the maze easier to solve, then you don't need to bother. 如果您试图缩小路径只是为了使迷宫更容易解决,那么您就不必费心了。 Finding the shortest path through the maze with BFS is about as fast as any path thinning algorithm (except delete every Nth row and column), and will produce paths without any extra twists or turns. 使用BFS在迷宫中找到最短路径的速度几乎与任何路径细化算法一样快(除了删除第N行和第N列),并且将生成没有任何额外曲折的路径。

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

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