30 addUsageLine(
"Generate projections as in a X-ray microscope from a 3D Xmipp volume.");
35 addParamsLine(
" [--sampling_rate <Ts>] : Sampling rate of the volume to be projected (nm).");
36 addParamsLine(
" : If empty, same value as X-Y plane sampling from PSF.");
38 addParamsLine(
"[--psf <psf_param_file=\"\">] : XRay-Microscope parameters file. If not set, then default parameters are chosen.");
39 addParamsLine(
"[--focal_shift+ <delta_z=0.0>] : Shift along optical axis between the center of the phantom and the center of the psf in microns");
41 addParamsLine(
"[--threshold+ <thr=0.0>] : Normalized threshold relative to maximum of PSF to reduce the volume into slabs");
42 addParamsLine(
"[--std_proj] : Save also standard projections, adding _std suffix to filenames");
43 addParamsLine(
"[--thr <threads=1>] : Number of concurrent threads");
46 addExampleLine(
"In the following link you can find an example of projection parameter file:",
false);
48 addExampleLine(
"http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/tomoProjection.param?format=raw",
false);
50 addExampleLine(
"In the following link you can find an example of X-ray microscope parameters file:",
false);
52 addExampleLine(
"http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/xray_psf.xmd?format=raw",
false);
117 std::cerr <<
"Projecting ...\n";
121 projMD.
setComment(
"True rot, tilt and psi; rot, tilt, psi, X and Y shifts applied");
122 double tRot,tTilt,tPsi,rot,tilt,
psi;
185 std::cout <<
"N Rot Tilt Psi" <<std::endl;
186 std::cout << idx <<
"\t" <<
proj.
rot() <<
"\t" 189 else if ((expectedNumProjs %
XMIPP_MAX(1, numProjs / 60)) == 0 &&
verbose > 0)
201 projMD.
setComment(
"Angles rot,tilt and psi contain noisy projection angles and rot2,tilt2 and psi2 contain actual projection angles");
214 int iniXdim, iniYdim, iniZdim, newXdim, newYdim, newZdim, rotXdim, rotZdim;
255 newXdim = (int)(rotXdim + 2*fabs(
XX(offsetNV)));
256 newYdim = (int)(iniYdim + 2*fabs(
YY(offsetNV)));
266 if (newXdim != iniXdim || newYdim != iniYdim)
268 std::cout << std::endl;
269 std::cout <<
"--------------------------------" << std::endl;
270 std::cout <<
"XrayProject::Volume_offCentered:" << std::endl;
271 std::cout <<
"--------------------------------" << std::endl;
272 std::cout <<
"(X,Y,Z) shifts = (" <<
XX(offsetNV) <<
"," <<
YY(offsetNV) <<
"," 273 <<
ZZ(offsetNV) <<
") um" << std::endl;
274 std::cout <<
"Image resize (Nx,Ny): (" << iniXdim <<
"," << iniYdim <<
") --> (" 275 << newXdim <<
"," << newYdim <<
") " << std::endl;
279 std::cout <<
"yoffsetN "<<
YY(offsetNV) <<std::endl;
280 std::cout <<
"xoffsetN "<<
XX(offsetNV) <<std::endl;
281 std::cout <<
"yinit " << yinit <<std::endl;
282 std::cout <<
"yend " << yend <<std::endl;
283 std::cout <<
"xinit " << xinit <<std::endl;
284 std::cout <<
"xend " << xend <<std::endl;
285 std::cout <<
"zinit " << zinit <<std::endl;
286 std::cout <<
"zend " << zend <<std::endl;
327 P().selfWindow(-
ROUND(outYDim/2),
329 -
ROUND(outYDim/2) + outYDim -1,
330 -
ROUND(outXDim/2) + outXDim -1);
348 std::vector<int> phantomSlabIdx, psfSlicesIdx;
355 for (
size_t kk = 0; kk < psf.
slabIndex.size(); ++kk)
365 phantomSlabIdx.push_back(
STARTINGZ(muVol));
367 for (
size_t kk = firstSlab+1; kk < psf.
slabIndex.size(); ++kk)
373 phantomSlabIdx.push_back(tempK);
375 auto psfMeanSlice = (int)((tempK + tempKK)*0.5 * psf.
dzoPSF / psf.
dzo);
376 psfSlicesIdx.push_back(psfMeanSlice);
381 int psfMeanSlice = (tempK + phantomSlabIdx[kk-1])/2;
382 psfSlicesIdx.push_back(psfMeanSlice);
391 phantomSlabIdx.push_back(
k);
392 psfSlicesIdx.push_back(
k);
395 phantomSlabIdx.push_back(
FINISHINGZ(muVol)+1);
402 projThrData.
muVol = &muVol;
403 projThrData.
IgeoVol = &IgeoVol;
410 size_t blockSize, numberOfJobs = psfSlicesIdx.size() ;
413 projThrData.
td = &
td;
451 std::vector<int> &phantomSlabIdx = *(dataThread->phantomSlabIdx);
452 std::vector<int> &psfSlicesIdx = *(dataThread->psfSlicesIdx);
454 Barrier * barrier = dataThread->barrier;
456 size_t first = 0, last = 0;
469 imOut.setXmippOrigin();
474 imTemp.setXmippOrigin();
475 imTempSc.setXmippOrigin();
485 int kini = phantomSlabIdx[
first];
486 int kend = phantomSlabIdx[last + 1] - 1 ;
494 for (
int k = kini;
k <= kend;
k++)
503 _Im.
write(
"projectXR-intExp.spi");
506 _Im.
write(
"projectXR-imTemp.spi");
528 _Im().alias(*imTempP);
529 _Im.
write(
"projectXR-imTempEsc_before.spi");
536 _Im.
write(
"projectXR-imTempEsc_after.spi");
546 _Im.
write(
"projectXR-imout.spi");
551 if (projNorm !=
nullptr)
572 if (projNorm !=
nullptr)
580 imOutGlobal.
write(
"projectXR-imoutGlobal.spi");
607 imOutGlobal.
write(
"projectXR-imoutGlobal_negative.spi");
629 if (ThrMgr ==
nullptr)
636 iGeoArgs.
muVol = &muVol;
638 iGeoArgs.
cumMu = &cumMu;
639 iGeoArgs.
IgeoZb = & IgeoZb;
646 if (ThrMgr ==
nullptr)
654 double sampling = dataThread->samplingZ;
669 for (
size_t i = first;
i <= last; ++
i)
678 for (
size_t k = 0;
k <
ZSIZE(muVol); ++
k)
679 for (
size_t j=0;
j<
XSIZE(muVol); ++
j)
704 projThrData.
muVol = &muVol;
705 projThrData.
IgeoVol = &IgeoVol;
708 projThrData.
forw = FORW;
737 int forw = dataThread->forw;
750 int threadId,
int numthreads)
781 double XX_footprint_size;
782 double YY_footprint_size;
788 int XX_corner2, XX_corner1;
789 int YY_corner2, YY_corner1;
841 ZZ_lowest += threadId;
848 beginZ = (double)XX_lowest * prjX + (
double)YY_lowest * prjY + (double)ZZ_lowest * prjZ + prjOrigin;
854 condition = threadId==1;
855 if (condition || numthreads==1)
857 std::cout <<
"Equation mode " << eq_mode << std::endl;
858 std::cout <<
"Footprint size " << YY_footprint_size <<
"x" 859 << XX_footprint_size << std::endl;
860 std::cout <<
"rot=" << proj->
rot() <<
" tilt=" << proj->
tilt()
861 <<
" psi=" << proj->
psi() << std::endl;
862 std::cout <<
"Euler matrix " << proj->
euler;
863 std::cout <<
"Projection direction " << prjDir << std::endl;
865 std::cout <<
"image limits (" <<
x0 <<
"," <<
y0 <<
") (" <<
xF <<
"," 867 std::cout <<
"prjX " << prjX.
transpose() << std::endl;
868 std::cout <<
"prjY " << prjY.
transpose() << std::endl;
869 std::cout <<
"prjZ " << prjZ.
transpose() << std::endl;
870 std::cout <<
"prjOrigin " << prjOrigin.
transpose() << std::endl;
871 std::cout <<
"beginZ(coord) " << beginZ.
transpose() << std::endl;
872 std::cout <<
"lowest " << XX_lowest <<
" " << YY_lowest
873 <<
" " << XX_lowest << std::endl;
874 std::cout <<
"highest " << XX_highest <<
" " << YY_highest
875 <<
" " << XX_highest << std::endl;
876 std::cout <<
"Stats of input basis volume ";
877 (*vol)().printStats();
878 std::cout << std::endl;
883 for (k = ZZ_lowest; k <= ZZ_highest; k += numthreads)
887 for (i = YY_lowest; i <= YY_highest; i++)
891 for (j = XX_lowest; j <= XX_highest; j++)
894 bool ray_length_interesting =
true;
900 if (ray_length_interesting)
905 condition = threadId == 1;
908 printf(
"\nProjecting grid coord (%d,%d,%d) ", j, i, k);
909 std::cout <<
"Vol there = " <<
A3D_ELEM(*vol, k, i, j) << std::endl;
910 printf(
" 3D universal position (%f,%f,%f) \n",
911 XX(univ_position),
YY(univ_position),
ZZ(univ_position));
912 std::cout <<
" Center of the basis proj (2D) " <<
XX(actprj) <<
"," <<
YY(actprj) << std::endl;
915 std::cout <<
" Center of the basis proj (more accurate) " << aux.
transpose() << std::endl;
929 std::cout <<
"Clipped and rounded Corner 1 " << XX_corner1
930 <<
" " << YY_corner1 <<
" " << std::endl;
931 std::cout <<
"Clipped and rounded Corner 2 " << XX_corner2
932 <<
" " << YY_corner2 <<
" " << std::endl;
938 if (XX_corner1 <= XX_corner2 && YY_corner1 <= YY_corner2
942 double IgeoValue =
A3D_ELEM(*IgeoVol, (
int)
ZZ(actprj), (
int)
YY(actprj), (
int)
XX(actprj));
948 for (
int y = YY_corner1;
y <= YY_corner2;
y++)
950 for (
int x = XX_corner1;
x <= XX_corner2;
x++)
957 std::cout <<
"Position in projection (" <<
x <<
"," 962 std::cout <<
"in footprint (" 963 << foot_U <<
"," << foot_V <<
")";
964 IMG2OVER(basis->blobprint, foot_V, foot_U, y, x);
965 std::cout <<
" (d= " <<
sqrt(y*y + x*x) <<
") ";
973 a =
A3D_ELEM(psfVol, (
int)
ZZ(actprj),
y,
x) * IgeoValue;
979 std::cout <<
"=" << a <<
" , " << a2;
992 std::cout <<
" proj= " <<
IMGPIXEL(*proj,
y,
x)
993 <<
" norm_proj=" <<
A2D_ELEM(projNorm ,
y,
x) << std::endl;
1008 std::cout <<
" corr_img= " <<
A2D_ELEM(projNorm ,
y,
x)
1009 <<
" correction=" << vol_corr << std::endl;
1021 A3D_ELEM(*vol, k, i, j) += vol_corr;
1027 printf(
"\nFinal value at (%d,%d,%d) ", j, i, k);
1028 std::cout <<
" = " <<
A3D_ELEM(*vol, k, i, j) << std::endl;
1043 V3_PLUS_V3(beginZ, beginZ, prjZ * numthreads );
void run(ThreadFunction function, void *data=NULL)
bool only_create_angles
Only create angles, do not project.
void threadXrayProject(ThreadArgument &thArg)
Generate an X-ray microscope projection for volume vol using the microscope configuration psf...
void init_progress_bar(long total)
void defineParams(XmippProgram *program)
#define A2D_ELEM(v, i, j)
double Npixel_dev
Standard deviation of the noise to be added to each pixel grey value.
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
FileName fnOut
Output filename (used for a singleProjection)
ParametersProjectionTomography projParam
double getDoubleParam(const char *param, int arg=0)
virtual void read(int argc, const char **argv, bool reportErrors=true)
#define REPORT_ERROR(nerr, ErrormMsg)
double psi(const size_t n=0) const
void projectXraySimpleGridThread(ThreadArgument &thArg)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
Data struct to be passed to threads.
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
double Zoff(const size_t n=0) const
void resizeNoCopy(const MultidimArray< T1 > &v)
void applyOTF(MultidimArray< double > &Im, const double sliceOffset) const
Apply the OTF to the image, by means of the convolution.
MultidimArray< double > * IgeoVol
double tilt0
Minimum tilt around this axis.
void sqrt(Image< double > &op)
virtual void defineParams()
FileName insertBeforeExtension(const String &str) const
bool getTasks(size_t &first, size_t &last)
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)
int threads
number of working threads.
#define MULTIDIM_ARRAY(v)
void projectXrayVolume(MultidimArray< double > &muVol, MultidimArray< double > &IgeoVol, XRayPSF &psf, Projection &P, MultidimArray< double > *projNorm, ThreadManager *thMgr)
void compose(const String &str, const size_t no, const String &ext="")
void XrayRotateAndProjectVolumeOffCentered(XrayProjPhantom &phantom, XRayPSF &psf, Projection &P, Projection &standardP, int Ydim, int Xdim)
void readParams(XmippProgram *program)
Image< double > iniVol
Phantom Xmipp volume.
Image< double > psfVol
3D PSF read from file
void setFocalShift(double zShift)
Add focal shift to previously read psf zshift.
Incorrect MultidimArray size.
double rot(const size_t n=0) const
ParallelTaskDistributor * td
MultidimArray< double > * projNorm
double dxo
object space XY-plane sampling rate
double tiltF
Maximum tilt around this axis.
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
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
Matrix1D< T > transpose() const
void addSeeAlsoLine(const char *seeAlso)
double tilt(const size_t n=0) const
std::vector< int > * phantomSlabIdx
std::vector< int > * psfSlicesIdx
Matrix1D< double > raxis
Offset of the tilt axis.
#define A3D_ELEM(V, k, i, j)
Standard mode, image size does not changes.
void projectXrayGridVolume(MultidimArray< double > &muVol, XRayPSF &psf, MultidimArray< double > &IgeoVol, Projection &proj, MultidimArray< double > *projNorm, int FORW, ThreadManager *thMgr)
Project as in an X-ray microscope using a grids and blobs.
double Npixel_avg
Bias to be applied to each pixel grey value */.
int proj_Ydim
Projection Ydim.
FileName fn_psf_xr
Filename with the Microscope Parameters.
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
const char * getParam(const char *param, int arg=0)
std::vector< int > slabIndex
Z positions in the original PSF Volume to determine de slabs.
ParallelTaskDistributor * td
Intensity in the beginning of the volume to project.
void read(const FileName &fn, bool readVolume=true)
bool save_std_projs
Save standard projections.
ParallelTaskDistributor * td
double Ncenter_avg
Bias to apply to the image center.
double Ncenter_dev
Standard deviation of the image center.
size_t Nix
Size of the image in image plane, to be rescaled if needed.
#define XMIPP_EQUAL_ACCURACY
double psfThr
threshold for psfSlabs
#define IMG2OVER(IO, iv, iu, v, u)
void progress_bar(long rlen)
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
void projectXraySimpleGrid(MultidimArray< double > *vol, const XRayPSF &psf, MultidimArray< double > *IgeoVol, Projection *proj, MultidimArray< double > &projNorm, int FORW, int threadId, int numthreads)
#define dAkij(V, k, i, j)
int threads
Number of threads.
MultidimArray< double > * muVol
void addExampleLine(const char *example, bool verbatim=true)
virtual void readParams()
double Nangle_dev
Standard deviation of the angles.
int verbose
Switch to control verbose mode.
double slabThr
Threshold to separate The volume into slabs to use the same PSF.
void calculateIgeoThread(ThreadArgument &thArg)
#define XMIPP_EQUAL_ZERO(x)
int verbose
Verbosity level.
int proj_Xdim
Projection Xdim.
void alias(const MultidimArray< T > &m)
void calculateProjectionAngles(Projection &P, double angle, double inplaneRot, const Matrix1D< double > &sinplane)
void calculateParams(double _dxo, double _dzo=-1, double threshold=0.)
Produce Side information.
FileName fnRoot
Root filename (used for a stack)
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)
void getCol(size_t j, Matrix1D< T > &v) const
MultidimArray< double > * IgeoVol
Accumulated Mu == Standard EM projection used as reference for reconstruction.
int nThr
Number of threads;.
void adjustParam()
Calculate if a resize of the X-Y plane is needed to avoid the Nyquist Limit.
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
size_t Nox
X size of the input image (object plane size)
void read(const ParametersProjectionTomography &prm)
Increasing the image size by Interpolating.
MultidimArray< double > * muVol
bool singleProjection
Only project a single image.
double psi(const double x)
#define VECTOR_R3(v, x, y, z)
double dzo
object space Z sampling rate
int thread_id
The thread id.
double dzoPSF
object space Z sampling rate of the PSF Volume
bool checkParam(const char *param)
MultidimArray< double > * IgeoZb
Igeo accumulated along Z axis.
PsfxrAdjust AdjustType
Parameters to change image size to avoid Nyquist limit.
double tiltStep
Step in tilt.
MultidimArray< double > * cumMu
Phantom volume.
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
unsigned int randomize_random_generator()
MultidimArray< double > rotVol
void calculateIgeo(MultidimArray< double > &muVol, double sampling, MultidimArray< double > &IgeoVol, MultidimArray< double > &cumMu, MultidimArray< double > &IgeoZb, int nThreads, ThreadManager *ThrMgr)
Calculate the volume of the information of Igeometric at each plane of the phantom.
int getIntParam(const char *param, int arg=0)
void getRow(size_t i, Matrix1D< T > &v) const
void Uproject_to_plane(const Matrix1D< double > &point, const Matrix1D< double > &direction, double distance, Matrix1D< double > &result)
size_t Noy
Y size of the input image (object plane size)
void addParamsLine(const String &line)
double Nangle_avg
Bias to apply to the angles.
ql0001_ & zero(ctemp+1),(cvec+1),(a+1),(b+1),(bl+1),(bu+1),(x+1),(w+1), &iout, ifail, &zero,(w+3), &lwar2,(iw+1), &leniw, &glob_grd.epsmac
#define V3_PLUS_V3(a, b, c)
#define IMGPIXEL(I, i, j)
void getShifts(double &xoff, double &yoff, double &zoff, const size_t n=0) const