循环平铺以旋转矩阵
我正在尝试编写一个函数来使用循环平铺技术来旋转图像矩阵。但是,我在使其正常工作时遇到了一些问题。
编辑: 这是我更新后的代码,但仅当 n 是块大小的倍数时才有效。我将如何处理不同的矩阵大小?现在,我只使用方块,并且它对于这些方块非常有效。我将如何根据给定的数组的大小来更改它以使用矩形块。具体来说,如果给我一个 nxn 数组,我如何选择将其分割成的矩形块尺寸?
//Block size to tune
int block = 20;
int i1, j1, k1, i, j, k;
for(i1 = 0; i1 < n; i1 += block) {
for(j1 = 0; j1< n; j1 += block) {
for(i = i1; i < i1 + block; i++){
for(j = j1; j < j1 + block; j++){
dest[getInd(j, i, n)] = src[getInd(i, n - 1 - j, n)];
}
}
}
}
}
I'm trying to write a function to rotate an image matrix using the loop-tiling technique. However, I'm running into some issues with getting it to work properly.
EDIT:
Here's my updated code that works, but only when n is a multiple of the block size. How would I go about handling varying matrix sizes? Right now, I'm just using square blocks, and it works very well for those square blocks. How would I go about changing this to use rectangular blocks based on the size of the array I'm given. Specifically, if I'm given an n x n array, how do I choose the rectangular block dimensions to split it up into?
//Block size to tune
int block = 20;
int i1, j1, k1, i, j, k;
for(i1 = 0; i1 < n; i1 += block) {
for(j1 = 0; j1< n; j1 += block) {
for(i = i1; i < i1 + block; i++){
for(j = j1; j < j1 + block; j++){
dest[getInd(j, i, n)] = src[getInd(i, n - 1 - j, n)];
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
前两个 for 循环看起来错误:
可能应该是:
纠正后,您可能只需要在调试器中单步执行代码即可找出还需要修复的内容。
The first two for loops look wrong:
should probably be:
When that's corrected though you'll probably just need to step through the code in your debugger to work out what else needs fixing.