Created
October 4, 2023 19:31
-
-
Save esnosy/0abdffda371689c563a72f08bd6f895c to your computer and use it in GitHub Desktop.
Write Eigen Matrix as PGM image
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
constexpr size_t N = 900; | |
Eigen::Matrix<uint8_t, -1, -1> output(N, N); | |
output.fill(255); | |
std::ofstream ofs("output.pgm", std::ofstream::binary); | |
ofs << "P5\n" | |
<< N << ' ' << N << "\n255\n"; | |
// Otherwise the image will be flipped due to how PGM file format is layed out | |
output.rowwise().reverseInPlace(); | |
ofs.write(reinterpret_cast<char *>(output.data()), N * N * sizeof(uint8_t)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment