【问题标题】:Binary image shearing algorithm二值图像剪切算法
【发布时间】:2011-09-01 01:53:44
【问题描述】:

我正在寻找一种简单的剪切算法。要剪切的图像是二进制的(0 - 背景像素,1 - 前景像素),由 2D 数组表示。它将用于手写数字倾斜校正,因此只需在 x 轴上进行剪切。

我找到了一些数学解释,但不确定如何正确实现。

谢谢!

【问题讨论】:

  • 您的问题如何与语言无关并且需要实施细节?
  • @MrE 我认为他的意思是他在将数学公式转换为基于代码的算法时遇到了麻烦。在这种情况下,提供伪代码可能会有所帮助。
  • @Diego 是的,我就是这个意思。

标签: algorithm language-agnostic image-processing


【解决方案1】:

只需从底行开始循环遍历行,并跟踪沿 x 轴的当前像素偏移(作为浮点数或定点数)。在每一行之后,您将移位增加所需的恒定斜率。出于绘图目的,您在每一行取对应像素位移的最接近的整数。

在伪代码中是:

slope = 0.2; // one pixel shift every five rows
shift = 0.0; // current pixelshift along x-axis
for (row = rows-1; row>=0; row--) {
  integershift = round(shift)  // round to nearest integer
  for (column = columns-1; column>=0; column--) {
    sourcecolumn = column + integershift;  // get the pixel from this column
    if (sourcecolumn < columns)
      outputImage[row][column] = inputImage[row][sourcecolumn];
    else  // draw black if we're outside the inputImage
      outputImage[row][column] = 0;
  }
  shift += slope;
}

这基本上是Bresenham line drawing algorithm,所以你应该找到大量的实现细节。

【讨论】:

    猜你喜欢
    • 2014-08-08
    • 2018-04-10
    • 1970-01-01
    • 2023-03-03
    • 2012-03-14
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多