ucurv.ucurv
- class ucurv.ucurv.Udct(sz, cfg, complex=False, sparse=False, high='curvelet', engine: str = 'auto')[source]
Bases:
objectA class to hold the configuration and parameters for the ucurv transform. This class initializes the sampling vectors, computes the parameters, and prepares the curvelet windows based on the specified parameters. :param sz: The size of the input image or data array. It must be the even multiples of the resolution levels.
2D example: (256, 256) for a 2D image.
- Parameters:
cfg (list of list of int) – Configuration for the curvelet transform, where each inner list specifies the number of angles for each resolution level.
complex (bool, optional) – If True, the transform will ouput complex curvelet coefficients. Default is False.
sparse (bool, optional) – If True, the transform will store sparse representations of the windows. This will sigmificantly reduced memory required to remember the curvelet windows. Default is False.
high (str, optional) – Specifies the type of the transform to use on the highest resolution. This will reduce the redundancy of the transform. Options are ‘curvelet’ or ‘wavelet’. Default is ‘curvelet’.
- ucurv.ucurv.angle_fun(Mgrid, n, alpha, bandpass=None, engine: str = 'auto')[source]
Return the angle meyer window as in Figure 8 of the paper Compute directional Meyer window functions for angular decomposition. :param Mgrid: An N-D coordinate grid (e.g., meshgrid) of angles normalized to [−1,1]. :type Mgrid: ndarray :param n: Total number of angular directions (must be positive and even). :type n: int :param alpha: Angular transition parameter controlling the width of each subband. :type alpha: float :param bandpass: An array of the same shape as Mgrid to modulate (mask) each window. :type bandpass: ndarray, optional
- Returns:
Mang – A list of length n containing the forward (0 <= id < n/2) and flipped inverse (n/2 <= id < n) Meyer windows for each angular sector.
- Return type:
list of ndarray
- ucurv.ucurv.downsamp(band, samp, shift=None, engine: str = 'auto')[source]
Downsample a N-D array by length N of power-2 integers
- ucurv.ucurv.fftflip(F, dirlist=None, engine: str = 'auto')[source]
Flip and circularly shift an N-D FFT array so that frequency sign is reversed.
This routine performs an axis-wise reversal and roll on the input array to map X(omega) to X(-omega) in its FFT representation. For each transformed axis, elements are flipped (so that the zero-frequency component moves to the end), then rolled by one to restore the zero-frequency component to the first position. Note the parameter dirlist denotes the axes to be flipped. This is useful when flipping the angle functions along certain dimensions only.
- Parameters:
F (ndarray) – Incput array in the frequency domain (FFT output). Can be of any dimensionality.
dirlist (int or sequence of ints, optional) – Axis or list of axes over which to apply the fftflip. If None (default), all axes of F will be processed.
- Returns:
Fc – A new array of the same shape as F, with each specified axis flipped and rolled so that the frequency axis is negated.
- Return type:
ndarray
Notes
Reversing an axis in FFT output corresponds to replacing omega with -omega.
After ncp.flip, the zero-frequency component moves to the end of the axis. ncp.roll by +1 brings it back to index 0.
For multi-dimensional FFTs, reversing multiple axes implements sign inversion in each frequency dimension.
- ucurv.ucurv.get_folding_indices(arr, fold_ratios)[source]
Returns aligned vectors of indices for folding an N-dimensional array.
- Parameters:
arr (np.ndarray) – Input array.
fold_ratios (sequence) – Folding ratio for each dimension.
- Returns:
- (orig_indices, folded_indices)
orig_indices: 1D array of flat indices in the big array.
folded_indices: 1D array of corresponding flat indices in the folded array.
- Return type:
tuple
- ucurv.ucurv.tan_theta_grid(S1, S2, engine: str = 'auto')[source]
Create a grid approximate the tan theta function as described in (28) of the paper
- ucurv.ucurv.ucurvfwd(img, udct)[source]
Forward Uniform Discrete Curvelet Transform (UDCT).
This function computes the forward UDCT coefficients of a given MD input signal img using the precomputed parameters and windows. Will either return output on the CPU/GPU depending on which engine is used(numpy/cupy).
- Parameters:
img (ndarray) – Input real- or complex-valued array of dimension udct.dim and shape udct.sz. For high=’curvelet’, the image size must match exactly udct.sz. For high=’wavelet’, the highest resolution is decomposed with Meyer wavelets instead of curvelets.
udct (Udct) – An instance of the Udct class containing precomputed window functions, sampling factors, and configuration parameters for the transform.
- Returns:
imband – Dictionary of UDCT coefficients (subbands). Keys are tuples identifying each subband:
(0,) : lowpass scaling coefficients.
(rs, ipyr, a1, …, ak) : directional subbands at resolution rs, pyramid index ipyr, and angular indices (a1, …, ak), where k = udct.dim -1 (why ?).
For complex UDCT, each subband has a conjugate-symmetric counterpart indexed with ipyr + udct.dim.
Each subband is stored as a downsampled array according to the decimation factors in udct.Sampling.
- Return type:
dict
Notes
Inverse transform function ucurvinv.
If udct.complex=True, symmetric/antisymmetric curvelets are stored separately as conjugate subbands, requiring sqrt(0.5) normalization.
If udct.sparse=True, subband windows are stored sparsely and reconstructed on-the-fly.
- ucurv.ucurv.ucurvinv(imband, udct)[source]
Inverse Uniform Discrete Curvelet Transform (UDCT). This function reconstructs a signal from its UDCT coefficients, providing the perfect inverse of ucurvfwd.
- Parameters:
imband (dict) –
Dictionary of UDCT coefficients produced by ucurvfwd. Keys must follow the same convention:
(0,) : lowpass scaling coefficients.
(rs, ipyr, a1, …, ak) : directional subbands.
For complex UDCT, additional conjugate subbands.
udct (Udct) – An instance of the Udct class containing precomputed window functions, sampling factors, and configuration parameters for the transform.
- Returns:
recon – The reconstructed signal, same shape as udct.sz
- Return type:
ndarray
Notes
Uses upsampling and FFT-domain synthesis with precomputed windows.
- ucurv.ucurv.update_win_overlaps_numpy(win, orig_indices, folded_indices)[source]
Updates ‘win’ using pure Numpy: 1. Identifies overlapping groups based on ‘folded_indices’. 2. Finds the MAX value in each group. 3. The MAX index gets the sum of all OTHER values in the group. 4. All OTHER indices are set to 0.