Ask Your Question
4

Reason for size limit on imread [closed]

asked 2018-11-21 14:22:57 -0600

scottt gravatar image

updated 2018-12-03 17:23:12 -0600

I have successfully written images with sizes of about 60000x30000 (1,800,000,000 pixels), but when reading the image with imread, I get an assertion from these defined limits in opencv/modules/imgcodecs/src/loadsave.cpp:

#define CV_IO_MAX_IMAGE_PARAMS (50)
#define CV_IO_MAX_IMAGE_WIDTH (1<<20)
#define CV_IO_MAX_IMAGE_HEIGHT (1<<20)
#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel

Are there specific requirements being met by these or are these limits just arbitrarily defined? In width and height for example, 1<<20 matches dimensions of 1,000,000, where 1<<16 = 65536 seems to make more sense. This is what leads me to believe they are arbitrarily defined. To be able to handle images up to a size of 65536x65536, CV_IO_MAX_IMAGE_PIXELS should be 2^32.

It doesn't make sense to be able to write an image out of a certain size but be unable to read it.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2018-12-09 11:01:56.062478

1 answer

Sort by ยป oldest newest most voted
3

answered 2018-12-04 02:27:59 -0600

LBerger gravatar image

updated 2018-12-09 11:01:37 -0600

May be it's a bug and you can post an issue I tried this :

    RNG r;
    Mat m(60000, 40000, CV_8UC3);
    r.fill(m, RNG::UNIFORM, 0, 255);
    imwrite("test.png", m);
    Mat p = imread("test.png", IMREAD_UNCHANGED),d;
    cout << p.rows << " " << p.cols;
    absdiff(m, p, d);
    Scalar v = mean(d);
    cout << " mean=" << v << "\n";

and an exception is thrown (opencv 4.0.0 windows 10 visual 2017 win64) Now I changed in source code

#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel

in

#define CV_IO_MAX_IMAGE_PIXELS (1ull<<32ull) // 1 Gigapixel

and no exception is thrown (after opencv rebuild)

PR https://github.com/opencv/opencv/pull... and now in imread doc :

By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS

edit flag offensive delete link more

Comments

1

Downvote is free but sometime world is not as you think.

LBerger gravatar imageLBerger ( 2018-12-04 04:23:33 -0600 )edit
2

There is a comment: // TODO Add runtime configuration

It is better to add support for reading these values from the environment (using utils::getConfigurationParameterSizeT). PR is welcome!

mshabunin gravatar imagemshabunin ( 2018-12-04 05:01:39 -0600 )edit

@Akhil Patel do you have an explanation to this?

sturkmen gravatar imagesturkmen ( 2018-12-07 16:14:12 -0600 )edit
1

+1 but i am afraid it is hard to reach more hits than the answer above :)

sturkmen gravatar imagesturkmen ( 2018-12-09 12:40:43 -0600 )edit

It does not matter. +6 it is artificial :

LBerger gravatar imageLBerger ( 2018-12-09 13:30:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-21 14:22:57 -0600

Seen: 5,011 times

Last updated: Dec 09 '18