【发布时间】:2018-10-25 22:52:58
【问题描述】:
它的参数需要三个 600x400 RGB 数组来创建像素颜色。我已经尝试集思广益了这么多小时,但我对这样做的方法感到非常困惑。这是我尝试过的一个想法,但我不知所措并被难住了:
将每个 RGB 数组(R[][]、G[][] 和 B[][] 分别复制到它们各自的临时数组中。将临时数组拆分为 4x4。每个元素都将包含其自己的二维数组,其中包含原始图像块。然后使用随机库,我可以将元素分配到 4x4 中的新位置。我不知道如何在不制作 42 个数组的情况下做到这一点(4x4 中每种颜色 16 个数组,但 R、G 和 B 有 42 个数组)。我将不胜感激任何建议或这是我目前拥有的代码,但我暂停(或可能放弃)工作:
void Shuffle(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]){
// Initialize 150x100 inner shuffle arrays. These arrays are chunks of the original image
int shuffArrR[150][100] = {0};
int shuffArrG[150][100] = {0};
int shuffArrB[150][100] = {0};
int row = 0, col = 0;
/*
BOUNDARY INFO FOR 4x4 ARRAY:
C1: C2: C3: C4: hBound# (row):
--------------------> 1
R1: | | | | |
--------------------> 2
R2: | | | | |
--------------------> 3
R3: | | | | |
--------------------> 4
R4: | | | | |
--------------------> 5
| | | | |
v v v v v
vBound# (col): 1 2 3 4 5
vBound: hBound:
#: col: #: row:
1 0 1 0
2 150 2 100
3 300 3 200
4 450 4 300
5 600 5 400
*/
// Define boundaries
int const vBound1 = 0, vBound2 = 150, vBound3 = 300, vBound4 = 450;
int const hBound1 = 0, hBound2 = 100, hBound3 = 200, hBound4 = 300;
for(row; row < HEIGHT; row++){
for(col; col < WIDTH; col++){
// Copy RGB arrays to shuffle arrays
shuffArrR[col][row] = R[col][row];
shuffArrG[col][row] = G[col][row];
shuffArrB[col][row] = B[col][row];
// Define 16 blocks in 4x4 array ------------------
// If in R1
if(row >= hBound1 && row <= hBound2){
// And in C1
if(col >= vBound1 && col <= vBound2){
// ** I stopped here after I realized how many arrays I'd have to make to account for every element in the 4x4 **
}
}
}
}
}
【问题讨论】:
-
为原始数组中的每个块分配一个索引(0,15)。使用这些索引创建一个数组
array[16] = {0,1,2,...,14,15};Fisher-Yates shuffle 数组。对于shuffled数组中的entry,index为输出图像中的block,value为block在原图中的index。 -
如何为 16 个 2D 块中的每一个分配索引?
-
您确定没有将其转换为更难处理的格式吗?通常像素是压缩的 RGB 或 GRB。
-
我已将我之前的评论扩展为一个答案。
标签: c arrays multidimensional-array chunks