本文整理汇总了C++中MultidimArray::setXmippOrigin方法的典型用法代码示例。如果您正苦于以下问题:C++ MultidimArray::setXmippOrigin方法的具体用法?C++ MultidimArray::setXmippOrigin怎么用?C++ MultidimArray::setXmippOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultidimArray
的用法示例。
在下文中一共展示了MultidimArray::setXmippOrigin方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/* Filter generation ------------------------------------------------------- */
void Steerable::generate1DFilters(double sigma,
const MultidimArray<double> &Vtomograph,
std::vector< MultidimArray<double> > &hx1,
std::vector< MultidimArray<double> > &hy1,
std::vector< MultidimArray<double> > &hz1){
// Initialization
MultidimArray<double> aux;
aux.initZeros(XSIZE(Vtomograph));
aux.setXmippOrigin();
for (int i=0; i<6; i++) hx1.push_back(aux);
aux.initZeros(YSIZE(Vtomograph));
aux.setXmippOrigin();
for (int i=0; i<6; i++) hy1.push_back(aux);
aux.initZeros(ZSIZE(Vtomograph));
aux.setXmippOrigin();
for (int i=0; i<6; i++) hz1.push_back(aux);
double sigma2=sigma*sigma;
double k1 = 1.0/pow((2.0*PI*sigma),(3.0/2.0));
double k2 = -1.0/(sigma2);
FOR_ALL_ELEMENTS_IN_ARRAY1D(hx1[0])
{
double i2=i*i;
double g = -exp(-i2/(2.0*sigma2));
hx1[0](i) = k1*k2*g*(1.0-(i2/sigma2));
hx1[1](i) = k1*k2*g;
hx1[2](i) = k1*k2*g;
hx1[3](i) = k1*k2*k2*g*i;
hx1[4](i) = k1*k2*k2*g*i;
hx1[5](i) = k1*k2*k2*g;
}
FOR_ALL_ELEMENTS_IN_ARRAY1D(hy1[0])
{
double i2=i*i;
double g = -exp(-i2/(2.0*sigma2));
hy1[0](i) = g;
hy1[1](i) = g*(1.0-(i2/sigma2));
hy1[2](i) = g;
hy1[3](i) = g*i;
hy1[4](i) = g;
hy1[5](i) = g*i;
}
FOR_ALL_ELEMENTS_IN_ARRAY1D(hz1[0])
{
double i2=i*i;
double g = -exp(-i2/(2.0*sigma2));
hz1[0](i) = g;
hz1[1](i) = g;
hz1[2](i) = g*(1.0-(i2/sigma2));
hz1[3](i) = g;
hz1[4](i) = g*i;
hz1[5](i) = g*i;
}
}
示例2: symmetriseMap
void symmetriseMap(MultidimArray<DOUBLE> &img, FileName &fn_sym, bool do_wrap)
{
if (img.getDim() != 3)
REPORT_ERROR("symmetriseMap ERROR: symmetriseMap can only be run on 3D maps!");
img.setXmippOrigin();
SymList SL;
SL.read_sym_file(fn_sym);
Matrix2D<DOUBLE> L(4, 4), R(4, 4); // A matrix from the list
MultidimArray<DOUBLE> sum, aux;
sum = img;
aux.resize(img);
for (int isym = 0; isym < SL.SymsNo(); isym++)
{
SL.get_matrices(isym, L, R);
applyGeometry(img, aux, R, IS_INV, do_wrap);
sum += aux;
}
// Overwrite the input
img = sum / (SL.SymsNo() + 1);
}
示例3: FourierProjector
/* Constructor */
PyObject *
FourierProjector_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
FourierProjectorObject *self = (FourierProjectorObject*) type->tp_alloc(type, 0);
XMIPP_TRY
if (self != NULL)
{
PyObject *image = NULL;
double padding_factor, max_freq, spline_degree;
if (PyArg_ParseTuple(args, "O|ddd", &image, &padding_factor, &max_freq, &spline_degree))
{
Image_Value(image).getDimensions(self->dims);
MultidimArray<double> *pdata;
Image_Value(image).data->getMultidimArrayPointer(pdata);
pdata->setXmippOrigin();
self->fourier_projector = new FourierProjector(*(pdata), padding_factor, max_freq, spline_degree);
}
}
XMIPP_CATCH
return (PyObject *) self;
}
示例4: griddingCorrect
void Projector::griddingCorrect(MultidimArray<DOUBLE> &vol_in)
{
// Correct real-space map by dividing it by the Fourier transform of the interpolator(s)
vol_in.setXmippOrigin();
FOR_ALL_ELEMENTS_IN_ARRAY3D(vol_in)
{
DOUBLE r = sqrt((DOUBLE)(k*k+i*i+j*j));
// if r==0: do nothing (i.e. divide by 1)
if (r > 0.)
{
DOUBLE rval = r / (ori_size * padding_factor);
DOUBLE sinc = sin(PI * rval) / ( PI * rval);
//DOUBLE ftblob = blob_Fourier_val(rval, blob) / blob_Fourier_val(0., blob);
// Interpolation (goes with "interpolator") to go from arbitrary to fine grid
if (interpolator==NEAREST_NEIGHBOUR && r_min_nn == 0)
{
// NN interpolation is convolution with a rectangular pulse, which FT is a sinc function
A3D_ELEM(vol_in, k, i, j) /= sinc;
}
else if (interpolator==TRILINEAR || (interpolator==NEAREST_NEIGHBOUR && r_min_nn > 0) )
{
// trilinear interpolation is convolution with a triangular pulse, which FT is a sinc^2 function
A3D_ELEM(vol_in, k, i, j) /= sinc * sinc;
}
else
REPORT_ERROR("BUG Projector::griddingCorrect: unrecognised interpolator scheme.");
//#define DEBUG_GRIDDING_CORRECT
#ifdef DEBUG_GRIDDING_CORRECT
if (k==0 && i==0 && j > 0)
std::cerr << " j= " << j << " sinc= " << sinc << std::endl;
#endif
}
}
}
示例5: produceSideInfo
void FourierProjector::produceSideInfo()
{
// Zero padding
MultidimArray<double> Vpadded;
int paddedDim=(int)(paddingFactor*volumeSize);
// JMRT: TODO: I think it is a very poor design to modify the volume passed
// in the construct, it will be padded anyway, so new memory should be allocated
volume->window(Vpadded,FIRST_XMIPP_INDEX(paddedDim),FIRST_XMIPP_INDEX(paddedDim),FIRST_XMIPP_INDEX(paddedDim),
LAST_XMIPP_INDEX(paddedDim),LAST_XMIPP_INDEX(paddedDim),LAST_XMIPP_INDEX(paddedDim));
volume->clear();
// Make Fourier transform, shift the volume origin to the volume center and center it
MultidimArray< std::complex<double> > Vfourier;
transformer3D.completeFourierTransform(Vpadded,Vfourier);
ShiftFFT(Vfourier, FIRST_XMIPP_INDEX(XSIZE(Vpadded)), FIRST_XMIPP_INDEX(YSIZE(Vpadded)), FIRST_XMIPP_INDEX(ZSIZE(Vpadded)));
CenterFFT(Vfourier,true);
Vfourier.setXmippOrigin();
// Compensate for the Fourier normalization factor
double K=(double)(XSIZE(Vpadded)*XSIZE(Vpadded)*XSIZE(Vpadded))/(double)(volumeSize*volumeSize);
FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(Vfourier)
DIRECT_MULTIDIM_ELEM(Vfourier,n)*=K;
Vpadded.clear();
// Compute Bspline coefficients
if (BSplineDeg==3)
{
MultidimArray< double > VfourierRealAux, VfourierImagAux;
Complex2RealImag(Vfourier, VfourierRealAux, VfourierImagAux);
Vfourier.clear();
produceSplineCoefficients(BSPLINE3,VfourierRealCoefs,VfourierRealAux);
produceSplineCoefficients(BSPLINE3,VfourierImagCoefs,VfourierImagAux);
//VfourierRealAux.clear();
//VfourierImagAux.clear();
}
else
Complex2RealImag(Vfourier, VfourierRealCoefs, VfourierImagCoefs);
// Allocate memory for the 2D Fourier transform
projection().initZeros(volumeSize,volumeSize);
projection().setXmippOrigin();
transformer2D.FourierTransform(projection(),projectionFourier,false);
// Calculate phase shift terms
phaseShiftImgA.initZeros(projectionFourier);
phaseShiftImgB.initZeros(projectionFourier);
double shift=-FIRST_XMIPP_INDEX(volumeSize);
double xxshift = -2 * PI * shift / volumeSize;
for (size_t i=0; i<YSIZE(projectionFourier); ++i)
{
double phasey=(double)(i) * xxshift;
for (size_t j=0; j<XSIZE(projectionFourier); ++j)
{
// Phase shift to move the origin of the image to the corner
double dotp = (double)(j) * xxshift + phasey;
sincos(dotp,&DIRECT_A2D_ELEM(phaseShiftImgB,i,j),&DIRECT_A2D_ELEM(phaseShiftImgA,i,j));
}
}
}
示例6: getCenteredImage
void CTF::getCenteredImage(MultidimArray<DOUBLE> &result, DOUBLE Tm,
bool do_abs, bool do_only_flip_phases, bool do_intact_until_first_peak, bool do_damping)
{
result.setXmippOrigin();
DOUBLE xs = (DOUBLE)XSIZE(result) * Tm;
DOUBLE ys = (DOUBLE)YSIZE(result) * Tm;
FOR_ALL_ELEMENTS_IN_ARRAY2D(result)
{
DOUBLE x = (DOUBLE)j / xs;
DOUBLE y = (DOUBLE)i / ys;
A2D_ELEM(result, i, j) = getCTF(x, y, do_abs, do_only_flip_phases, do_intact_until_first_peak, do_damping);
}
}
示例7: produceSideInfo
void FourierProjector::produceSideInfo()
{
// Zero padding
MultidimArray<double> Vpadded;
int paddedDim=(int)(paddingFactor*volumeSize);
volume->window(Vpadded,FIRST_XMIPP_INDEX(paddedDim),FIRST_XMIPP_INDEX(paddedDim),FIRST_XMIPP_INDEX(paddedDim),
LAST_XMIPP_INDEX(paddedDim),LAST_XMIPP_INDEX(paddedDim),LAST_XMIPP_INDEX(paddedDim));
volume->clear();
// Make Fourier transform, shift the volume origin to the volume center and center it
MultidimArray< std::complex<double> > Vfourier;
transformer3D.completeFourierTransform(Vpadded,Vfourier);
ShiftFFT(Vfourier, FIRST_XMIPP_INDEX(XSIZE(Vpadded)), FIRST_XMIPP_INDEX(YSIZE(Vpadded)), FIRST_XMIPP_INDEX(ZSIZE(Vpadded)));
CenterFFT(Vfourier,true);
Vfourier.setXmippOrigin();
// Compensate for the Fourier normalization factor
double K=(double)(XSIZE(Vpadded)*XSIZE(Vpadded)*XSIZE(Vpadded))/(double)(volumeSize*volumeSize);
FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(Vfourier)
DIRECT_MULTIDIM_ELEM(Vfourier,n)*=K;
Vpadded.clear();
// Compute Bspline coefficients
if (BSplineDeg==3)
{
MultidimArray< double > VfourierRealAux, VfourierImagAux;
Complex2RealImag(Vfourier, VfourierRealAux, VfourierImagAux);
Vfourier.clear();
produceSplineCoefficients(BSPLINE3,VfourierRealCoefs,VfourierRealAux);
produceSplineCoefficients(BSPLINE3,VfourierImagCoefs,VfourierImagAux);
//VfourierRealAux.clear();
//VfourierImagAux.clear();
}
else
Complex2RealImag(Vfourier, VfourierRealCoefs, VfourierImagCoefs);
// Allocate memory for the 2D Fourier transform
projection().initZeros(volumeSize,volumeSize);
projection().setXmippOrigin();
transformer2D.FourierTransform(projection(),projectionFourier,false);
}
示例8: normalize_tomography
//#define DEBUG
void normalize_tomography(MultidimArray<double> &I, double tilt, double &mui,
double &sigmai, bool tiltMask, bool tomography0,
double mu0, double sigma0)
{
// Tilt series are always 2D
I.checkDimension(2);
const int L=2;
// Build a mask using the tilt angle
I.setXmippOrigin();
MultidimArray<int> mask;
mask.initZeros(I);
int Xdimtilt=(int)XMIPP_MIN(FLOOR(0.5*(XSIZE(I)*cos(DEG2RAD(tilt)))),
0.5*(XSIZE(I)-(2*L+1)));
int N=0;
for (int i=STARTINGY(I); i<=FINISHINGY(I); i++)
for (int j=-Xdimtilt; j<=Xdimtilt;j++)
{
A2D_ELEM(mask,i,j)=1;
N++;
}
// Estimate the local variance
MultidimArray<double> localVariance;
localVariance.initZeros(I);
double meanVariance=0;
FOR_ALL_ELEMENTS_IN_ARRAY2D(I)
{
// Center a mask of size 5x5 and estimate the variance within the mask
double meanPiece=0, variancePiece=0;
double Npiece=0;
for (int ii=i-L; ii<=i+L; ii++)
{
if (INSIDEY(I,ii))
for (int jj=j-L; jj<=j+L; jj++)
{
if (INSIDEX(I,jj))
{
double pixval=A2D_ELEM(I,ii,jj);
meanPiece+=pixval;
variancePiece+=pixval*pixval;
++Npiece;
}
}
}
meanPiece/=Npiece;
variancePiece=variancePiece/(Npiece-1)-
Npiece/(Npiece-1)*meanPiece*meanPiece;
A2D_ELEM(localVariance,i,j)=variancePiece;
meanVariance+=variancePiece;
}
meanVariance*=1.0/N;
// Test the hypothesis that the variance in this piece is
// the same as the variance in the whole image
double iFu=1/icdf_FSnedecor(4*L*L+4*L,N-1,0.975);
double iFl=1/icdf_FSnedecor(4*L*L+4*L,N-1,0.025);
double iMeanVariance=1.0/meanVariance;
FOR_ALL_ELEMENTS_IN_ARRAY2D(localVariance)
{
if (A2D_ELEM(localVariance,i,j)==0)
A2D_ELEM(mask,i,j)=-2;
if (A2D_ELEM(mask,i,j)==1)
{
double ratio=A2D_ELEM(localVariance,i,j)*iMeanVariance;
double thl=ratio*iFu;
double thu=ratio*iFl;
if (thl>1 || thu<1)
A2D_ELEM(mask,i,j)=-1;
}
}
#ifdef DEBUG
Image<double> save;
save()=I;
save.write("PPP.xmp");
save()=localVariance;
save.write("PPPLocalVariance.xmp");
Image<int> savemask;
savemask()=mask;
savemask.write("PPPmask.xmp");
#endif
// Compute the statistics again in the reduced mask
double avg, stddev, min, max;
computeStats_within_binary_mask(mask, I, min, max, avg, stddev);
double cosTilt=cos(DEG2RAD(tilt));
double iCosTilt=1.0/cosTilt;
if (tomography0)
{
double iadjustedStddev=1.0/(sigma0*cosTilt);
FOR_ALL_ELEMENTS_IN_ARRAY2D(I)
switch (A2D_ELEM(mask,i,j))
{
case -2:
A2D_ELEM(I,i,j)=0;
break;
case 0:
if (tiltMask)
//.........这里部分代码省略.........
示例9: computeFourierTransformMap
// Fill data array with oversampled Fourier transform, and calculate its power spectrum
void Projector::computeFourierTransformMap(MultidimArray<DOUBLE> &vol_in, MultidimArray<DOUBLE> &power_spectrum, int current_size, int nr_threads, bool do_gridding)
{
MultidimArray<DOUBLE> Mpad;
MultidimArray<Complex > Faux;
FourierTransformer transformer;
// DEBUGGING: multi-threaded FFTWs are giving me a headache?
// For a long while: switch them off!
//transformer.setThreadsNumber(nr_threads);
DOUBLE normfft;
// Size of padded real-space volume
int padoridim = padding_factor * ori_size;
// Initialize data array of the oversampled transform
ref_dim = vol_in.getDim();
// Make Mpad
switch (ref_dim)
{
case 2:
Mpad.initZeros(padoridim, padoridim);
normfft = (DOUBLE)(padding_factor * padding_factor);
break;
case 3:
Mpad.initZeros(padoridim, padoridim, padoridim);
if (data_dim ==3)
normfft = (DOUBLE)(padding_factor * padding_factor * padding_factor);
else
normfft = (DOUBLE)(padding_factor * padding_factor * padding_factor * ori_size);
break;
default:
REPORT_ERROR("Projector::computeFourierTransformMap%%ERROR: Dimension of the data array should be 2 or 3");
}
// First do a gridding pre-correction on the real-space map:
// Divide by the inverse Fourier transform of the interpolator in Fourier-space
// 10feb11: at least in 2D case, this seems to be the wrong thing to do!!!
// TODO: check what is best for subtomo!
if (do_gridding)// && data_dim != 3)
griddingCorrect(vol_in);
// Pad translated map with zeros
vol_in.setXmippOrigin();
Mpad.setXmippOrigin();
FOR_ALL_ELEMENTS_IN_ARRAY3D(vol_in) // This will also work for 2D
A3D_ELEM(Mpad, k, i, j) = A3D_ELEM(vol_in, k, i, j);
// Translate padded map to put origin of FT in the center
CenterFFT(Mpad, true);
// Calculate the oversampled Fourier transform
transformer.FourierTransform(Mpad, Faux, false);
// Free memory: Mpad no longer needed
Mpad.clear();
// Resize data array to the right size and initialise to zero
initZeros(current_size);
// Fill data only for those points with distance to origin less than max_r
// (other points will be zero because of initZeros() call above
// Also calculate radial power spectrum
power_spectrum.initZeros(ori_size / 2 + 1);
MultidimArray<DOUBLE> counter(power_spectrum);
counter.initZeros();
int max_r2 = r_max * r_max * padding_factor * padding_factor;
FOR_ALL_ELEMENTS_IN_FFTW_TRANSFORM(Faux) // This will also work for 2D
{
int r2 = kp*kp + ip*ip + jp*jp;
// The Fourier Transforms are all "normalised" for 2D transforms of size = ori_size x ori_size
if (r2 <= max_r2)
{
// Set data array
A3D_ELEM(data, kp, ip, jp) = DIRECT_A3D_ELEM(Faux, k, i, j) * normfft;
// Calculate power spectrum
int ires = ROUND( sqrt((DOUBLE)r2) / padding_factor );
// Factor two because of two-dimensionality of the complex plane
DIRECT_A1D_ELEM(power_spectrum, ires) += norm(A3D_ELEM(data, kp, ip, jp)) / 2.;
DIRECT_A1D_ELEM(counter, ires) += 1.;
}
}
// Calculate radial average of power spectrum
FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(power_spectrum)
{
if (DIRECT_A1D_ELEM(counter, i) < 1.)
DIRECT_A1D_ELEM(power_spectrum, i) = 0.;
else
DIRECT_A1D_ELEM(power_spectrum, i) /= DIRECT_A1D_ELEM(counter, i);
}
transformer.cleanup();
}
示例10: processInprocessInputPrepareSPTH
//majorAxis and minorAxis is the estimated particle size in px
void ProgSortByStatistics::processInprocessInputPrepareSPTH(MetaData &SF, bool trained)
{
//#define DEBUG
PCAMahalanobisAnalyzer tempPcaAnalyzer0;
PCAMahalanobisAnalyzer tempPcaAnalyzer1;
PCAMahalanobisAnalyzer tempPcaAnalyzer2;
PCAMahalanobisAnalyzer tempPcaAnalyzer3;
PCAMahalanobisAnalyzer tempPcaAnalyzer4;
//Morphology
tempPcaAnalyzer0.clear();
//Signal to noise ratio
tempPcaAnalyzer1.clear();
tempPcaAnalyzer2.clear();
tempPcaAnalyzer3.clear();
//Histogram analysis, to detect black points and saturated parts
tempPcaAnalyzer4.clear();
double sign = 1;//;-1;
int numNorm = 3;
int numDescriptors0=numNorm;
int numDescriptors2=4;
int numDescriptors3=11;
int numDescriptors4 = 10;
MultidimArray<float> v0(numDescriptors0);
MultidimArray<float> v2(numDescriptors2);
MultidimArray<float> v3(numDescriptors3);
MultidimArray<float> v4(numDescriptors4);
if (verbose>0)
{
std::cout << " Sorting particle set by new xmipp method..." << std::endl;
}
int nr_imgs = SF.size();
if (verbose>0)
init_progress_bar(nr_imgs);
int c = XMIPP_MAX(1, nr_imgs / 60);
int imgno = 0, imgnoPCA=0;
bool thereIsEnable=SF.containsLabel(MDL_ENABLED);
bool first=true;
// We assume that at least there is one particle
size_t Xdim, Ydim, Zdim, Ndim;
getImageSize(SF,Xdim,Ydim,Zdim,Ndim);
//Initialization:
MultidimArray<double> nI, modI, tempI, tempM, ROI;
MultidimArray<bool> mask;
nI.resizeNoCopy(Ydim,Xdim);
modI.resizeNoCopy(Ydim,Xdim);
tempI.resizeNoCopy(Ydim,Xdim);
tempM.resizeNoCopy(Ydim,Xdim);
mask.resizeNoCopy(Ydim,Xdim);
mask.initConstant(true);
MultidimArray<double> autoCorr(2*Ydim,2*Xdim);
MultidimArray<double> smallAutoCorr;
Histogram1D hist;
Matrix2D<double> U,V,temp;
Matrix1D<double> D;
MultidimArray<int> radial_count;
MultidimArray<double> radial_avg;
Matrix1D<int> center(2);
MultidimArray<int> distance;
int dim;
center.initZeros();
v0.initZeros(numDescriptors0);
v2.initZeros(numDescriptors2);
v3.initZeros(numDescriptors3);
v4.initZeros(numDescriptors4);
ROI.resizeNoCopy(Ydim,Xdim);
ROI.setXmippOrigin();
FOR_ALL_ELEMENTS_IN_ARRAY2D(ROI)
{
double temp = std::sqrt(i*i+j*j);
if ( temp < (Xdim/2))
A2D_ELEM(ROI,i,j)= 1;
else
A2D_ELEM(ROI,i,j)= 0;
}
Image<double> img;
FourierTransformer transformer(FFTW_BACKWARD);
FOR_ALL_OBJECTS_IN_METADATA(SF)
{
if (thereIsEnable)
{
int enabled;
SF.getValue(MDL_ENABLED,enabled,__iter.objId);
if ( (enabled==-1) )
//.........这里部分代码省略.........
示例11: fit
void PolyZernikes::fit(const Matrix1D<int> & coef, MultidimArray<double> & im, MultidimArray<double> &weight,
MultidimArray<bool> & ROI, int verbose)
{
this->create(coef);
size_t xdim = XSIZE(im);
size_t ydim = YSIZE(im);
//int numZer = (size_t)coef.sum();
int numZer = (size_t)coef.sum();
//Actually polOrder corresponds to the polynomial order +1
int polOrder=(int)ZERNIKE_ORDER(coef.size());
im.setXmippOrigin();
Matrix2D<double> polValue(polOrder,polOrder);
//First argument means number of images
//Second argument means number of pixels
WeightedLeastSquaresHelper weightedLeastSquaresHelper;
Matrix2D<double>& zerMat=weightedLeastSquaresHelper.A;
zerMat.resizeNoCopy((size_t)ROI.sum(), numZer);
double iMaxDim2 = 2./std::max(xdim,ydim);
size_t pixel_idx=0;
weightedLeastSquaresHelper.b.resizeNoCopy((size_t)ROI.sum());
weightedLeastSquaresHelper.w.resizeNoCopy(weightedLeastSquaresHelper.b);
FOR_ALL_ELEMENTS_IN_ARRAY2D(im)
{
if ( (A2D_ELEM(ROI,i,j)))
{
//For one i we swap the different j
double y=i*iMaxDim2;
double x=j*iMaxDim2;
//polValue = [ 0 y y2 y3 ...
// x xy xy2 xy3 ...
// x2 x2y x2y2 x2y3 ]
//dMij(polValue,py,px) py es fila, px es columna
for (int py = 0; py < polOrder; ++py)
{
double ypy=std::pow(y,py);
for (int px = 0; px < polOrder; ++px)
dMij(polValue,px,py) = ypy*std::pow(x,px);
}
Matrix2D<int> *fMat;
//We generate the representation of the Zernike polynomials
for (int k=0; k < numZer; ++k)
{
fMat = &fMatV[k];
if (fMat == NULL)
continue;
double temp = 0;
for (size_t px = 0; px < (*fMat).Xdim(); ++px)
for (size_t py = 0; py < (*fMat).Ydim(); ++py)
temp += dMij(*fMat,py,px)*dMij(polValue,py,px);
dMij(zerMat,pixel_idx,k) = temp;
}
VEC_ELEM(weightedLeastSquaresHelper.b,pixel_idx)=A2D_ELEM(im,i,j);
VEC_ELEM(weightedLeastSquaresHelper.w,pixel_idx)=std::abs(A2D_ELEM(weight,i,j));
++pixel_idx;
}
}
Matrix1D<double> zernikeCoefficients;
weightedLeastSquares(weightedLeastSquaresHelper, zernikeCoefficients);
fittedCoeffs = zernikeCoefficients;
// Pointer to the image to be fitted
MultidimArray<double> reconstructed;
reconstructed.resizeNoCopy(im);
pixel_idx=0;
FOR_ALL_ELEMENTS_IN_ARRAY2D(im)
if (A2D_ELEM(ROI,i,j))
{
double temp=0;
for (int k=0; k < numZer; ++k)
temp+=dMij(zerMat,pixel_idx,k)*VEC_ELEM(fittedCoeffs,k);
A2D_ELEM(reconstructed,i,j)=temp;
if ( fabs(A2D_ELEM(reconstructed,i,j)-A2D_ELEM(im,i,j)) > PI)
A2D_ELEM(ROI,i,j) = false;
++pixel_idx;
}
pixel_idx=0;
//.........这里部分代码省略.........
示例12: zernikePols
void PolyZernikes::zernikePols(const Matrix1D<int> coef, MultidimArray<double> & im, MultidimArray<bool> & ROI, int verbose)
{
this->create(coef);
int polOrder=(int)ZERNIKE_ORDER(coef.size());
int numZer = coef.size();
int xdim = XSIZE(im);
int ydim = YSIZE(im);
im.setXmippOrigin();
Matrix2D<double> polValue(polOrder,polOrder);
double iMaxDim2 = 2./std::max(xdim,ydim);
double temp = 0;
FOR_ALL_ELEMENTS_IN_ARRAY2D(im)
{
if (A2D_ELEM(ROI,i,j))
{
//For one i we swap the different j
double y=i*iMaxDim2;
double x=j*iMaxDim2;
//polValue = [ 0 y y2 y3 ...
// x xy xy2 xy3 ...
// x2 x2y x2y2 x2y3 ]
//dMij(polValue,py,px) py es fila, px es columna
for (int py = 0; py < polOrder; ++py)
{
double ypy=std::pow(y,py);
for (int px = 0; px < polOrder; ++px)
dMij(polValue,px,py) = ypy*std::pow(x,px);
}
Matrix2D<int> *fMat;
//We generate the representation of the Zernike polynomials
for (int k=0; k < numZer; ++k)
{
fMat = &fMatV[k];
if ( (dMij(*fMat,0,0) == 0) && MAT_SIZE(*fMat) == 1 )
continue;
for (size_t px = 0; px < (*fMat).Xdim(); ++px)
for (size_t py = 0; py < (*fMat).Ydim(); ++py)
temp += dMij(*fMat,py,px)*dMij(polValue,py,px)*VEC_ELEM(coef,k);
}
A2D_ELEM(im,i,j) = temp;
temp = 0;
}
}
STARTINGX(im)=STARTINGY(im)=0;
if (verbose == 1)
{
Image<double> save;
save()=im;
save.write("PPP1.xmp");
}
}