I realized a memory usage issue when I try to display huge images such as a 2GB of TIFF image. The code is below:
Mat image, output;
image = imread("img.tif", IMREAD_UNCHANGED);
//Memory usage : 2GB
normalize(image, output, 0, 0xFFFF, cv::NORM_MINMAX);
//Memory usage : 4GB
namedWindow("Display Image", WINDOW_NORMAL);
imshow("Display Image", output);
//Memory usage : 6.5GB
waitKey(0);
When I run this program step-by-step in Debug mode on Ubuntu environment, I saw that memory usage is increasing tremendously from System Monitor.
When imread is hit, my program uses approximately 2GB of memory. When normalize is called, it increases to approximately 4GB. And finally when imshow is called, it increases to ~6.5GB.
So what i think it creates new copies everytime I call imread, normalize and imshow.
Is there any way to overcome this issue ? What I think is that maybe i can manually normalize my original image, but is it possible to use imshow with reference of my original Mat object instead of creating a new one ?