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
35 bool skip_type_check_;
37 bool skip_extra_checkings_;
45 skip_type_check_=
false;
46 force_reversed_=
false;
47 skip_extra_checkings_=
false;
60 bool force_reversed,
bool skip_extra_checkings) {
62 skip_type_check_=skip_type_check;
63 force_reversed_=force_reversed;
64 skip_extra_checkings_=skip_extra_checkings;
69 cv::Mat &data)
const {
70 this->read_from_floats(filename, header,data);
74 const cv::Mat &data)
const {
75 this->write_to_floats(filename, header,data);
78 void read_from_ints(
const String &, em::ImageHeader&, cv::Mat &)
const {
81 void write_to_ints(
const String &, em::ImageHeader&,
const cv::Mat &)
const {
91 void read_from_floats(
const String &filename,
95 in.open(filename.c_str(), std::ios::in | std::ios::binary);
96 if (in.fail() || in.bad()) {
97 IMP_THROW(
"Error reading from Spider Image " << filename,IOException);
100 bool success=header.
read(in,skip_type_check_,force_reversed_,
101 skip_extra_checkings_);
103 IMP_THROW(
"Error reading header from Spider Image "
104 << filename,IOException);
107 << header << std::endl);
109 unsigned int rows = (int)header.get_number_of_rows();
110 unsigned int cols = (int)header.get_number_of_columns();
111 data.create(rows,cols,CV_64FC1);
114 for (cvDoubleMatIterator it=data.begin<
double>();
115 it!=data.end<
double>();++it) {
117 in.read(reinterpret_cast< char* >(&aux),
sizeof(
float));
120 sizeof(
float),1,in,
true);
122 (*it) =
static_cast<double>(aux);
134 void write_to_floats(
const String &filename,
136 const cv::Mat &data)
const {
138 out.open(filename.c_str(), std::ios::out | std::ios::binary);
143 for (cvDoubleConstMatIterator it=data.begin<
double>();
144 it!=data.end<
double>();++it) {
147 out.write(reinterpret_cast< char* >(&aux),
sizeof(
float));
150 sizeof(
float),1,out,
true);
157 { out <<
"SpiderImageReaderWriter"; }, {});
163 IMPEM2D_END_NAMESPACE