87 double dot=op1().dotProduct(op2());
88 std::cout <<
"<" << op1.
name() <<
"," << op2.
name() <<
">=" << dot << std::endl;
284 op(k,
i,
j) = radial_mean(my_rad);
305 op(k,
i,
j) = radial_mean(my_rad);
316 each_image_produces_an_output =
true;
317 save_metadata_stack =
true;
318 keep_input_columns =
true;
319 addUsageLine(
"A simple Xmipp images calculator. Binary and unary operations");
321 addParamsLine(
"== Binary operations: ==");
322 addParamsLine(
" --plus <file_or_value> :Sums two images, volumes or adds a numerical value to an image");
323 addParamsLine(
"or --minus <file_or_value> :Subtracts two images, volumes or subtracts a numerical value to an image");
324 addParamsLine(
"or --minusAdjusted <file> :Subtracts two sets of images adjusting the gray values so that error is minimized");
325 addParamsLine(
" : If you are comparing a set of noisy and clean images, put the noisy images in -i");
326 addParamsLine(
"or --mult <file_or_value> :Multiplies two images, volumes, or multiplies per a given number");
327 addParamsLine(
"or --divide <file_or_value> :Divides two images, volumes, or divides per a given number");
328 addParamsLine(
"or --min <file_or_value> :Minimum of two images, volumes, or number (pixel-wise)");
329 addParamsLine(
"or --max <file_or_value> :Maximum of two images, volumes, or number (pixel-wise)");
330 addParamsLine(
"or --compare <file_or_value> :Returns -1 if the left value is less, 0 if are equal or 1 if greater.(pixel-wise)");
331 addParamsLine(
"or --dot_product <file> :Dot product between two images or volumes");
332 addParamsLine(
"or --dropout <p> :Set to 0.0 the values of the input with probability p");
333 addParamsLine(
"==+ Relational operations: ==");
334 addParamsLine(
"or --eq <file_or_value> :Returns 1 if the pixels values are equal, 0 otherwise (pixel-wise)");
335 addParamsLine(
"or --le <file_or_value> :Returns 1 if the pixels values are less or equal, 0 otherwise (pixel-wise)");
336 addParamsLine(
"or --lt <file_or_value> :Returns 1 if the pixels values are less than, 0 otherwise (pixel-wise)");
337 addParamsLine(
"or --ge <file_or_value> :Returns 1 if the pixels values are greater or equal, 0 otherwise (pixel-wise)");
338 addParamsLine(
"or --gt <file_or_value> :Returns 1 if the pixels values are greater, 0 otherwise (pixel-wise)");
339 addParamsLine(
"or --ne <file_or_value> :Returns 1 if the pixels values are not equal, 0 otherwise (pixel-wise)");
341 addParamsLine(
"== Unary operations: ==");
342 addParamsLine(
"or --log :Computes the natural logarithm of an image");
343 addParamsLine(
"or --log10 :Computes the decimal logarithm of an image");
344 addParamsLine(
"or --sqrt :Computes the square root of an image");
345 addParamsLine(
"or --abs :Computes the absolute value of an image");
346 addParamsLine(
"or --pow <value=2> :Computes the power of an image");
347 addParamsLine(
"or --slice <value> :Extracts a given slice from a volume (first slice=0)");
348 addParamsLine(
"or --column <value> :Extracts a given column from a image or volume");
349 addParamsLine(
"or --row <value> :Extracts a given row from a image or volume");
350 addParamsLine(
"or --radial_avg :Compute the radial average of an image");
351 addParamsLine(
"or --psd_radial_avg :Compute the radial average of an image");
352 addParamsLine(
"or --reset :Set the image to 0");
354 addExampleLine(
"Sum two volumes and save result",
false);
355 addExampleLine(
"xmipp_image_operate -i volume1.vol --plus volume2.vol -o result.vol");
356 addExampleLine(
"Calculate the log10 of an image called example.xmp and store the resulting one in example_log.xmp",
false);
357 addExampleLine(
"xmipp_image_operate -i example.xmp --log10 -o example_log.xmp");
358 addExampleLine(
"Calculate the square root of a volume called example.vol and store it in expample_sq.vol",
false);
359 addExampleLine(
"xmipp_image_operate -i example.vol --sqrt -o expample_sq.vol");
360 addExampleLine(
"Extract the slice number 10 of a set of of volumes given in the sel file called volumes.sel. The names of the output images its supposed to be in the selfile images.sel",
false);
361 addExampleLine(
"xmipp_image_operate -i volumes.sel --slice 10 -o images.sel");
362 addExampleLine(
"Sum 5 to every image in images.sel and rewrite the input images",
false);
363 addExampleLine(
"xmipp_image_operate -i images.sel --plus 5");
364 addExampleLine(
"Subtract two volumes:",
false);
365 addExampleLine(
"xmipp_image_operate -i volume1.vol --minus volume2.vol -o volume3.vol");
366 addExampleLine(
"Multiply an image by 2 in every pixel:",
false);
367 addExampleLine(
"xmipp_image_operate -i image.xmp --mult 2 -o image2.xmp");
368 addExampleLine(
"Divide 2 by the value of every pixel in the image:",
false);
369 addExampleLine(
"xmipp_image_operate -i 2 -divide image.xmp -o image2.xmp");
370 addExampleLine(
" Rotational average",
false);
371 addExampleLine(
"xmipp_image_operate -i image.xmp --radial_avg -o radial_avg.xmp");
372 addExampleLine(
"where radial_avg.txt is an ascii file for plotting the radial_averaged profile, radial_avg.xmp a radial_averaged image",
false);
373 addExampleLine(
"xmipp_image_operate -i micrograph.psd --psd_radial_avg -o radial_psd.xmp");
374 addExampleLine(
"where radial_psd.txt is an ascii file for plotting the radial_averaged profile, radial_psd.xmp a radial_averaged image",
false);
380 binaryOperator =
nullptr;
381 unaryOperator =
nullptr;
385 if (checkParam(
"--plus"))
387 file_or_value = getParam(
"--plus");
388 binaryOperator =
plus;
390 else if (checkParam(
"--minus"))
392 file_or_value = getParam(
"--minus");
393 binaryOperator =
minus;
395 else if (checkParam(
"--minusAdjusted"))
397 file_or_value = getParam(
"--minusAdjusted");
400 else if (checkParam(
"--mult"))
402 file_or_value = getParam(
"--mult");
403 binaryOperator =
mult;
405 else if (checkParam(
"--divide"))
407 file_or_value = getParam(
"--divide");
410 else if (checkParam(
"--max"))
412 file_or_value = getParam(
"--max");
413 binaryOperator =
max;
415 else if (checkParam(
"--min"))
417 file_or_value = getParam(
"--min");
418 binaryOperator =
min;
420 else if (checkParam(
"--compare"))
422 file_or_value = getParam(
"--compare");
425 else if (checkParam(
"--dot_product"))
427 file_or_value = getParam(
"--dot_product");
430 else if (checkParam(
"--dropout"))
432 pDropout = getDoubleParam(
"--dropout");
436 else if (checkParam(
"--eq"))
438 file_or_value = getParam(
"--eq");
441 else if (checkParam(
"--ne"))
443 file_or_value = getParam(
"--ne");
446 else if (checkParam(
"--lt"))
448 file_or_value = getParam(
"--lt");
451 else if (checkParam(
"--le"))
453 file_or_value = getParam(
"--le");
456 else if (checkParam(
"--gt"))
458 file_or_value = getParam(
"--gt");
461 else if (checkParam(
"--ge"))
463 file_or_value = getParam(
"--ge");
467 else if (checkParam(
"--log10"))
468 unaryOperator =
log10;
469 else if (checkParam(
"--sqrt"))
470 unaryOperator =
sqrt;
471 else if (checkParam(
"--abs"))
473 else if (checkParam(
"--pow"))
476 unaryOperator =
power;
478 else if (checkParam(
"--slice"))
481 nSlice = getIntParam(
"--slice");
484 else if (checkParam(
"--column"))
487 nSlice = getIntParam(
"--column");
490 else if (checkParam(
"--row"))
493 nSlice = getIntParam(
"--row");
496 else if (checkParam(
"--radial_avg"))
501 else if (checkParam(
"--psd_radial_avg"))
506 else if (checkParam(
"--reset"))
509 unaryOperator =
reset;
511 else if (checkParam(
"--log"))
513 else if (checkParam(
"--log10"))
514 unaryOperator =
log10;
521 if (binaryOperator !=
nullptr)
523 if (!file_or_value.exists())
533 img2().resizeNoCopy(zdimOut, ydimOut, xdimOut);
534 img2().initConstant(value);
542 if (md2.isMetadataFile || md2.size() > 1)
544 if (mdInSize != md2.size())
549 md2IdIterator = memoryUtils::make_unique<MetaDataVec::id_iterator>(md2.ids().begin());
557 if (!dotProduct && checkParam(
"--dot_product"))
570 if (unaryOperator !=
nullptr)
576 img2.readApplyGeo(md2, **md2IdIterator);
579 binaryOperator(img, img2);
void radialAvg(Image< double > &op)
void min(Image< double > &op1, const Image< double > &op2)
void dropOut(Image< double > &op1)
void le(Image< double > &op1, const Image< double > &op2)
const MultidimArray< double > * I1
__host__ __device__ float2 floor(const float2 v)
void mult(Image< double > &op1, const Image< double > &op2)
void getSlice(int k, MultidimArray< T1 > &M, char axis='Z', bool reverse=false, size_t n=0) const
#define REPORT_ERROR(nerr, ErrormMsg)
void sqrt(Image< double > &op)
void plus(Image< double > &op1, const Image< double > &op2)
void ne(Image< double > &op1, const Image< double > &op2)
void reset(Image< double > &op)
void minusAdjusted(Image< double > &op1, const Image< double > &op2)
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)
void compare(Image< double > &op1, const Image< double > &op2)
void abs(Image< double > &op)
void readParams()
Read input parameters.
const FileName & name() const
void ge(Image< double > &op1, const Image< double > &op2)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
Process one image.
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
void gt(Image< double > &op1, const Image< double > &op2)
void defineParams()
Define parameters.
void CenterFFT(MultidimArray< T > &v, bool forward)
void minus(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
void log(Image< double > &op)
float textToFloat(const char *str)
Incorrect argument received.
void write(const FileName &fn) const
void eq(Image< double > &op1, const Image< double > &op2)
Be careful with integer images for relational operations...due to double comparisons.
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
void radialAverage(const MultidimArray< double > &VolFourierMag, const MultidimArray< double > &V, MultidimArray< double > &radial_mean)
#define DIRECT_MULTIDIM_ELEM(v, n)
void log10(Image< double > &op)
void psdRadialAvg(Image< double > &op)
void power(Image< double > &op)
FileName withoutExtension() const
T dotProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
const MultidimArray< double > * I2
double minusAdjusted_L1(double *x, void *_prm)
void imageDotProduct(Image< double > &op1, const Image< double > &op2)
void divide(Image< double > &op1, const Image< double > &op2)
Incorrect value received.
void lt(Image< double > &op1, const Image< double > &op2)
void getSlice(Image< double > &op)
__host__ __device__ float dot(float2 a, float2 b)