简体   繁体   中英

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[];

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]

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:

subBlockList[0].vertMask contains a unsigned char* 2d (array of size 224x224) NW vals

subBlockList[1].vertMask contains a unsigned char* 2d (array of size 224x224) NE vals

subBlockList[2].vertMask contains a unsigned char* 2d (array of size 224x224) SW vals

subBlockList[3].vertMask contains a unsigned char* 2d (array of size 224x224) SE Vals

Function to take the 4 parts and put it back into one 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] .

subBlockList[0] returns a struct subBlock . .vertMask is an array of unsigned characters. .vertMask[i] returns the ith unsigned char in .vertMask . .vertMask[i][j] is asking for the jth element of an unsigned char which doesn't make sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM