7 #ifndef IMPEM2D_JPG_IMAGE_READER_WRITER_H
8 #define IMPEM2D_JPG_IMAGE_READER_WRITER_H
10 #include "IMP/em2d/em2d_config.h"
13 #include <boost/filesystem/convenience.hpp>
15 IMPEM2D_BEGIN_NAMESPACE
23 void read(
const String &filename,
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);
47 cv::Mat temp= cv::imread(filename,0);
49 IMP_THROW(
"Error reading from JPG Image " << filename,IOException);
51 temp.assignTo(data,CV_64FC1);
71 const cv::Mat &data)
const {
74 IMP_LOG(
IMP::WARNING,
"Writing with JPGImageReaderWriter "
75 "discards image header " << std::endl);
77 String ext=boost::filesystem::extension(filename);
79 << filename <<std::endl);
80 if(ext!=
".jpg" && ext!=
".jpeg") {
81 IMP_THROW(
"JPGImageReaderWriter: The filename extension is not .jpg "
82 "or .jpeg",IOException);
88 cv::minMaxLoc(data,&min,&max);
91 double alpha = (jpg_max-jpg_min)/(max-min);
92 double beta = jpg_min-alpha*min;
93 data.convertTo(jpg_data,CV_8UC1,alpha,beta);
95 std::vector<int> flags;
96 flags.push_back(CV_IMWRITE_JPEG_QUALITY);
98 cv::imwrite(filename,jpg_data,flags);
104 IMPEM2D_END_NAMESPACE
Class to read and write EM images in JPG format.
Virtual class for reader/writers of images.
void write_to_ints(const String &filename, em::ImageHeader &header, const cv::Mat &data) const
Writes an EM image in JPG format.
#define IMP_UNUSED(variable)
inteface with OpenCV Copyright 2007-2013 IMP Inventors. All rights reserved.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#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 JPG format.
std::string String
Basic string value.
#define IMP_LOG_VERBOSE(expr)