9 #ifndef IMPEM2D_TIFF_IMAGE_READER_WRITER_H
10 #define IMPEM2D_TIFF_IMAGE_READER_WRITER_H
13 #include <boost/filesystem.hpp>
16 IMPEM2D_BEGIN_NAMESPACE
25 cv::Mat &data)
const {
26 this->read_from_ints(filename, header, data);
30 const cv::Mat &data)
const {
31 this->write_to_ints(filename, header, data);
35 const cv::Mat &)
const {}
49 cv::Mat &data)
const {
52 cv::Mat temp = cv::imread(filename, 0);
56 temp.assignTo(data, CV_64FC1);
70 const cv::Mat &data)
const {
74 "Writing with TIFFImageReaderWriter "
75 "discards image header "
78 String ext = boost::filesystem::extension(filename);
81 if (ext !=
".tiff" && ext !=
".tif") {
83 "TIFFImageReaderWriter: The filename extension is not .tiff "
91 cv::minMaxLoc(data, &min, &max);
92 double TIFF_max = 255;
94 double alpha = (TIFF_max - TIFF_min) / (max - min);
95 double beta = TIFF_min - alpha * min;
96 data.convertTo(TIFF_data, CV_8UC1, alpha, beta);
98 cv::minMaxLoc(TIFF_data, &min, &max);
100 cv::imwrite(filename, TIFF_data);
106 IMPEM2D_END_NAMESPACE
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Virtual class for reader/writers of images.
Virtual class for reader/writers of images Copyright 2007-2020 IMP Inventors. All rights reserved...
#define IMP_LOG_VERBOSE(expr)
An input/output exception.
#define IMP_UNUSED(variable)
Logging and error reporting support.
void write_to_ints(const String &filename, em::ImageHeader &header, const cv::Mat &data) const
Writes an EM image in TIFF format.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
void read_from_ints(const String &filename, em::ImageHeader &header, cv::Mat &data) const
Reads an image file in TIFF format.
std::string String
Basic string value.
Management of reading/writing TIFF images.