Returns num if it is even and has no prime factor greater than limit, or makes the number even and adds idnum until it reaches a value with this property. Use a values of 2 for idnum and call niceFFTlimit to obtain an optimal value of limit for taking the FFT with the current IMOD package. This value is 15 when linked with FFTW (because higher values use slower algorithms) and 19 with the old IMOD FFT routines (an absolute limit in that case).
Fortran wrapper for niceFrame
Takes the filter parameters sigma1, sigma2, radius1, and radius2 and sets up a contrast transfer (filter) function in the array ctf, which should be dimensioned to at least 8193. The dimensions of the real space image being filtered are specified in nx and ny, and the step size between the values in ctf is returned in delta. If no filtering is selected (sigma1 and sigma2 both 0) then 0 is returned in delta. The values in ctf are scaled so that mean of all but the zero element is 1.
Fortran wrapper for XCorrSetCTF
Sets up a filter function in ctf as described for XCorrSetCTF, but with no scaling, such that the filter value will be 1 for all unattenuated frequencies. The number of elements computed in ctf is returned in nizeOut.
Fortran wrapper for XCorrSetCTFnoScl
Applies the filter in ctf to the 2D Fourier transform in fft, and puts result into array, which can be the same as fft. The dimensions of the real space image are given by nx and ny, and the dimension of the real image array are assumed to be nx + 2 by ny. delta is the interval in reciprocal space (1/pixel) for the function in ctf.
Fortran wrapper to XCorrFilterPart
Computes a dose weighting filter. Arguments are:
startDose, endDose - Dose at start and end of image acquisition, in
electrons per square Angstrom
pixelSize - Pixel size in Angstroms
afac, bfac, cfac - Three factors in critical dose equation
afac * frequency**bfac + cfac
pass 0 to use the default for any one of these
doseScale - Amount by which to scale the critical dose; it should
include the factor of 0.8 for 200 instead of 300 kV
ctf - Array to fill with filter
numVals - Number of values to compute in the array
maxFreq - Frequency of last value placed in the array in reciprocal pixels
delta - Returned with spacing in reciprocal pixels between array values
Fortran wrapper to doseWeightFilter
Returns the dose weighting filter value for frequency in reciprocal Angstroms in atten; other arguments are as in doseWeightFilter
Shifts the contents of array to have a zero mean. nxdim specifies the X dimension of array, and nx and ny are the size of the data in array.
Fortran wrapper to XCorrMeanZero
Finds the coordinates of up to the maxPeaks highest peaks in array, which is dimensioned to nxdim by ny, and returns the positions in xpeak, ypeak, and the peak values in peak. If minStrength is greater than 0, then only those peaks that are greater than that fraction of the highest peak will be returned. In addition, if width and widthMin are not NULL, the distance from the peak to the position at half of the peak height is measured in 8 directions, the overall mean width of the peak is returned in width, and the minimum width along one of the four axes is returned in widthMin. The X size of the image is assumed to be nxdim - 2. The sub-pixel position is determined by fitting a parabola separately in X and Y to the peak and 2 adjacent points. Positions are numbered from zero and coordinates bigger than half the image size are shifted to be negative. The positions are thus the amount to shift a second image in a correlation to align it to the first. If fewer than maxPeaks peaks are found, then the remaining values in peaks will be -1.e30.
Fortran wrapper to XCorrPeakFindWidth. If maxPeaks is 1, then xpeak, ypeak, and peak can be single variables instead of arrays.
Calls XCorrPeakFindWidth with width and widthMin NULL and minStrength 0.
Fortran wrapper to XCorrPeakFind. If maxPeaks is 1, then xpeak, ypeak, and peak can be single variables instead of arrays.
Sets limits for shifts in X and in Y for peaks found in the next call to XCorrPeakFindWidth. The peak position must be between limXlo and limXhi in X and between limYlo and limYhi in Y. Also, if useEllipse is non-zero, the peaks are constrained to be in the ellipse bounded by these limits (i.e., a circle if the range of limts is the same in X and Y).
Fortran wrapper to setPeakFindLimits.
Finds multiple cross-correlation peaks, such as from correlating with a template, much
more efficiently than XcorrPeakFindWidth. Finds the coordinates of up to the
maxPeaks highest peaks in array, which is dimensioned to nxdim by ny, and
returns the positions in xpeak, ypeak, the peak values in peak, and the number
of peaks in numFound. For a template correlation where a template has been wrapped
to give correlation peaks at the same location as the feature, the offsets
ixOffset and iyOffset can be set to the amount of padding on each side in X and Y
to ignore the borders where the array was padded. For a regular cross-correlation to
find shifts between images, pass iyOffset as -1 and ixOffset as either -1 or -2.
This will allow the routine to find peaks along the borders of the correlation, where
ixOffset of -1 would make it loop in X all the way out to nxdim - 1 and wrap X from
0 to nxdim - 1 when testing peaks, whereas -2 handles the more common case of a
padded inverse correlation and makes it loop X to nxdim - 3 and wrap X between 0 and
nxdim - 3. In this case, the routine returns positive and negative shifts as
XcorrPeakFindWidth does.
Rather than maintaining peaks in
order while finding them, up to maxGrow peaks are collected into arrays allocated
for this purpose, then sorted, and the top maxPeaks peaks are retained. The array
is allowed to grow repeatedly. After the first time, only the newest peaks need to be
sorted, but all the data need to be repacked to integrate new high ones. Values for
maxGrow of 1.2 - 1.5 were found to be most efficient in a case where several thousand
peaks were being selected out of several hundred thousand. Returns 1 if maxGrow is
not more than 1.05 times maxPeaks and -1 for memory error.
Finds multiple cross-correlation peaks with a minimum spacing between them even more efficiently than findManyXCorrPeaks. Finds the coordinates of up to the maxPeaks highest peaks separated by minSpacing in array, whose X dimension is nxdim, within the * coordinates from ixMin to ixMax and iyMin to iyMax, inclusive. Returns the positions in xpeak, ypeak, the peak values in peak, and the number of peaks in numPeaks. If minStrength is non-zero, only those peaks that are greater than that fraction of the highest peak will be returned. The function divides the image into blocks of minSpacing / sqrt(2.) pixels, searches for the highest peak within each block, and stores that peak for each block. The loop on blocks is paralellized with OpenMP. At the end, data are merged from the different threads, sorted, and weaker peaks too close to other ones eliminated. The coordinates of the peaks within the image are returned, not offsets from the origin as in XcorrPeakFindWidth. Returns -1 for memory error.
Given values at three successive positions, y1, y2, and y3, where y2 is the peak value, this fits a parabola to the values and returns the offset of the peak from the center position, a number between -0.5 and 0.5.
Fortran wrapper to parabolicFitPosition
Forms the product of complex numbers in array and the complex conjugate of numbers in brray and puts the result back in array, where the arrays are Fourier transforms of images with dimensions nx by ny.
Fortran wrapper to conjugateProduct
Returns the cross-correlation coefficient between the images in array and brray at a shift between the images given by xpeak, ypeak. The images have sizes nx by ny and the arrays have X dimension nxdim. Areas on each side of nxpadA in X and nypadA in Y in array, and of nxpadB and nypadB in brray, are excluded from the correlation. Otherwise, the correlation will include all the pixels in the overlap between the images at the given shift. The number of pixels will be returned in nsum, but no computation will be done and 0. will be returned if this number is less than minPixels.
Fortran wrapper to CCCoefficientTwoPads
Calls CCCoefficientTwoPads with both excluded areas specified by nxpad, nypad and with a value of 25 for minPixels.
Fortran wrapper to XCorrCCCoefficient
Computes a cross-correlation coefficient in a subarea at one shift between two images in array and brray with X dimension nxdim. The amount that the image in brray is shifted relative to array is in delx, dely, and the correlation is done between xstart and xend in X and ystart and yend in Y (inclusive coordinates in array, numbered from 0. There are no checks for the validity of these limits.
Returns a weighted cross-correlation between images in array and brray, with X X dimension nxDim, over the range of positions in array given by ix0 to ix1 in X and iy0 to iy1 in Y (inclusive, numbered from 0), at a shift of B relative to A given by delX, delY. Weights are supplied in aWeights for A and bWeights for B, with X dimension nxWgt, binned by binning and with offsets wgtXoffset, wgtYoffset, where for position ix, iy in an image, the index of the weight is ix / binning + wgtXoffset + nxWgt * (iy / binning + wgtYoffset). The weight at each pixel is the product of the weights for A and B.
Returns the weighted cross-correlation from the set of weighted sums: aSum, bSum are the sums of weighted values in A and B, aSumSq and bSumSq are sums of weighted squares, abSum is the sum of weighted cross-products, and sSum is the sum of weights. If sumArray is non-null, it will be filled with the 6 sum arguments in order. If descrip is non-zero length,values will be printed after this text; it can be NULL.
Fills mat with the coefficients of a dim x dim Gaussian kernel with standard deviation sigma. The coefficients are scaled to sum to 1.
Fortran wrapper for sliceGaussianKernel
Fills mat with the coefficients of a Gaussian kernel with standard deviation sigma. The size of the kernel is set to 3 for sigma up to 1., 5 for sigma up to 2., etc., up to the size given by limit. The size is returned in dim. The coefficients are scaled to sum to 1. Values are placed sequentially in mat; i.e., it is not treated as a 2D array of size limit.
Fortran wrapper for scaledGaussianKernel
Applies the kernel in mat, with the size given in kdim, to a whole floating point image in array with X and Y sizes nx amd ny and X dimension nxdim, and places the output into brray with the same X dimension. Scaling coefficients should be sequential in mat with the X dimension advancing fastest. The filtering is parallelized with OpenMP with the same size-dependent limitation on the number of threads as in cubinterp
Fortran wrapper for applyKernelFilter
Converts a 2D FFT or Z slice of a 3D FFT between the organization used by FFT routines, with the origin at the lower left, and the organization used in MRC files, with the origin at the middle left. The complex data are packed in array with nx and ny complex elements in X and Y, direction is 0 to convert from FFT routine organization to file organization, and non-zero for the reverse. tmpArray is a temporary array that must be dimensioned to at least 2 * nx.
Fortran wrapper for wrapFFTslice
Produces indices needed for converting between FFT routine organization and MRC file organization. The size of the dimension is in ny and the direction is 0 for FFT routine to file, or non-zero otherwise. Returns the starting index to copy data from on the low and high ends of the dimension in iyLow and iyHigh, respectively, and the starting index to copy data from the high end to in iyOut. The return value is the increment for these indices. In all cases, a loop is run ny / 2 times. For ny even, the loop simply swaps each element or line between iyHigh to iyLow. For ny odd, first the element at iyOut is saved, then the loop is run to copy from iyHigh to iyOut and from iyLow to iyHigh, then the saved element is copied to iyOut.
Applies a phase shift to the Fourier transform in fft to produce a shift of dx and dy in the corresponding real-space image. The size of the image is given in nxPad, nyPad and the X-dimension of fft is assumed to be nxPad + 2. temp is a temporary array that must be dimensioned to at least nxPad + 2.
Fortran wrapper for fourierShiftImage.
Extracts a portion of the Fourier transform in fftIn into fftOut to achieve an image reduction from real-space image size nxrIn, nyrIn to nxrOut, nyrOut, after shifting the image by dxIn, dyIn. A Fourier shift is required to keep the image centered anyway, so it is efficient to combine this with another shift if one is needed. The X-dimension of fftIn is assumed to be nxrIn + 2 and that of fftOut is assumed to be nxrOut + 2. temp is a temporary array that must be dimensioned to at least nxrOut + 2, unless temp is NULL, in which case the FFT is simply cropped, fourierShiftImage is not called and dxIn and dyIn are ignored.
Fortran wrapper for fourierReduceImage.
Pads the Fourier transform in fftIn into fftOut to achieve an image expansion from real-space image size nxrIn, nyrIn to nxrOut, nyrOut, after shifting the image by dxIn, dyIn. A Fourier shift is required to keep the image centered anyway, so it is efficient to combine this with another shift if one is needed. The X-dimension of fftIn is assumed to be nxrIn + 2 and that of fftOut is assumed to be nxrOut + 2. temp is a temporary array that must be dimensioned to at least nxrIn + 2, unless temp is NULL, in which case the FFT is simply padded, fourierShiftImage is not called and dxIn and dyIn are ignored.
Fortran wrapper for fourierExpandImage.
Applies a phase shift to the 3D Fourier transform in fft to produce a shift of dx, dy, and dz in the corresponding real-space volume. The size of the volume is given in nxPad, nyPad, nzPad and the X-dimension of fft is assumed to be nxPad + 2. temp is a temporary array that must be dimensioned to at least nxPad + 2.
Fortran wrapper for fourierShiftVolume.
Extracts a portion of the 3-D Fourier transform in fftIn into fftOut to achieve an volume reduction from real-space columesize nxrIn, nyrIn, nzrIn to nxrOut, nyrOut, nzrOut after shifting the volume by dxIn, dyIn, dzIn. A Fourier shift is required to keep the image centered anyway, so it is efficient to combine this with another shift if one is needed. The X-dimension of fftIn is assumed to be nxrIn + 2 and that of fftOut is assumed to be nxrOut + 2. temp is a temporary array that must be dimensioned to at least nxrOut + 2, unless temp is NULL, in which case the FFT is simply cropped, fourierShiftVolume is not called and dxIn, dyIn, and dzIn are ignored.
Fortran wrapper for fourierReduceVolume.
Pads the 3-D Fourier transform in fftIn into fftOut to achieve an image expansion from real-space image size nxrIn, nyrIn, nzrIn to nxrOut, nyrOut, nzrOut after shifting the image by dxIn, dyIn, dzIn. A Fourier shift is required to keep the image centered anyway, so it is efficient to combine this with another shift if one is needed. The X-dimension of fftIn is assumed to be nxrIn + 2 and that of fftOut is assumed to be nxrOut + 2. temp is a temporary array that must be dimensioned to at least nxrIn + 2, unless temp is NULL, in which case the FFT is simply padded, fourierShiftVolume is not called and dxIn, dyIn, and dzIn are ignored.
Fortran wrapper for fourierExpandImage.
Computes the Fourier Ring Correlation between two FFTs in ffta and fftb with real-space image size of nxReal by ny, where each line has nxReal + 2 floating point numbers. The ring spacing is specified by deltaR and maxRings sets the maximum number of rings to compute. The correlation coefficients are returned into ringCorrs. temp is a temporary array that must have at least 4 * maxRings elements; it can be the same as ringCorrs.
Fortran wrapper for fourierRingCorr
Computes padded sizes in one dimension for Fourier reduction or expansion, given the original size in size, the reduction factor or inverse of expansion factor in factor, fraction to pad in padFrac, minimum padding in minPad, and the nice or necessary limiting factor for FFTs in niceLimit. The padded size for the original and processed data are returned in fullPadSize and cropPadSize and the actual factor being applied is returned in actualFac. The reduction or expansion factor or its multiple by 2, 3, 4, 5, 6, 8, or 10 is required to be an integer, where the factor must be accurate to the third decimal place for a multiple to be acceptable. The return value is 1 for a factor equal to 1 or 2 if it is not an acceptable fractional value.
Applies a Sobel-type gradient filter to an image after scaling it by a
specified amount. When an image is being scaled down, some of the scaling
can be done with binning and the remainder is done with interpolation.
inImage - input image
nxin, nyin - size of image, which is assumed to be contiguous in
the image array (X dimension equals nxin.)
scaleFac - overall amount by which image is being scaled down (a value
< 1 will scale an image up).
minInterp - minimum amount of this scaling to be done by interpolation.
linear - set to 1 to use linear rather than cubic interpolation, or to
-1 to use zoomFiltInterp instead of binning followed by cubinterp
center - weighting of center pixel, 2 for Sobel or 1 for Prewitt filter
outImage - output image
nxout, nyout - returned with size of output image
xOffset, yOffset - coordinate offset in output image:
input_coord = output_coord * scalingFactor + xOffset
The return value is 1 for a failure to allocate a temporary array, or the return
value from zoomdown if it gives an error.
If inImage is NULL or center < 0, the function will compute the output
sizes and offsets and return.
If center is 0, the scaled image is computed and returned without Sobel
filtering.
The filtering operation is parallelized with OpenMP with the same limitation on
number of threads as used in cubinterp.
The call from Fortran is the same as that from C.