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.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)
hi, can you try to upload your images here (the "Edit" menu has an image upload button for this) ?
(your upload site has an https problem)
No, sorry. I can't upload the image, i dont no why. After i choose my image, no image will be there. Can it be, that the image is to big?(~7MB) Or because it is 16bit gray scale? I can upload a downscaled image, but with this image the effect does not occur.
ah right, 16bit not supported. and iirc some size limit, too.
but please don't make us download 7mb images , cmon.... !
maybe you can synthesize an image in memory. it's all about debugging some weird over/underflow, right ?
oh, and your actual code works on [0..1] float data.
what do you mean with synthesize an image in memory? It’s an interesting idea, that the problem comes from data-overflow. but why the effect occurs only on windows 10. And produce black pixels in a rectangle area of the picture.
I have Update the links to the pictures
try with (maxIgnore=0.23)
it's a better but not good
with setUseoptimize(false)
Oops : bug or not bug in blur (disable blur)
Wow. To see a white box is new... It is realy a bug in blur? I wonder that changes in the calculations before the blur, have an impact on the problem. I will not give up the blur filtering, what can i do? Is the problem also in other OpenCV Versions?
blakc line is a Nan rectangle. You can blur just after imread or convertTo