Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

fog removal C++ code

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;

}