How to save 5 channel image?

Viewed 85

I created a 5 channel image in cv::Mat format but I am unable to save it since the imwrite function for opencv doesn't support 5 channels? (i read this from another thread)

I am trying to save it as .tiff since i know it supports multiple channels, but i am open to other file type alternatives as long as i can save all 5 channels of the image.I have also tried the FileStorage approach but somehow it doesn't work. It runs without error but the file is nowhere to be found.

opencv version: 4.5.2

cv::Mat FiveChannelImage;

cv::Mat color3 = this->capturedColorImage; // CV_16UC3
std::vector<cv::Mat>channelsForColor2(3);
cv::split(color3, channelsForColor2);

cv::Mat depthToColor3 = this->capturedDepthToColorImage; // CV_16UC1
std::vector<cv::Mat>channelsForDepth2(1);
cv::split(depthToColor3, channelsForDepth2);

cv::Mat depthToColor4 = this->capturedDepthToColorImageNormalized; // CV_16UC1
std::vector<cv::Mat>channelsForDepth3(1);
cv::split(depthToColor4, channelsForDepth3);

std::vector<cv::Mat>channels2(5);

channels2[0] = channelsForColor2[0];
channels2[1] = channelsForColor2[0];
channels2[2] = channelsForColor2[0];
channels2[3] = channelsForDepth2[0];
channels2[4] = channelsForDepth3[0];
cv::merge(channels2, FiveChannelImage);

qDebug() << FiveChannelImage.channels();


// Doesn't work?
cv::FileStorage fs("file.ext.gz", cv::FileStorage::WRITE);
fs << "matfile" << FiveChannelImage;
fs.release();

cv::imwrite("./combined_image.tiff", FiveChannelImage);
0 Answers
Related