Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

void filter(Mat src, Mat dst, int kernel, double P)
{
    Mat temp = src.clone();
    Mat output;
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
    int sum = 0;
    for(int row = 0; row < temp.rows; row++)
    {
        for(int col = 0 ; col < temp.cols; col++)
        {
            for(int i = -floor(kernel/2); i <= floor(kernel/2) ; i++)
            {
                for(int j = -floor(kernel/2) ; j <= floor(kernel/2); j++)
                {

                    sum += temp.at<int>(row+i,col+j);
                }
            }
            output.at<uchar>(row,col) = pow(sum,P+1)/pow(sum,P);
            sum = 0;
        }
    }

    dst = output;
}

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

 void filter(Mat src, Mat dst, int kernel, double P)
{
    Mat temp = src.clone();
    Mat output;
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
    int sum float num = 0;
    float den = 0;
    for(int row = 0; kernel/2; row < temp.rows; (temp.rows - kernel)/2; row++)
    {
        for(int col = 0 ; kernel/2; col < temp.cols; (temp.cols - kernel)/2; col++)
        {
            for(int i = -floor(kernel/2); -(kernel/2); i <= floor(kernel/2) (kernel/2) ; i++)
            {
                for(int j = -floor(kernel/2) -(kernel/2) ; j <= floor(kernel/2); (kernel/2); j++)
                {

                    sum                     den += temp.at<int>(row+i,col+j);
(temp.at<uchar>(row+i,col+j),P);
                    num += (temp.at<uchar>(row+i,col+j),P+1);
                }
            }
            output.at<uchar>(row,col) = pow(sum,P+1)/pow(sum,P);
            sum 
            dst.at<uchar>(row,col) = num/den;
            cout << num/den << endl;
            num = 0;
            den = 0;
        }
    }

    dst = output;
}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

  void filter(Mat src, Mat dst, int kernel, double P)
{
    Mat temp = src.clone();
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
    float num = 0;
    float den = 0;
    for(int row = kernel/2; row < (temp.rows - kernel)/2; row++)
    {
        for(int col = kernel/2; col < (temp.cols - kernel)/2; col++)
        {
            for(int i = -(kernel/2); i <= (kernel/2) ; i++)
            {
                for(int j = -(kernel/2) ; j <= (kernel/2); j++)
                {
                    den += (temp.at<uchar>(row+i,col+j),P);
(temp.at<float>(row+i,col+j),P);
                    num += (temp.at<uchar>(row+i,col+j),P+1);
(temp.at<float>(row+i,col+j),P+1);
                }
            }

            dst.at<uchar>(row,col) dst.at<float>(row,col) = num/den;
            cout << num/den << endl;
            num = 0;
            den = 0;
        }
    }

}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

  void filter(Mat src, Mat dst, int kernel, double P)
{
    { Mat temp = src.clone();
   copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
   float num = 0;
   float den = 0;
   for(int row = kernel/2; row < (temp.rows temp.rows - kernel)/2; kernel/2-1; row++)
   {
     for(int col = kernel/2; col < (temp.cols temp.cols - kernel)/2; kernel/2-1; col++)
     {
         for(int i = -(kernel/2); i <= (kernel/2) ; i++)
         {
             for(int j = -(kernel/2) ; j <= (kernel/2); j++)
             {
                 den += (temp.at<float>(row+i,col+j),P);
                 num += (temp.at<float>(row+i,col+j),P+1);
             }
         }

            dst.at<float>(row,col) = num/den;
            cout //cout << num/den << endl;
        dst.at<float>(row,col) = num/den;
        num = 0;
         den = 0;
     }
    }

}

}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

  void filter(Mat src, Mat dst, int kernel, double P)
{ Mat temp = src.clone();
  copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
  float num = 0;
  float den = 0;
  for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
  {
    for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
    {
        for(int i = -(kernel/2); i <= (kernel/2) ; i++)
        {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += (temp.at<float>(row+i,col+j),P);
                num += (temp.at<float>(row+i,col+j),P+1);
            }
        }

        //cout << num/den << endl;
        dst.at<float>(row,col) = num/den;
        num = 0;
        den = 0;
    }
}

}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

  void filter(Mat src, Mat dst, int kernel, double P)
{ Mat temp = src.clone();
  copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
  float num = 0;
  float den = 0;
  for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
  {
    for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
    {
        for(int i = -(kernel/2); i <= (kernel/2) ; i++)
        {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += (temp.at<float>(row+i,col+j),P);
                num += (temp.at<float>(row+i,col+j),P+1);
            }
        }

        //cout << num/den << endl;
        dst.at<float>(row,col) = num/den;
        num = 0;
        den = 0;
    }
}

}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

  void filter(Mat src, Mat dst, int kernel, double P)
 {   
     cout << "got it" << endl;
    Mat temp = src.clone();
    dst = src.clone();
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
  float num = 0;
  float den = 0;
   for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
   {
     for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
     {

        double den=0,num=0;
          for(int i = -(kernel/2); i <= (kernel/2) ; i++)
         {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += (temp.at<float>(row+i,col+j),P);
pow(temp.at<uchar>(row+i,col+j),P);
                num += (temp.at<float>(row+i,col+j),P+1);
pow(temp.at<uchar>(row+i,col+j),P+1);
                cout <<"Row: "<<row+i << " " << "col: "<< col + j << endl;
            }
         }

        //cout << num/den << endl;
        dst.at<float>(row,col) = num/den;
        num = 0;
        den = 0;
dst.at<uchar>(row,col) = uchar(num/den);
      }
    }
    cout << "done " << endl;
    dst.convertTo(dst,CV_8U);
}

}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

 void filter(Mat src, Mat dst, int kernel, double P)
    {   
   {
  cout << "got it" << endl;
    Mat temp = src.clone();
    dst Mat dst111 = src.clone();
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));

    for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
    {
        for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
        {

        double den=0,num=0;
          for(int i = -(kernel/2); i <= (kernel/2) ; i++)
          {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += pow(temp.at<uchar>(row+i,col+j),P);
pow(temp.at<double>(row+i,col+j),P);
                num += pow(temp.at<uchar>(row+i,col+j),P+1);
                cout pow(temp.at<double>(row+i,col+j),P+1);
                //cout <<"Row: "<<row+i << " " << "col: "<< col + j << endl;
            }
          }

        //cout << num/den << endl;
        dst.at<uchar>(row,col) = uchar(num/den);
double value = num/den;
        dst.at<double>(row,col) = (uchar)value;
      }
    }
    cout << "done " << endl;
    dst.convertTo(dst,CV_8U);
dst111.convertTo(dst,CV_8U);
    imshow("hey",dst);
    waitKey(0);
}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

void filter(Mat src, Mat dst, int kernel, double P)
{
  cout << "got it" << endl;
    Mat temp = src.clone();
    Mat dst111 = src.clone();
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));

    for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
    {
        for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
        {

        double den=0,num=0;
          for(int i = -(kernel/2); i <= (kernel/2) ; i++)
          {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += pow(temp.at<double>(row+i,col+j),P);
                num += pow(temp.at<double>(row+i,col+j),P+1);
                //cout <<"Row: "<<row+i << " " << "col: "<< col + j << endl;
            }
          }

        //cout << num/den << endl;
        double value = num/den;
        dst.at<double>(row,col) = (uchar)value;
value;
      }
    }
    cout << "done " << endl;
    dst111.convertTo(dst,CV_8U);
    imshow("hey",dst);
    waitKey(0);
waitKey();
}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

void filter(Mat src, Mat dst, int kernel, double P)
{
  cout << "got it" << endl;
    Mat temp = src.clone();
    Mat dst111 = src.clone();
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));

    for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
    {
        for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
        {

        double den=0,num=0;
          for(int i = -(kernel/2); i <= (kernel/2) ; i++)
          {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += pow(temp.at<double>(row+i,col+j),P);
                num += pow(temp.at<double>(row+i,col+j),P+1);
                //cout <<"Row: "<<row+i << " " << "col: "<< col + j << endl;
            }
          }

        //cout << num/den << endl;
        double value = num/den;
        dst.at<double>(row,col) = value;
      }
    }
    cout << "done " << endl;
    dst111.convertTo(dst,CV_8U);
    imshow("hey",dst);
dst.convertTo(dst,CV_8U);
    imshow("hey",dst111);
    waitKey();
}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description

Applying filter keeps crashing?

I am bit unsure why this keep crashing.. Qt isn't providing me with an proper error message, but just states that it crashed.. I seems to me that the program crashes when I try to add the pixel values together.

here is the filter.

void filter(Mat src, Mat dst, int kernel, double P)
{
  cout << "got it" << endl;
    Mat temp = src.clone();
    Mat dst111 = src.clone();
    copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));

    for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
    {
        for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
        {

        double den=0,num=0;
          for(int i = -(kernel/2); i <= (kernel/2) ; i++)
          {
            for(int j = -(kernel/2) ; j <= (kernel/2); j++)
            {
                den += pow(temp.at<double>(row+i,col+j),P);
                num += pow(temp.at<double>(row+i,col+j),P+1);
                //cout <<"Row: "<<row+i << " " << "col: "<< col + j << endl;
            }
          }

        //cout << num/den << endl;
        double value = num/den;
        dst.at<double>(row,col) = value;
      }
    }
    cout << "done " << endl;
    dst.convertTo(dst,CV_8U);
    imshow("hey",dst111);
    waitKey();
}

--UPDATE-- I changed some few things, based on the comments. It seems now that nothings happens to the image, when the filter is applied to it. The output image is the same image, with some lines on it..

ex. image description

---Update--- Using the code snippet posted below things the output image becomes this

image description