7 #ifndef IMPEM2D_SPIDER_IMAGE_READER_WRITER_H
8 #define IMPEM2D_SPIDER_IMAGE_READER_WRITER_H
10 #include "IMP/em2d/em2d_config.h"
27 IMPEM2D_BEGIN_NAMESPACE
34 bool skip_type_check_;
36 bool skip_extra_checkings_;
44 skip_type_check_ =
false;
45 force_reversed_ =
false;
46 skip_extra_checkings_ =
false;
59 bool force_reversed,
bool skip_extra_checkings) {
61 skip_type_check_ = skip_type_check;
62 force_reversed_ = force_reversed;
63 skip_extra_checkings_ = skip_extra_checkings;
67 cv::Mat &data)
const {
68 this->read_from_floats(filename, header, data);
72 const cv::Mat &data)
const {
73 this->write_to_floats(filename, header, data);
76 void read_from_ints(
const String &, em::ImageHeader &, cv::Mat &)
const {}
78 void write_to_ints(
const String &, em::ImageHeader &,
const cv::Mat &)
const {
89 cv::Mat &data)
const {
92 in.open(filename.c_str(), std::ios::in | std::ios::binary);
93 if (in.fail() || in.bad()) {
97 bool success = header.
read(in, skip_type_check_, force_reversed_,
98 skip_extra_checkings_);
100 IMP_THROW(
"Error reading header from Spider Image " << filename,
106 unsigned int rows = (int)header.get_number_of_rows();
107 unsigned int cols = (int)header.get_number_of_columns();
108 data.create(rows, cols, CV_64FC1);
111 for (cvDoubleMatIterator it = data.begin<
double>();
112 it != data.end<
double>(); ++it) {
114 in.read(reinterpret_cast<char *>(&aux),
sizeof(
float));
119 (*it) =
static_cast<double>(aux);
131 const cv::Mat &data)
const {
133 out.open(filename.c_str(), std::ios::out | std::ios::binary);
138 for (cvDoubleConstMatIterator it = data.begin<
double>();
139 it != data.end<
double>(); ++it) {
142 out.write(reinterpret_cast<char *>(&aux),
sizeof(
float));
154 IMPEM2D_END_NAMESPACE
bool get_is_big_endian()
Returns 1 if machine is big endian else 0.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Virtual class for reader/writers of images.
SpiderImageReaderWriter(const String &filename, bool skip_type_check, bool force_reversed, bool skip_extra_checkings)
Full constructor.
Virtual class for reader/writers of images Copyright 2007-2015 IMP Inventors. All rights reserved...
Interface with OpenCV Copyright 2007-2015 IMP Inventors. All rights reserved.
#define IMP_LOG_VERBOSE(expr)
Exception definitions and assertions.
void read_from_floats(const String &filename, em::ImageHeader &header, cv::Mat &data) const
An input/output exception.
functions to deal with endian of EM images
Functions to deal with very common math operations.
void write_to_floats(const String &filename, em::ImageHeader &header, const cv::Mat &data) const
Writes an EM image in Spider format.
SpiderImageReaderWriter()
void reversed_read(void *dest, size_t size, size_t nitems, std::ifstream &f, bool reverse)
Reads from file in normal or reverse order.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
void reversed_write(const void *src, size_t size, size_t nitems, std::ofstream &f, bool reverse=false)
Writes to a file in normal or reversed order.
Logging and error reporting support.
std::string String
Basic string value.