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 override {
26 this->read_from_ints(filename, header, data);
30 const cv::Mat &data)
const override {
31 this->write_to_ints(filename, header, data);
35 const cv::Mat &)
const override {}
38 cv::Mat &)
const override {}
50 cv::Mat &data)
const override {
53 cv::Mat temp = cv::imread(filename, 0);
57 temp.assignTo(data, CV_64FC1);
71 const cv::Mat &data)
const override {
75 "Writing with TIFFImageReaderWriter "
76 "discards image header "
79 String ext = boost::filesystem::extension(filename);
82 if (ext !=
".tiff" && ext !=
".tif") {
84 "TIFFImageReaderWriter: The filename extension is not .tiff "
92 cv::minMaxLoc(data, &min, &max);
93 double TIFF_max = 255;
95 double alpha = (TIFF_max - TIFF_min) / (max - min);
96 double beta = TIFF_min - alpha * min;
97 data.convertTo(TIFF_data, CV_8UC1, alpha, beta);
99 cv::minMaxLoc(TIFF_data, &min, &max);
101 cv::imwrite(filename, TIFF_data);
107 IMPEM2D_END_NAMESPACE
void write_to_ints(const String &filename, em::ImageHeader &header, const cv::Mat &data) const override
Writes an EM image in TIFF format.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Virtual class for reader/writers of images.
void read_from_ints(const String &filename, em::ImageHeader &header, cv::Mat &data) const override
Reads an image file in TIFF format.
Virtual class for reader/writers of images Copyright 2007-2022 IMP Inventors. All rights reserved...
#define IMP_LOG_VERBOSE(expr)
An input/output exception.
#define IMP_UNUSED(variable)
Logging and error reporting support.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
std::string String
Basic string value.
Management of reading/writing TIFF images.