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 void read(
const String &filename,
26 cv::Mat &data)
const {
27 this->read_from_ints(filename, header,data);
31 const cv::Mat &data)
const {
32 this->write_to_ints(filename, header,data);
54 cv::Mat temp= cv::imread(filename,0);
56 IMP_THROW(
"Error reading from TIFF Image " << filename,IOException);
58 temp.assignTo(data,CV_64FC1);
73 const cv::Mat &data)
const {
76 IMP_LOG(
IMP::WARNING,
"Writing with TIFFImageReaderWriter "
77 "discards image header " << std::endl);
79 String ext=boost::filesystem::extension(filename);
81 << filename <<std::endl);
82 if(ext!=
".tiff" && ext!=
".tif") {
83 IMP_THROW(
"TIFFImageReaderWriter: The filename extension is not .tiff "
84 "or .tif",IOException);
90 cv::minMaxLoc(data,&min,&max);
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);
106 IMPEM2D_END_NAMESPACE
Virtual class for reader/writers of images.
#define IMP_UNUSED(variable)
Virtual class for reader/writers of images Copyright 2007-2013 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)