43 appendToStack =
false;
59 comments.
addComment(
"++ Supported read formats are:");
60 comments.
addComment(
"++ dm3 : Digital Micrograph 3");
61 comments.
addComment(
"++ em : Electron Microscopy");
64 comments.
addComment(
"++ inf,raw : RAW file with header INF file");
66 comments.
addComment(
"++ pif : Portable Image Format");
67 comments.
addComment(
"++ ser : Tecnai Imaging and Analysis");
68 comments.
addComment(
"++ spe : Princeton Instruments CCD camera");
71 comments.
addComment(
"++ raw#xDim,yDim,[zDim],offset,datatype,[r] : RAW image file without header file");
72 comments.
addComment(
"++ where datatype can be: uint8,int8,uint16,int16,uint32,int32,long,float,double,");
73 comments.
addComment(
"++ cint16,cint32,cfloat,cdouble,bool");
76 addUsageLine(
"Convert among stacks, volumes and images, and change the file format.");
77 addUsageLine(
"+Conversion to a lower bit_depth automatically adjusts the gray level range. If it is between same bit ");
78 addUsageLine(
"+depths and different sign, then only a histogram shift is done. If parameter --depth is not passed, then ");
79 addUsageLine(
"+bit_depth is automatically chosen equal to or higher than input bit_depth. For stack output format, ");
80 addUsageLine(
"+a selection file with the images in the stack is optionally created, replicating the labels of the input sel file.");
81 addUsageLine(
"+If output file extension is not set when --oroot is used (neither setting --oext nor :ext), then input format is chosen.");
82 addKeywords(
"conversion, convert, image, stack, volume, format, extension ");
84 addParamsLine(
" [--oext <extension=\"\">] : Output file format extension.");
86 addParamsLine(
" img : Imagic (Data types: uint8, int16, float* and cfloat).");
87 addParamsLine(
" inf : RAW file with header INF file (Data types: (u)int8, (u)int16 and float*).");
88 addParamsLine(
" raw : RAW file with header INF file (Data types: (u)int8, (u)int16 and float*).");
89 addParamsLine(
" mrc : CCP4 (Data types: uint8, (u)int16, float* and cfloat).");
90 addParamsLine(
" spi : Spider (Data types: float* and cfloat).");
91 addParamsLine(
" xmp : Spider (Data types: float* and cfloat).");
92 addParamsLine(
" tif : TIFF (Data types: uint8*, uint16, uint32 and float).");
94 addParamsLine(
" custom <ext> : Custom extension name, the real format will be Spider.");
95 addParamsLine(
" [--type <output_type=auto>] : Force output file type.");
97 addParamsLine(
" auto: Autodetect output type according to output extension and whether --oroot is passed or not.");
103 addParamsLine(
" [--depth+ <bit_depth=default>] : Image bit depth.");
121 addParamsLine(
" [--swap <type=arch>] : Swap the endianness of the image file");
123 addParamsLine(
" arch : Set the opposite endian of the architecture");
127 addParamsLine(
" [--range_adjust] : Adjust the histogram to fill the gray level range");
129 addParamsLine(
"or --dont_convert : Do not apply any conversion to gray levels when writing");
130 addParamsLine(
" : in a lower bit depth or changing the sign");
132 addParamsLine(
" [--append] : Append the input to the output stack instead of overwriting it");
139 addExampleLine(
"xmipp_image_convert -i spider.vol -o stack.mrcs -t stk");
140 addExampleLine(
"Create a stack of volumes with a Spider volume :",
false);
141 addExampleLine(
"xmipp_image_convert -i spider.vol -o vol_stack.stk -t vol");
143 addExampleLine(
"xmipp_image_convert -i spider.vol -o vol_stack.stk -a");
145 addExampleLine(
"xmipp_image_convert -i spider.vol -o 3@vol_stack.stk");
146 addExampleLine(
"Save images in a stack as independent TIFF files in image directory with \"newimage\" basename in 8bit format:",
false);
147 addExampleLine(
"xmipp_image_convert -i stackFile.stk -o tiffImages.sel --oroot images/newimage:tif -d uint8");
148 addExampleLine(
"Convert a selection file of 16bit TIFF images to 8bit and overwrites files and sel file:",
false);
151 addExampleLine(
"xmipp_image_convert -i img.spi -o stackFile.stk --append");
153 addExampleLine(
"xmipp_image_convert -i selFile.sel -o stackFile.stk --append");
155 addExampleLine(
"xmipp_image_convert -i img.spi -o 3@stackFile.stk");
157 addExampleLine(
"xmipp_image_convert -i stack.mrc -o volume.mrc -t vol");
172 if (
oext ==
"custom" )
181 if (depthTemp !=
"default")
182 depth =
"%" + depthTemp;
189 if (swapType !=
"arch")
191 bool setLE = swapType ==
"little";
210 else if (
mdInSize > 1 || appendToStack)
227 else if (type ==
"stk" && appendToStack)
252 "Only 2D images can be converted into volumes");
310 if (fnImg == fnImgOut)
319 imIn.
write(_fnImgOut+depth,
ALL_IMAGES, type ==
"stk", writeMode, castMode, swap);
321 if ((fnImg == fnImgOut) && (rename(tempName.c_str(),fnImgOut.c_str())!=0))
335 imOut->
write(fnImgOut+depth,
ALL_IMAGES, type ==
"stk", writeMode, castMode, swap);
365 std::cout <<
"Output Extension: " <<
oext << std::endl;
std::string datatype2Str(DataType datatype)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
bool IsLittleEndian(void)
#define REPORT_ERROR(nerr, ErrormMsg)
FileName removeFileFormat() const
void setSlice(int k, const MultidimArray< T1 > &v, size_t n=0)
void compose(const String &str, const size_t no, const String &ext="")
Input/Output general error.
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
void addKeywords(const char *keywords)
String getExtension() const
void getSlice(int k, MultidimArray< T > &M, char axis='Z', bool reverse=false, size_t n=0) const
const char * getParam(const char *param, int arg=0)
void progress_bar(long rlen)
void mapFile2Write(int Xdim, int Ydim, int Zdim, const FileName &_filename, bool createTempFile=false, size_t select_img=APPEND_IMAGE, bool isStack=false, int mode=WRITE_OVERWRITE, int _swapWrite=0)
void addExampleLine(const char *example, bool verbatim=true)
void createEmptyFile(const FileName &filename, int xdim, int ydim, int Zdim, size_t select_img, bool isStack, int mode, int _swapWrite, const MDRowVec *md)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
String formatString(const char *format,...)
bool checkParam(const char *param)
Incorrect MultidimArray dimensions.
bool hasVolumeExtension() const
void addUsageLine(const char *line, bool verbatim=false)
bool hasStackExtension() const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
MultidimArrayGeneric * data
void addParamsLine(const String &line)
std::map< String, CommentList > defaultComments