Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem with calculations on Mat-Array with Windows 10

I have a very mysterious problem with calculations on Mat-Arrays under Windows 10. Following code produce a black area on the output image under Windows 10. I don't know where it come from. When I run this code under windows 7 the image is ok, and no black area is to see. The effect has obscure dependency of the parameters MaxIgnore and MinIgnore and the input Image. What is wrong with my code, or is it a problem of the OpenCV Library itself?

cv::Mat Image;
Image = cv::imread("Input.png", cv::ImreadModes::IMREAD_ANYCOLOR | cv::ImreadModes::IMREAD_ANYDEPTH);

//scale 16bit gray scale image up to 0-1
int type = Image.type();
Image.convertTo(Image, CV_32F, 1.0 / 65536.0, 0.0);

//Calculations for brightness adjustment
double MinIgnore = 0;//>0 bad!
double MaxIgnore = 0.5;//Bad: 0.2, 0.4, 0.6, 0.7; OK: 0.1, 0.3, 0.5
double Gamma = 1.01;

double minHist, maxHist;
cv::minMaxLoc(Image, &minHist, &maxHist);
double Histdiff = maxHist - minHist;
double min = minHist + MinIgnore * Histdiff;
double max = maxHist - MaxIgnore * Histdiff;

double diff = max - min;
double m = (1 / (max - min));
double n = -m * min;

cv::pow(((m * Image) + n) / diff, Gamma, Image);
Image = diff * (Image);

//Smoothing
int Smoothingfactor = 11;
cv::blur(Image, Image, cv::Size(Smoothingfactor, Smoothingfactor));

//back to 16bit
Image.convertTo(Image, type, 65536.0, 0.0);

cv::imwrite("Output.png", Image);

Following 16Bit gray scale picture i use as InputImage: Input Image

This is the output on Windows 10: Output Image

Following Output will produce with MaxIgnore of 0.3: Output Image 0.3 (no black area)

Problem with calculations on Mat-Array with Windows 10

Hallo, I have a very mysterious problem with calculations on Mat-Arrays under Windows 10. Following code produce a black area on the output image under Windows 10. I don't know where it come from. When I run this code under windows 7 the image is ok, and no black area is to see. The effect has obscure dependency of the parameters MaxIgnore and MinIgnore and the input Image. What is wrong with my code, or is it a problem of the OpenCV Library itself?itself? I use OpenCV 3.4.1, Visual Studio 2017, Windows 10

cv::Mat Image;
Image = cv::imread("Input.png", cv::ImreadModes::IMREAD_ANYCOLOR | cv::ImreadModes::IMREAD_ANYDEPTH);

//scale 16bit gray scale image up to 0-1
int type = Image.type();
Image.convertTo(Image, CV_32F, 1.0 / 65536.0, 0.0);

//Calculations for brightness adjustment
double MinIgnore = 0;//>0 bad!
double MaxIgnore = 0.5;//Bad: 0.2, 0.4, 0.6, 0.7; OK: 0.1, 0.3, 0.5
double Gamma = 1.01;

double minHist, maxHist;
cv::minMaxLoc(Image, &minHist, &maxHist);
double Histdiff = maxHist - minHist;
double min = minHist + MinIgnore * Histdiff;
double max = maxHist - MaxIgnore * Histdiff;

double diff = max - min;
double m = (1 / (max - min));
double n = -m * min;

cv::pow(((m * Image) + n) / diff, Gamma, Image);
Image = diff * (Image);

//Smoothing
int Smoothingfactor = 11;
cv::blur(Image, Image, cv::Size(Smoothingfactor, Smoothingfactor));

//back to 16bit
Image.convertTo(Image, type, 65536.0, 0.0);

cv::imwrite("Output.png", Image);

Following 16Bit gray scale picture i use as InputImage: Input Image

This is the output on Windows 10: Output Image

Following Output will produce with MaxIgnore of 0.3: Output Image 0.3 (no black area)

Problem with calculations on Mat-Array with Windows 10

Hallo, I have a very mysterious problem with calculations on Mat-Arrays under Windows 10. Following code produce a black area on the output image under Windows 10. I don't know where it come from. When I run this code under windows 7 the image is ok, and no black area is to see. The effect has obscure dependency of the parameters MaxIgnore and MinIgnore and the input Image. What is wrong with my code, or is it a problem of the OpenCV Library itself? I use OpenCV 3.4.1, Visual Studio 2017, Windows 10

cv::Mat Image;
Image = cv::imread("Input.png", cv::ImreadModes::IMREAD_ANYCOLOR | cv::ImreadModes::IMREAD_ANYDEPTH);

//scale 16bit gray scale image up to 0-1
int type = Image.type();
Image.convertTo(Image, CV_32F, 1.0 / 65536.0, 0.0);

//Calculations for brightness adjustment
double MinIgnore = 0;//>0 bad!
double MaxIgnore = 0.5;//Bad: 0.23;//Bad: 0.2, 0.4, 0.6, 0.7; OK: 0.1, 0.3, 0.5
double Gamma = 1.01;

double minHist, maxHist;
cv::minMaxLoc(Image, &minHist, &maxHist);
double Histdiff = maxHist - minHist;
double min = minHist + MinIgnore * Histdiff;
double max = maxHist - MaxIgnore * Histdiff;

double diff = max - min;
double m = (1 / (max - min));
double n = -m * min;

cv::pow(((m * Image) + n) / diff, Gamma, Image);
Image = diff * (Image);

//Smoothing
int Smoothingfactor = 11;
cv::blur(Image, Image, cv::Size(Smoothingfactor, Smoothingfactor));

//back to 16bit
Image.convertTo(Image, type, 65536.0, 0.0);

cv::imwrite("Output.png", Image);

Following 16Bit gray scale picture i use as InputImage: Input Image

This is the output on Windows 10: Output Image

Following Output will produce with MaxIgnore of 0.3: Output Image 0.3 (no black area)