49 const Region * region,
bool is_3d)
55 LstIO * myLstIO =
dynamic_cast<LstIO *
>(imageio);
65 if ((
int)
attr_dict[
"is_complex_ri"] == 1)
107 const Region * region,
bool is_3d,
117 _read_image(imageio, img_index, nodata, region, is_3d);
148 if ((
int)
attr_dict[
"is_complex_ri"] == 1) {
156 if (!fast) ori_nz-=ori_nz%binfactor;
166 size_t sizeofslice =
nx*
ny*
sizeof(float);
169 int zbin = binfactor;
172 float percent = 0.1f;
173 for(
int k = 0; k < ori_nz; k+=binfactor){
174 if(k > ori_nz*percent){
175 printf(
"%1.0f %% Done\n",100.0*
float(k)/
float(ori_nz));
180 const Region* binregion =
new Region(0,0,k,ori_nx,ori_ny,zbin);
181 tempdata->read_image(filename, 0,
false, binregion);
183 if (binfactor > 1) tempdata->process_inplace(
"math.meanshrink",
Dict(
"n",binfactor));
184 size_t offset =
nx*
ny*k/binfactor;
202 bool header_only,
const Region * region,
204 bool use_host_endian)
214 LOGVAR(
"header write %d",img_index);
216 switch(filestoragetype) {
243 const char *reffile =
attr_dict[
"LST.reffile"];
244 if (strcmp(reffile,
"") == 0)
245 reffile =
path.c_str();
250 const char *comment =
attr_dict[
"LST.comment"];
251 char *lstdata =
new char[1024];
252 sprintf(lstdata,
"%d\t%s", refn, reffile);
253 if(strcmp(comment,
"") != 0)
254 sprintf(lstdata+strlen(lstdata),
"\t%s\n", comment);
256 strcat(lstdata,
"\n");
257 err = imageio->
write_data((
float*)lstdata, img_index,
258 region, filestoragetype, use_host_endian);
266 const char *reffile =
attr_dict[
"LST.reffile"];
267 if (strcmp(reffile,
"") == 0)
268 reffile =
path.c_str();
273 const char *comment =
attr_dict[
"LST.comment"];
274 char *lstdata =
new char[1024];
275 sprintf(lstdata,
"%d\t%s", refn, reffile);
276 if(strcmp(comment,
"") != 0)
277 sprintf(lstdata+strlen(lstdata),
"\t%s\n", comment);
279 strcat(lstdata,
"\n");
280 err = imageio->
write_data((
float*)lstdata, img_index,
281 region, filestoragetype, use_host_endian);
305 bool header_only,
const Region * region,
307 bool use_host_endian)
311 struct stat fileinfo;
312 if ( region && stat(filename.c_str(),&fileinfo) != 0 )
throw UnexpectedBehaviorException(
"To write an image using a region the file must already exist and be the correct dimensions");
318 auto pos = filename.rfind(
'.');
319 if (pos != string::npos)
339 LOGVAR(
"getimageio %d",rwmode);
343 header_only, region, filestoragetype,
356 write_image(filename, -1, imgtype, header_only, 0);
362 int refn,
const string & comment)
372vector<shared_ptr<EMData>>
EMData::read_images(
const string & filename, vector<int> img_indices,
379 size_t num_img = img_indices.size();
381 for (
size_t i = 0; i < num_img; i++)
382 if (img_indices[i] < 0 || img_indices[i] >= total_img)
385 size_t n = (num_img == 0 ? total_img : num_img);
388 vector<shared_ptr<EMData>> v;
389 for (
size_t j = 0; j < n; j++) {
390 shared_ptr<EMData> d(
new EMData());
391 size_t k = (num_img == 0 ? j : img_indices[j]);
393 d->_read_image(imageio, (
int)k, header_only);
417 bool use_host_endian)
423 auto num_imgs = imgs.size();
424 for (
size_t i = 0; i < num_imgs; i++) {
425 auto d = imgs[i].get();
427 d->_write_image(imageio, (
int)i, imgtype, header_only, region, filestoragetype, use_host_endian);
443 int nx = obj.get_xsize();
444 int ny = obj.get_ysize();
445 int nz = obj.get_zsize();
446 for (
int iz = 0; iz < nz; iz++) {
447 out <<
"(z = " << iz <<
" slice)" << std::endl;
448 for (
int ix = 0; ix < nx; ix++) {
449 for (
int iy = 0; iy < ny; iy++) {
450 out << std::setiosflags(std::ios::fixed)
451 << std::setiosflags(std::ios_base::scientific)
453 << std::setprecision(5) << obj(ix,iy,iz) <<
" ";
454 if (((iy+1) % 6) == 0) {
455 out << std::endl <<
" ";
Dict is a dictionary to store <string, EMObject> pair.
void erase(const string &key)
Remove a particular key.
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
E2Exception class is the parent class of all EMAN2 E2Exceptions.
EMData stores an image's data and defines core image processing routines.
void save_byteorder_to_dict(ImageIO *imageio)
EMData()
For all image I/O.
float * rdata
image real data
Dict attr_dict
to store all image header info
static void em_memcpy(void *dst, const void *const src, const size_t size)
static void close_imageio(const string &filename, const ImageIO *io)
Ian: Close ImageIO object.
static int get_image_count(const string &filename)
Get the number of images in an image file.
EMDataType
Image pixel data type used in EMAN.
static ImageIO * get_imageio(const string &filename, int rw_mode, ImageType image_type=IMAGE_UNKNOWN)
Get an ImageIO object.
ImageType
Image format types.
static ImageType get_image_ext_type(const string &file_ext)
Get an image's format type from its filename extension.
static void em_free(void *data)
ImageIO classes are designed for reading/writing various electron micrography image formats,...
virtual void flush()=0
Flush the IO buffer.
virtual int write_header(const Dict &dict, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
Write a header to an image.
virtual int write_data(float *data, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
Write data to an image.
string get_filename() const
virtual bool is_complex_mode()=0
Is this an complex image or not.
virtual int read_header(Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)=0
Read the header from an image.
virtual bool is_single_image_format() const
Is this image format only storing 1 image or not.
virtual int read_data(float *data, int image_index=0, const Region *area=0, bool is_3d=false)=0
Read the data from an image.
A LST file is an ASCII file that contains a list of image file names.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
float get_width() const
get the width
float get_depth() const
get the depth
float get_height() const
get the height
static bool is_file_exist(const string &filename)
check whether a file exists or not
void to_zero()
Set all the pixel value = 0.
void write_lst(const string &filename, const string &reffile="", int refn=-1, const string &comment="")
Append data to a LST image file.
void append_image(const string &filename, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false)
append to an image file; If the file doesn't exist, create one.
void read_binedimage(const string &filename, int img_index=0, int binfactor=0, bool fast=false, bool is_3d=false)
read in a binned image, bin while reading.
void _read_image(ImageIO *imageio, int img_index=0, bool header_only=false, const Region *region=0, bool is_3d=false)
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
void write_image(const string &filename, int img_index=0, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false, const Region *region=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
write the header and data out to an image.
static vector< std::shared_ptr< EMData > > read_images(const string &filename, vector< int > img_indices=vector< int >(), EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false)
Read a set of images from file specified by 'filename'.
void _write_image(ImageIO *imageio, int img_index=0, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false, const Region *region=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
void read_image(const string &filename, int img_index=0, bool header_only=false, const Region *region=0, bool is_3d=false, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN)
read an image file and stores its information to this EMData object.
static bool write_images(const string &filename, vector< std::shared_ptr< EMData > > imgs, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false, const Region *region=nullptr, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
Write a set of images to file specified by 'filename'.
#define ImageReadException(filename, desc)
#define ImageFormatException(desc)
#define OutofRangeException(low, high, input, objname)
#define UnexpectedBehaviorException(desc)
#define ImageWriteException(imagename, desc)
std::ostream & operator<<(std::ostream &os, const ScreenVector &v)