arrays - C程序中的下标值既不是数组也不是指针也不是向量
问题描述
我有一个程序传递了一个大小为 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
该结构的每个位置都占总图像的四分之一,如下所示:
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
获取 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]
返回 中的第 iunsigned char
个.vertMask
。.vertMask[i][j]
正在要求一个unsigned char
没有意义的第 j 个元素。
推荐阅读
- c - 为什么 += 在 C 中花费这么多时间,以及如何提高性能?
- sockets - TCP客户端套接字与飞镖中的公共服务器IP连接
- c++ - 如何实现拆分功能以从一行中拆分单词?
- mysql - mysqldatabase 没有反映 Postman 中的 post 请求
- fullcalendar - 如何获取在 Fullcalendar v4 中双击背景事件的日期?
- javascript - 如何在邮件中获取图片?不和谐.js
- android - 如何使用 Kotlin Android 以编程方式获取 CPU 使用率?
- java - 在 Eclipse PDE 视图中打开文件
- r - SQL数据库发生变化时如何使renderUI发生变化?
- r - 循环嵌套列表的名称以创建一个数据框