将二维图像存储在平面阵列或阵列阵列中更好吗?

问题描述 投票:0回答:0

我有两个选择。

  1. 接收和处理平面阵列中的像素数据。

如果我选择它,我必须使用单指针。 我必须在每个重复的像素数据处理中使用此代码。

int getIndex(int row, int col){
    return row*(Image_Width) + col;
}

for (int i ...){
    for (int j ...){
        R[getIndex(i,j)]
        G[getIndex(i,j)]
        B[getIndex(i,j)]
    }
}
  1. 接收和处理双数组中的像素数据。

如果我选择它,我必须使用指针到指针。我不需要使用

getIndex()
.

我想知道这两个方案的优缺点,哪个是有效率的。

这是一个使用单数组和双数组对每个像素数据进行常量乘法的例子

B = (unsigned char *)malloc(ImgSize);
G = (unsigned char *)malloc(ImgSize);
R = (unsigned char *)malloc(ImgSize);
for (int i = 0; i < ImgSize; i++){
    B[i] = fgetc(f);
    G[i] = fgetc(f);
    R[i] = fgetc(f);
}
for (int i = 0; i < Height; i++){
    for(int j = 0; j < Width; j++){
        B[getIndex(i,j)] = int(B[getIndex(i,j)]*num);
        G[getIndex(i,j)] = int(G[getIndex(i,j)]*num);
        R[getIndex(i,j)] = int(R[getIndex(i,j)]*num);
    }
}
dB = (unsigned char **)malloc(hInfo.biHeight * sizeof(unsigned char *));
dG = (unsigned char **)malloc(hInfo.biHeight * sizeof(unsigned char *));
dR = (unsigned char **)malloc(hInfo.biHeight * sizeof(unsigned char *));
for (int i = 0 ; i < hInfo.biHeight; i++){
    *(dB+i) = (unsigned char *)malloc(hInfo.biWidth * sizeof(unsigned char));
    *(dG+i) = (unsigned char *)malloc(hInfo.biWidth * sizeof(unsigned char));
    *(dR+i) = (unsigned char *)malloc(hInfo.biWidth * sizeof(unsigned char));
}
for (int i = 0; i < hInfo.biHeight; i++){
    for (int j = 0; j < hInfo.biWidth; j++){
        dB[i][j] = fgetc(f);
        dG[i][j] = fgetc(f);
        dR[i][j] = fgetc(f);
    }
}
for (int i = 0; i < Height; i++){
    for(int j = 0; j < Width; j++){
        dB[i][j] = int(dB[i][j]*num);
        dG[i][j] = int(dG[i][j]*num);
        dR[i][j] = int(dR[i][j]*num);
    }
}
arrays image-processing indexing processing-efficiency pointer-to-pointer
© www.soinside.com 2019 - 2024. All rights reserved.