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 cv::Mat &data)
const {
24 this->read_from_ints(filename, header, data);
28 const cv::Mat &data)
const {
29 this->write_to_ints(filename, header, data);
42 cv::Mat &data)
const {
45 cv::Mat temp = cv::imread(filename, 0);
47 IMP_THROW(
"Error reading from JPG Image " << filename, IOException);
49 temp.assignTo(data, CV_64FC1);
55 const cv::Mat &)
const {}
68 const cv::Mat &data)
const {
72 "Writing with JPGImageReaderWriter "
73 "discards image header "
76 String ext = boost::filesystem::extension(filename);
79 if (ext !=
".jpg" && ext !=
".jpeg") {
81 "JPGImageReaderWriter: The filename extension is not .jpg "
89 cv::minMaxLoc(data, &min, &max);
92 double alpha = (jpg_max - jpg_min) / (max - min);
93 double beta = jpg_min - alpha * min;
94 data.convertTo(jpg_data, CV_8UC1, alpha, beta);
96 std::vector<int> flags;
97 flags.push_back(CV_IMWRITE_JPEG_QUALITY);
99 cv::imwrite(filename, jpg_data, flags);
105 IMPEM2D_END_NAMESPACE
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
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.
Interface with OpenCV Copyright 2007-2014 IMP Inventors. All rights reserved.
#define IMP_LOG_VERBOSE(expr)
#define IMP_UNUSED(variable)
#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.