error: expression must have pointer-to-object type
I am passing two 2D arrays, along with other variables, from the main() function to a function defined as:
Code:
float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage,float kernel[][5], int image[][15])
{
..........
..........
float imageConvolved;
float sum;
int kernelSize=5;
imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum;
return(imageConvolved);
}
The main function is defined as:
Code:
int main()
{
float gauss[5][5]={
{.........},
{.........},
..........
{.........}
};
int img[15][15]={
{.......},
{.......},
.........
{.......}
};
int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
float result;
result = conv2D(rowsK, colsK, rowsI, colsI, gauss, img);
return 0;
}
When I compile this code using CCStudio V3.3 I get an error " error: expression must have pointer-to-object type" and a warning "warning: variable "result" was set but never used". The error points to the function conv2D in the line:
imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum.
I have been struggling through the knowledge I am having in C programming and also through various posts online but none of the post has solved my problem. I tried using the GCC v4.7.3 compiler in UBUNTU but I am getting an error in the same line, the error says:
"error: subscripted value is neither array nor pointer nor vector"
Please, if someone has a link or explanations to the sources of these errors in my code kindly share it.
The complete code is:
Code:
#include<stdio.h>
#include<math.h>
float conv2D(int, int, int, int,float kernel[][5], int image[][15]);//Function Prototype definition
float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage,float kernel[][5], int image[][15])
{
int kernelSize;//This variable represents the size of the Gaussian kernel
int i; //variable which controls the rows of an image
int j; //variable which controls the columns of an image
int ii; //variable which controls the rows of the kernel
int jj;//variable which controls the columns of the kernel
float sum;//variable that holds the result of convolution for a particular pixel of an image
float imageConvolved;//Result of an image convolved by a Gaussian kernel
int imagePixel;
float kernelPixel;
kernelSize = colsKernel;/*Since we consider a square kernel, then rowsKernel=colsKernel, which implies that the size of the kernel (kernelSize) equals either of these two variables (that is, kernelSize=colsKernel=rowsKernel)*/
for (i = kernelSize/ 2; i < rowsImage - kernelSize / 2; i++) // perform iteration through the rows of an image
{
for (j = kernelSize / 2; j < colsImage - kernelSize / 2; j++) // perform iteration through the columns of an image
{
sum = 0; /*Initializing the accumulator. This variable will finally contain the convolution result for a particular pixel*/
for (ii = - kernelSize / 2; ii <= kernelSize / 2; ii++) // perform iteration through the rows of a kernel
{
for (jj = - kernelSize / 2; jj <= kernelSize / 2; jj++) //perform iteration through the columns of a kernel
{
imagePixel = image[i + ii][j +jj];
kernelPixel = kernel[ii + kernelSize / 2][jj + kernelSize / 2];
sum += imagePixel * kernelPixel;
}
}
imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum;
}
}
return(imageConvolved);// convolved image
}
int main()
{
float gauss[][5]={
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1}
};
int img[][15]={
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
float result;
result = conv2D(rowsK, colsK, rowsI, colsI, gauss, img);
return 0;
}