53 addUsageLine(
"This program takes a region from the input images");
56 "But... what is windowing? Let's suppose we have an image 32x32,");
58 "and we window it to 16x16, then the central part which contains");
60 "this 16x16 square is returned, but if we window to 64x64 then the");
62 "image is kept in the center of the final image and it is padded");
64 "with 0's until the new size is reached (the padding value may be");
66 "modified using --pad_value, --corner_pad_value or --average_pad_value).");
69 "With this idea in mind of padding or cutting, if you define two");
71 "logical corners in the input image (the most negative -the top");
73 "left in an image- and the most positive -bottom right in an image-)");
75 "you can store the new image or volume generated by windowing with");
78 " --corners <...> : Windows corners (by default indexes are logical)");
80 " : 2D: <x0> <y0> <xF> <yF>");
82 " : 3D: <x0> <y0> <z0> <xF> <yF> <zF>");
84 " or --size <sizeX> <sizeY=0> <sizeZ=0> : Output dimension. The volume is windowed");
86 " : (expanded or cutted) in all directions such");
88 " : that the origin of the volume remains the");
90 " : same. If the Y and Z dimensions are not");
92 " : specified they are assumed to be the same as");
94 " : the X dimension.");
96 " or --crop <sizeX> <sizeY=0> <sizeZ=0> : Crop this amount of pixels in each direction.");
98 " : Half of the pixels will be cropped from the left");
100 " : and the other half from the right");
102 " : if only one is given, the other two");
104 " : are supposed to be the same");
106 " or --unitcell <sym> <rmin=0> <rmax=0> <expandFactor=0> <offset=0> <sampling=1.> <x_origin=-1.> <y_origin=-1.> <z_origin=-1.> : Extract a unit cell from volume");
108 " : sym = particle symmetry");
110 " : expandFactor = expand unitcell by this factor");
112 " : rmax, rmin = cut a shell with these radii (pixels)");
114 " : offset= for CN symmetry rotate unit cell by this angle");
116 " : sampling=if the output is a mrc file it will use this value to fill the header");
118 " : x_origin = origin x coordinate introduced by the user with the input volume (in pixels)");
120 " : y_origin = origin y coordinate introduced by the user with the input volume (in pixels)");
122 " : z_origin = origin z coordinate introduced by the user with the input volume (in pixels)");
124 " [--physical] : use physical instead of logical coordinates");
127 " [--pad <padtype=value>] : value used for padding");
130 " value <v=0> : use this value for padding");
132 " corner : use the top-left corner for padding");
134 " avg : use the image average for padding");
136 "Window a single image to 16x16, overwriting input image",
138 addExampleLine(
"xmipp_transform_window -i g0ta0001.xmp --size 16");
140 addExampleLine(
"xmipp_transform_window -i g0ta.vol --size 64 64 32");
143 "xmipp_transform_window -i g0ta.vol --corners -32 -32 -16 31 31 15");
145 "Note that r0 and rF are not symmetric because the volume is of an",
148 "even size, if we wanted to get a 33x65x65 volume, the right indexes",
152 "xmipp_transform_window -i g0ta.vol --corners -32 -32 -16 32 32 16");
153 addExampleLine(
"Reduce the volume by 10 pixels on each direction",
157 "Enlarge the volume by 10 pixels on each direction (negative crop)",
160 addExampleLine(
"scipion xmipp_transform_window -i postprocess.mrc:mrc -o postprocess_win.mrc --unitcell i2 0 300 20 0 0.34");
161 addKeywords(
"window, crop, resize, corner, padding");
167 if (padType ==
"value")
171 if (nparams == 4 || nparams == 6) {
186 "Incorrect number of arguments after --corners");
204 physical_coords =
false;
217 physical_coords =
false;
239 switch (windowMode) {
241 std::cout <<
"New size: (XxYxZ)=" << sizeX <<
"x" << sizeY <<
"x" 242 << sizeZ << std::endl;
245 std::cout <<
"Crop: (XxYxZ)=" << cropX <<
"x" << cropY <<
"x" 246 << cropZ << std::endl;
249 std::cout <<
"New window: from (z0,y0,x0)=(" << z0 <<
"," << y0
250 <<
"," << x0 <<
") to (zF,yF,xF)=(" << zF <<
"," << yF
251 <<
"," << xF <<
")\n" <<
"Physical: " << physical_coords
255 std::cout <<
"Sym: " << sym <<
", rmin: " << rmin <<
", rmax: " << rmax
256 <<
", Expand Factor: " << expand <<
", offset: " << offset
257 <<
", sampling: " << sampling <<
"; Origin in Angstroms: " 258 <<
" x: " << x_origin * sampling <<
", y: " << y_origin * sampling <<
", z: " << z_origin * sampling
266 renameTempFn =
false;
280 UnitCell UC(sym, rmin, rmax, expand, offset, sampling, x_origin, y_origin, z_origin);
289 bool createTempFile = (fnImg == fnImgOut);
296 double init_value(padValue);
297 if (padType ==
"avg")
298 init_value = Iin().computeAvg();
299 else if (padType ==
"corner")
300 init_value = Iin()(0, 0, 0, 0);
302 Iin().setXmippOrigin();
303 if (
ZSIZE(Iin()()) == 1)
312 }
else if (windowMode ==
CROPMODE) {
319 if (
ZSIZE(Iin()()) == 1) {
328 Iin().window(result(),
333 }
else if (!physical_coords) {
335 fnImgOut, createTempFile);
336 Iin().window(result(), z0, y0, x0, zF, yF, xF, init_value);
339 fnImgOut, createTempFile);
340 Iin().window(result(),
349 result.
write(fnImgOut);
356 if (std::rename(
fn_out.c_str(),
fn_in.c_str()) != 0)
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)
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
Input/Output general error.
DataType getDatatype() const
void addKeywords(const char *keywords)
String getExtension() const
const char * getParam(const char *param, int arg=0)
Incorrect argument received.
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)
int verbose
Verbosity level.
void convert2Datatype(DataType datatype, CastWriteMode castMode=CW_CONVERT)
int getCountParam(const char *param)
void maskUnitCell(ImageGeneric &in3DDmap, ImageGeneric &out3DDmap)
#define FIRST_XMIPP_INDEX(size)
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
String formatString(const char *format,...)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
bool checkParam(const char *param)
void addUsageLine(const char *line, bool verbatim=false)
#define LAST_XMIPP_INDEX(size)
int getIntParam(const char *param, int arg=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
void addParamsLine(const String &line)
void unitcell(ImageGeneric &in3Dmap, ImageGeneric &out3DDmap)