Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

segmentation fault

this code can work the image size 256x256, but not work on 4096x4096. I really confuse where get problem. the img.at<float>(i,j) should not access invalid memory address.

    void dustHighValue(Mat & img, float & sigma)
{
    int m = img.rows;
    int n = img.cols;
    copyMakeBorder(img, img,2, 2, 2, 2, BORDER_CONSTANT, Scalar::all(0));
    Mat tmp;
    Scalar meanValue, stdValue;
    for ( int i=2; i<img.rows-2; ++i)
        for( int j=2; j<img.cols-2; ++j)
        {
            tmp=img(Rect(i-1,j-1,3,3));
            meanStdDev(tmp, meanValue, stdValue);
            if( img.at<float>(i,j) > (sigma * stdValue[0] + meanValue[0]))      
                img.at<float>(i,j) = meanValue[0];
            }
        }

    img=img(Rect(2,2,n,m));

}

segmentation fault

this code can work the image size 256x256, but not work on 4096x4096. I really confuse where get problem. the img.at<float>(i,j) should not access invalid memory address.

    void dustHighValue(Mat & img, float & sigma)
{
    int m = img.rows;
    int n = img.cols;
    copyMakeBorder(img, img,2, 2, 2, 2, BORDER_CONSTANT, Scalar::all(0));
    Mat tmp;
    Scalar meanValue, stdValue;
    for ( int i=2; i<img.rows-2; ++i)
        for( int j=2; j<img.cols-2; ++j)
        {
            tmp=img(Rect(i-1,j-1,3,3));
            meanStdDev(tmp, meanValue, stdValue);
            if( img.at<float>(i,j) > (sigma * stdValue[0] + meanValue[0]))   
            {   
                img.at<float>(i,j) = meanValue[0];
            }
        }

    img=img(Rect(2,2,n,m));

}