Created
September 14, 2019 15:56
-
-
Save zoq/504adca4cf7bbfb6854ccc7b309a5f75 to your computer and use it in GitHub Desktop.
image_save.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Image saving API for multiple files. | |
template<typename eT> | |
bool Save(const std::vector<std::string>& files, | |
arma::Mat<eT>& matrix, | |
ImageInfo& info, | |
const bool fatal, | |
const bool transpose) | |
{ | |
if (files.size() == 0) | |
{ | |
std::ostringstream oss; | |
oss << "Files vector is empty." << std::endl; | |
throw std::runtime_error(oss.str()); | |
return false; | |
} | |
if (files.size() != matrix.n_cols) | |
{ | |
std::ostringstream oss; | |
oss << "Number of columns doesn't match with the number of files. " | |
<< "Note a single image is stored into a single column." << std::endl; | |
throw std::runtime_error(oss.str()); | |
return false; | |
} | |
// We transpose by default. So, un-transpose if necessary. | |
if (!transpose) | |
matrix = arma::trans(matrix); | |
for (size_t i = 0; i < files.size() ; i++) | |
{ | |
arma::Mat<unsigned char> colImg(matrix.colptr(i), matrix.n_rows, 1, | |
false, true); | |
status &= Save(files[i], colImg, info, fatal, transpose); | |
} | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment