How to split multiple pages/layers from a tif image and save it as seperate images using C++ OpenCV?

493 views Asked by At

I am new to using C++ with OpenCV and I want to load a .tif image and find out how many pages/layers exists and split the image into multiple pages. I could count the number of channels in the image using Mat::channels() and split the seperate channels using cv::Split() but I would like to know if there is a way to find out the number of layers in the .tif image and to split them into seperate layers and save them as seperate images in C++. I also came across this post using python. how to import multiple layers from tif file with opencv

Since I am new to C++, I find it a little difficult to adapt this code to C++ although I tried. I am using a Mat image object.

Any help would be greatly appreciated.

Edit:

for (int i = 0; i < count; i++) //Count is the number of tif images in the folder
{
        images.push_back(imread(fn[i], cv::IMREAD_UNCHANGED)); //pushes all images into a vector of Mat objects
        fileName = getFileExtension(fn[i], true); //getFileExtension is a function to take filename and extension seperately
        Mat current_image = images[i];

        imreadmulti(fileName, pages, cv::IMREAD_ANYCOLOR);
        cout << images[i].dims << endl;
        cout<< pages.size() << endl;
}
0

There are 0 answers