0. 完整仓库 & 教程:
这一章节的完整代码在:Chapter 3. Affine Transformation and Smoothing
如果你喜欢这个系列的文章或者感觉对你有帮助,请给我的仓库一个⭐️。
1. 恒等变换
算法:
后续代码将以固定距离平移图像。
图像和结果对比(lena, circles):
结果分析:
通过在水平和竖直方向上移动图像中所有像素,从而达到平移的效果。移动后的黑色背景中不包含任何信息。这种方法速度快,不会导致任何像素值的改变。
代码实现(完整代码见顶部GitHub):
// set the background of the whole image to black(0):
for(int i = 0; i < outimage->Height; i++) {
for(int j = 0; j < outimage->Width; j++){
tempout[(outimage->Width)*i + j] = 0;
}
}
for(int i = 0; i < image->Height; i++) {
for(int j = 0; j < image->Width; j++){
// in case the coordinates + offsets beyond the boundary:
if((j+72) >= outimage->Width || (i+72) >= outimage->Height) continue;
else tempout[(outimage->Width)*(i+72) &