Ask Your Question
-1

fog removal C++ code

asked 2017-07-13 01:43:12 -0600

Khani gravatar image

Hello Dear All,

I am trying to run this simple fog removal which takes an input RGB image and removes fog from it. When i run the following code, it gives me the following exception. Exception at memory location 0x000000B8FD6FE6A0. I think the possible reasons might be static casting in the transmission map and original image recovery part. Any help would be deeply appreciated.

int main(int, char** argv)
{
Mat input_image;
double patchsize = 3;
double m_AtmosLight = 255.0;
double _t = 255.0;
double w = 1;
Mat m_DarkChannelImage;
Mat m_RecoveredImage;

const char* source_window = "Source image";
const char* dark_channel = "Dark Channel";

namedWindow(source_window, WINDOW_AUTOSIZE);
imshow(source_window, input_image);
input_image.convertTo(input_image, CV_64FC3);

// Dark Channel Creation
vector<Mat> planes(3);
split(input_image, planes);

m_DarkChannelImage=min(planes[2], min(planes[1], planes[0]));
namedWindow(dark_channel, WINDOW_AUTOSIZE);
imshow(dark_channel, m_DarkChannelImage);

// Original Image Recovery part

 for (int i = 0; i < input_image.rows; i++)
{
    for (int j = 0; j < input_image.cols; j++)
    {

        double t = std::max(1 - (w*m_DarkChannelImage.at<uchar>(i, j) / m_AtmosLight), _t);

        m_RecoveredImage.at<Vec3b>(i, j)[0] = static_cast<uchar>(std::min(((input_image.at<Vec3b>(i, j)[0] - m_AtmosLight) / t + m_AtmosLight), 255.0));
        m_RecoveredImage.at<Vec3b>(i, j)[1] = static_cast<uchar>(std::min(((input_image.at<Vec3b>(i, j)[1] - m_AtmosLight) / t + m_AtmosLight), 255.0));
        m_RecoveredImage.at<Vec3b>(i, j)[2] = static_cast<uchar>(std::min(((input_image.at<Vec3b>(i, j)[2] - m_AtmosLight) / t + m_AtmosLight), 255.0));
    }
}

waitKey(0);
system("pause");
return 0;

}

edit retag flag offensive close merge delete

Comments

1

you never initialize m_RecoveredImage ? (at least i don't see anything)

also: inputImage ?

berak gravatar imageberak ( 2017-07-13 01:54:05 -0600 )edit
2

It always helps both you and us if you write which line causes this exception.

KjMag gravatar imageKjMag ( 2017-07-13 02:43:36 -0600 )edit

The following line causes the exception double t = std::max(1 - (w*m_DarkChannelImage.at<uchar>(i, j) / m_AtmosLight), _t); If i change <uchar> to <unsigned int=""> then the exception is thrown my next line which is: m_RecoveredImage.at<vec3b>(i, j)[0] = static_cast<uchar>(std::min(((input_image.at<vec3b>(i, j)[0] - m_AtmosLight) / t + m_AtmosLight), 255.0));

Khani gravatar imageKhani ( 2017-07-13 07:23:55 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2017-07-13 10:35:06 -0600

KjMag gravatar image

The problem is that m_DarkChannelImage is of type CV_64F, because you assign to it one of the planes, which holds the results of splitting the input_image, which is CV_64FC3.

If you want to access its pixels, you have to call at<double>(), whereas you call at<uchar>(), which is only suitable for CV_8UC type.

edit flag offensive delete link more

Comments

The code worked thanks alot for your suggestion

Khani gravatar imageKhani ( 2017-07-14 01:13:42 -0600 )edit

No problem. You may upvote and accept the answer (the 'tick' sign on the left right under voting buttons) if you are satisfied with this answer.

KjMag gravatar imageKjMag ( 2017-07-14 02:32:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-13 01:43:12 -0600

Seen: 863 times

Last updated: Jul 13 '17