Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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;



}