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
24 this->read_from_ints(filename, header, data);
29 this->write_to_ints(filename, header, data);
45 cv::Mat temp = cv::imread(filename, 0);
49 temp.assignTo(data, CV_64FC1);
73 "Writing with JPGImageReaderWriter "
74 "discards image header "
77 String ext = boost::filesystem::extension(filename);
80 if (ext !=
".jpg" && ext !=
".jpeg") {
82 "JPGImageReaderWriter: The filename extension is not .jpg "
90 cv::minMaxLoc(data, &min, &max);
93 double alpha = (jpg_max - jpg_min) / (max - min);
94 double beta = jpg_min - alpha * min;
95 data.convertTo(jpg_data, CV_8UC1, alpha, beta);
97 std::vector<int> flags;
98 #if CV_VERSION_MAJOR >= 3
99 flags.push_back(cv::IMWRITE_JPEG_QUALITY);
101 flags.push_back(CV_IMWRITE_JPEG_QUALITY);
103 flags.push_back(100);
104 cv::imwrite(filename, jpg_data, flags);
110 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-2021 IMP Inventors. All rights reserved.
#define IMP_LOG_VERBOSE(expr)
An input/output exception.
#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.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.