[英]Subscripted value is neither array nor pointer nor vector in C program
我有一個程序傳遞了一個大小為 448x448 的 img_ptr,它被分成 4 個相等的部分,每個角都應用了過濾器,現在我正在嘗試使用每個存儲在 subBlock subBlockList[] 中的 4 個部分將圖像重新組合在一起;
我被拋出這個錯誤:“錯誤:每行的下標值既不是數組也不是指針也不是向量”:“subImageTempHolder[i][j] = subBlockList[x].vertMask[i][j]
我該如何糾正這個問題,我懷疑它與指針有關。
子塊結構
struct subBlock {
unsigned char *horizMask;
unsigned char *vertMask;
unsigned char *combMask;
float localMean;
float localSD;
float localMedian;
};
static struct subBlock subBlockList[4];
#define BLOCK_ROW 224 //sub-block row
#define BLOCK_COL 224 //sub-block col
#define imageSize 448
該結構的每個 position 占總圖像的四分之一,如下所示:
subBlockList[0].vertMask 包含一個 unsigned char* 2d(大小為 224x224 的數組)NW vals
subBlockList[1].vertMask 包含一個 unsigned char* 2d(大小為 224x224 的數組)NE vals
subBlockList[2].vertMask 包含一個 unsigned char* 2d(大小為 224x224 的數組)SW vals
subBlockList[3].vertMask 包含一個 unsigned char* 2d(大小為 224x224 的數組)SE Vals
Function 把 4 個部分放回一個 image_ptr (THE ONE THROWING ERRORS)
image_ptr buildImage(){
image_ptr retVal; // contains the image pointer to return
unsigned char subImageTempHolder[imageSize][imageSize];
int subBlockSize = 224;
//NW Corner
for (int i=0; i< subBlockSize; i++) { // 0<224
for (int j=0; j< subBlockSize; j++){ // 0<224
subImageTempHolder[i][j] = subBlockList[0].vertMask[i][j];
}
}
//NE Corner
for (int i=0; i< subBlockSize; i++) { //0 <224
for (int j=subBlockSize; j< imageSize; j++){ //224 < 448
subImageTempHolder[i][j] = subBlockList[1].vertMask[i][j];
}
}
//SW Corner
for (int i=subBlockSize; i< imageSize; i++) { //224 <448
for (int j=0; j< subBlockSize; j++){ //0 < 224
subImageTempHolder[i][j] = subBlockList[2].vertMask[i][j];
}
}
//SE Corner
for (int i=subBlockSize; i< imageSize; i++) { //224 < 448
for (int j=subBlockSize; j< imageSize; j++){ //224 <448
subImageTempHolder[i][j] = subBlockList[3].vertMask[i][j];
}
}
retVal = (image_ptr) subImageTempHolder;
return retVal;
}
它是這樣設置的:
subBlockList[blockPos].vertMask = verticalMask(block);
//I didnt include the function using line above ^ but you should get the idea.
unsigned char* verticalMask(unsigned char paramBlock[BLOCK_ROW][BLOCK_COL]) {
unsigned char retVal[BLOCK_ROW][BLOCK_COL]; //return value
double pixelVal;
double min = DBL_MAX;
double max = -DBL_MAX;
//3x3 Gy Sobel Mask
int Gy[3][3];
Gy[0][0] = 1; Gy[0][1] = 2; Gy[0][2] = 1;
Gy[1][0] = 0; Gy[1][1] = 0; Gy[1][2] = 0;
Gy[2][0] = -1; Gy[2][1] = -2; Gy[2][2] = -1;
//filtering
for (int y = 0; y<= BLOCK_COL-1; y++) {
for (int x=0; x <= BLOCK_ROW-1; x++) {
pixelVal = 0.0;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
pixelVal += Gy[i+1][j+1] * paramBlock[y+i][x+j];
}
}
if (pixelVal < min) {
min = pixelVal;
}
if (pixelVal > min) {
max = pixelVal;
}
}
}
if((int)(max - min) == 0) {
printf("Error nothing exists");
}
//generate image
for (int y = 1; y < BLOCK_COL - 1; y++) {
for (int x = 1; x < BLOCK_ROW - 1; x++) {
pixelVal = 0.0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
pixelVal += Gy[j + 1][i + 1] * paramBlock[y + j][x + i];
}
}
pixelVal = max * (pixelVal - min) / (max - min); //MAX_BRIGHTNESS
retVal[y][x] = (unsigned char)pixelVal;
}
}
return retVal;
}
它是vertMask[i][j]
subBlockList[0].vertMask[i][j]
。
subBlockList[0]
返回一個struct subBlock
。 .vertMask
是一個無符號字符數組。 .vertMask[i]
返回.vertMask
中的第 i 個unsigned char
。 .vertMask[i][j]
要求unsigned char
的第 j 個元素,這是沒有意義的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.