38 if (strMethod==
"fourier")
43 else if (strMethod==
"smooth")
53 addUsageLine(
"Downsample a micrograph. For volumes use xmipp_transform_geometry.");
54 addUsageLine(
"+There are several downsampling methods. The most general and recommended is Fourier.");
55 addUsageLine(
"+Fourier downsampling puts a window in Fourier space. This is the best downsampling that can be performed.");
56 addUsageLine(
"+Altermatively, smoothing makes color dithering which is pretty good for visualization, ");
57 addUsageLine(
"+but it modifies the particle spectrum. Binning with a rectangle kernel modifies the ");
58 addUsageLine(
"+spectrum of the micrographs and is not recommended. You may see the effects of the different ");
59 addUsageLine(
"+downsampling schemes at [[http://biocomp.cnb.csic.es/~coss/Articulos/Sorzano2009d.pdf][this article]].");
61 addUsageLine(
"+The downsampling factor (--step) is the factor by which the micrograph will be reduced.");
62 addUsageLine(
"+For instance, a downsampling by 2 will reduce the image size to one half. Using Fourier and smooth ");
63 addUsageLine(
"+you may use non-integer downsampling factors, and the image size will be reduced by 1/factor");
66 addParamsLine(
" --step <factor> : Downsampling factor. factor=2 reduces the image size to one half.");
67 addParamsLine(
" :+Fourier and smooth support non-integer downsampling factors.");
68 addParamsLine(
" :+Rectangular binning must use integer factors.");
69 addParamsLine(
" [--method <mth=fourier>] : Method for making the downsampling");
71 addParamsLine(
" fourier <numThreads=1>: Fourier supports non-integer downsampling factors");
73 addParamsLine(
" rectangle: This is simple binning in a square of size factor x factor");
74 addParamsLine(
" :+This is not a good choice since it creates aliasing and ");
77 addParamsLine(
" :+ Both input and output micrographs must be 8 bits, unsigned char");
78 addExampleLine(
"xmipp_transform_downsample -i micrograph.tif -o downsampledMicrograph.tif --step 2");
87 size_t Zdim, Ydim, Xdim;
100 M_out.
mapFile2Write(Xpdim, Ypdim, 1, fnImgOut,fnImg==fnImgOut);
110 M_out.
write(fnImgOut);
116 auto istep=(int)step;
121 size_t Ydim, Xdim, Ypdim, Xpdim;
129 size_t ii, jj, i2, j2,
i,
j,
y,
x;
133 double omin=0., omax=0.;
142 for (ii = 0, y = 0; y < Ydim && ii < Ypdim; y += istep, ++ii)
143 for (jj = 0, x = 0; x < Xdim && jj < Xpdim; x += istep, ++jj)
146 for (i=0, i2=y; i<
YSIZE(kernel) && i2<Ydim; ++
i, ++i2)
147 for (j=0, j2=x; j<
XSIZE(kernel) && j2<Xdim; ++
j, ++j2)
152 pixval +=
A2D_ELEM(kernel,i, j) * aux;
157 omin = omax = pixval;
168 double irange = imax - imin;
169 double orange = omax - omin;
173 a = scale * irange / orange;
185 for (ii = 0, y = 0; y < Ydim && ii < Ypdim; y += istep, ++ii)
186 for (jj = 0, x = 0; x < Xdim && jj < Xpdim; x += istep, ++jj)
189 for (i=0, i2=y; i<
YSIZE(kernel) && i2<Ydim; ++
i, ++i2)
190 for (j=0, j2=x; j<
XSIZE(kernel)&& j2<Xdim; ++
j, ++j2)
192 if (ii < Ypdim && jj < Xpdim)
204 size_t Ydim, Xdim, Ypdim, Xpdim;
228 int ihalf=
YSIZE(MpmemFourier)/2+1;
229 for (
int i=0;
i<ihalf;
i++)
230 for (
size_t j=0;
j<
XSIZE(MpmemFourier);
j++)
232 for (
size_t i=ihalf;
i<
YSIZE(MpmemFourier);
i++)
234 size_t ip=
YSIZE(MmemFourier)-
YSIZE(MpmemFourier)+
i;
235 for (
size_t j=0;
j<
XSIZE(MpmemFourier);
j++)
243 double omin=0.,omax=0.;
245 double orange = omax - omin;
268 "Choose a supporting 8bit file format different from %s",Mp.
image->
name().c_str()));
270 size_t Ydim, Xdim, Ypdim, Xpdim;
273 byte *inputImage=
nullptr;
276 M().getArrayPointer(inputImage);
283 unsigned char *outputImage;
284 Mp().getArrayPointer(outputImage);
285 SmoothResize(inputImage,outputImage, Xdim, Ydim, Xpdim, Ypdim);
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)
#define A2D_ELEM(v, i, j)
void setPixel(unsigned long n, int k, int i, int j, double value) const
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
#define REPORT_ERROR(nerr, ErrormMsg)
void resizeNoCopy(const MultidimArray< T1 > &v)
#define MULTIDIM_ARRAY(v)
const FileName & name() const
void SmoothResize(byte *picSrc8, byte *destpic8, size_t swide, size_t shigh, size_t dwide, size_t dhigh)
DataType getDatatype() const
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
void addSeeAlsoLine(const char *seeAlso)
const char * getParam(const char *param, int arg=0)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
Incorrect argument received.
void downsampleFourier(const ImageGeneric &M, double step, ImageGeneric &Mp, int nThreads)
void computeDoubleMinMax(double &minval, double &maxval) const
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)
double getPixel(unsigned long n, int k, int i, int j) const
void downsampleKernel(const ImageGeneric &M, double step, ImageGeneric &Mp)
void setDatatype(DataType _datatype)
void downsampleSmooth(const ImageGeneric &M, ImageGeneric &Mp)
int readOrReadMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
String formatString(const char *format,...)
int getDatatypeDepth() const
Incorrect MultidimArray dimensions.
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)