Segmentation fault(core dumped) in log transformation
I am a beginner of digital image processing. And I want to conduct log transformation for each pixel of the input picture. But, I encountered a segmentation fault(core dumped error). I don't know where does the error exists. Can you help me? For some pictures, like lena.jpg, the error didn't happen, while it happens when I input a picture of a hand-writing on a paper. Here is my code:
Mat Log_Trans(Mat);
int main(int argc,char**argv)
{
Mat m1=imread(argv[1]);
if ( m1.empty() )
{
cout<< "Could not open file" <<endl;
return ( 1 );
}
imshow("Input",m1) ;
m1=Log_Trans(m1);
imshow("Log",m1);
waitKey(0);
return 1;
}
Mat Log_Trans(Mat input)
{
Mat output(input.cols+1,input.rows+1,CV_8UC3,Scalar(0,0,0));
int i,j;
for(i=0;i<=input.rows;i++)
{
for(j=0;j<=input.cols;j++)
{
output.at<Vec3b>(j,i)[0]=(int)log(1+input.at<Vec3b>(j,i)[0]);
output.at<Vec3b>(j,i)[1]=(int)log(1+input.at<Vec3b>(j,i)[1]);
output.at<Vec3b>(j,i)[2]=(int)log(1+input.at<Vec3b>(j,i)[2]);
}
}
normalize(output,output,0,255,NORM_MINMAX);
return output;
}
It is not Mat output(input.cols+1,input.rows+1,CV_8UC3,Scalar(0,0,0)); but Mat output(input.rows+1,input.cols+1,CV_8UC3,Scalar(0,0,0));
I modified my code as you said, and it works. But there is something I still can not understand: Isn't the rows denoting the number of pixels in a column or the number of rows the Matrix has? And is the First parameter of a Mat class when initializing it represents the numbers of columns?
Mat(numRows, numCols, type)
-- is that, what you meant ? rows counts "vertically", or in y direction, cols counts "horizontal", or in x direction