Algorithm 二值图像剪切算法
我正在寻找一个简单的剪切算法。要剪切的图像是由2D数组表示的二进制图像(0-背景像素,1-前景像素)。它将用于手写数字倾斜校正,因此剪切只需在x轴上进行 我找到了一些数学解释,但不知道如何正确地实现它Algorithm 二值图像剪切算法,algorithm,language-agnostic,image-processing,Algorithm,Language Agnostic,Image Processing,我正在寻找一个简单的剪切算法。要剪切的图像是由2D数组表示的二进制图像(0-背景像素,1-前景像素)。它将用于手写数字倾斜校正,因此剪切只需在x轴上进行 我找到了一些数学解释,但不知道如何正确地实现它 谢谢 只需在行中循环,从最下面的行开始,跟踪当前像素沿x轴的移动(作为浮点或定点数字)。每行之后,按所需的恒定坡度增加偏移量。出于绘图目的,可以在每一行上取对应的pixelshift的最近整数 在伪代码中,这将是: slope = 0.2; // one pixel shift every fiv
谢谢 只需在行中循环,从最下面的行开始,跟踪当前像素沿x轴的移动(作为浮点或定点数字)。每行之后,按所需的恒定坡度增加偏移量。出于绘图目的,可以在每一行上取对应的pixelshift的最近整数 在伪代码中,这将是:
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;
}
slope=0.2;//每五行移动一个像素
shift=0.0;//当前像素沿x轴移动
对于(行=行-1;行>=0;行--){
integershift=round(shift)//四舍五入到最接近的整数
对于(列=列-1;列>=0;列--){
sourcecolumn=column+integershift;//从该列获取像素
if(sourcecolumn
这基本上是一个问题,因此你应该找到大量的实现细节。你的问题怎么可能是语言无关的,需要实现细节?@MrE我想他的意思是,他在从数学公式转换为基于代码的算法时遇到了困难。在这种情况下,提供伪代码可能会有帮助。@Diego是的,这就是我的意思。