9 #ifndef IMPEM2D_TIFF_IMAGE_READER_WRITER_H
10 #define IMPEM2D_TIFF_IMAGE_READER_WRITER_H
13 #include <boost/filesystem.hpp>
15 IMPEM2D_BEGIN_NAMESPACE
24 cv::Mat &data)
const {
25 this->read_from_ints(filename, header, data);
29 const cv::Mat &data)
const {
30 this->write_to_ints(filename, header, data);
34 const cv::Mat &)
const {}
48 cv::Mat &data)
const {
51 cv::Mat temp = cv::imread(filename, 0);
53 IMP_THROW(
"Error reading from TIFF Image " << filename, IOException);
55 temp.assignTo(data, CV_64FC1);
69 const cv::Mat &data)
const {
73 "Writing with TIFFImageReaderWriter "
74 "discards image header "
77 String ext = boost::filesystem::extension(filename);
80 if (ext !=
".tiff" && ext !=
".tif") {
82 "TIFFImageReaderWriter: The filename extension is not .tiff "
90 cv::minMaxLoc(data, &min, &max);
91 double TIFF_max = 255;
93 double alpha = (TIFF_max - TIFF_min) / (max - min);
94 double beta = TIFF_min - alpha * min;
95 data.convertTo(TIFF_data, CV_8UC1, alpha, beta);
97 cv::minMaxLoc(TIFF_data, &min, &max);
99 cv::imwrite(filename, TIFF_data);
105 IMPEM2D_END_NAMESPACE
Virtual class for reader/writers of images.
#define IMP_UNUSED(variable)
Virtual class for reader/writers of images Copyright 2007-2014 IMP Inventors. All rights reserved...
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
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.
#define IMP_LOG_VERBOSE(expr)