[英]Subscripted value is neither array nor pointer nor vector in C program
I have a program that is passed a img_ptr of size 448x448, that is broken into 4 equal parts, each corner is applied filters, and now I am trying to reform the image back together using the 4 parts each stored in the subBlock subBlockList[];我有一个程序传递了一个大小为 448x448 的 img_ptr,它被分成 4 个相等的部分,每个角都应用了过滤器,现在我正在尝试使用每个存储在 subBlock subBlockList[] 中的 4 个部分将图像重新组合在一起;
I am being thrown this error: "error: subscripted value is neither array nor pointer nor vector" for each line: "subImageTempHolder[i][j] = subBlockList[x].vertMask[i][j]我被抛出这个错误:“错误:每行的下标值既不是数组也不是指针也不是向量”:“subImageTempHolder[i][j] = subBlockList[x].vertMask[i][j]
How can I correct this, I suspect it has something to do with pointers.我该如何纠正这个问题,我怀疑它与指针有关。
Sub-block structure子块结构
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
Each position of the structure holds a quarter of the total image as follows:该结构的每个 position 占总图像的四分之一,如下所示:
subBlockList[0].vertMask contains a unsigned char* 2d (array of size 224x224) NW vals subBlockList[0].vertMask 包含一个 unsigned char* 2d(大小为 224x224 的数组)NW vals
subBlockList[1].vertMask contains a unsigned char* 2d (array of size 224x224) NE vals subBlockList[1].vertMask 包含一个 unsigned char* 2d(大小为 224x224 的数组)NE vals
subBlockList[2].vertMask contains a unsigned char* 2d (array of size 224x224) SW vals subBlockList[2].vertMask 包含一个 unsigned char* 2d(大小为 224x224 的数组)SW vals
subBlockList[3].vertMask contains a unsigned char* 2d (array of size 224x224) SE Vals subBlockList[3].vertMask 包含一个 unsigned char* 2d(大小为 224x224 的数组)SE Vals
Function to take the 4 parts and put it back into one image_ptr (THE ONE THROWING ERRORS) 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;
}
It is being set like this:它是这样设置的:
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;
}
It's the vertMask[i][j]
in subBlockList[0].vertMask[i][j]
.它是
vertMask[i][j]
subBlockList[0].vertMask[i][j]
。
subBlockList[0]
returns a struct subBlock
. subBlockList[0]
返回一个struct subBlock
。 .vertMask
is an array of unsigned characters. .vertMask
是一个无符号字符数组。 .vertMask[i]
returns the ith unsigned char
in .vertMask
. .vertMask[i]
返回.vertMask
中的第 i 个unsigned char
。 .vertMask[i][j]
is asking for the jth element of an unsigned char
which doesn't make sense. .vertMask[i][j]
要求unsigned char
的第 j 个元素,这是没有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.