\brief Zero-pads a 1D array to a specified size. * * Adds zeros symmetrically around the input array so it reaches the desired padded * dimension. This prevents circular convolution artefacts in FFT-based convolution. * \param[in] unpaddedSpectrum The input array to be padded. * \param[in] paddedDimension The target size after padding (sum of both convolution operand sizes
| 54 | * \param[in] paddedDimension The target size after padding (sum of both convolution operand sizes). |
| 55 | * \return The zero-padded array. */ |
| 56 | inline itk::Array<double> zeropadding1d(itk::Array<double> unpaddedSpectrum, int paddedDimension) |
| 57 | { |
| 58 | |
| 59 | int initialDimension = unpaddedSpectrum.GetNumberOfElements(); |
| 60 | |
| 61 | itk::Array<double> paddedSpectrum(paddedDimension); |
| 62 | paddedSpectrum.fill(0.); |
| 63 | |
| 64 | if(paddedDimension > initialDimension) |
| 65 | { |
| 66 | unsigned int padding = paddedDimension - initialDimension; |
| 67 | |
| 68 | for(int i=0; i<initialDimension ;++i) |
| 69 | { |
| 70 | paddedSpectrum.SetElement(i+padding/2, unpaddedSpectrum.GetElement(i)); |
| 71 | } |
| 72 | } |
| 73 | return paddedSpectrum; |
| 74 | } |
| 75 | |
| 76 | /** \brief Removes padding and scales the result after inverse FFT. |
| 77 | * |
no test coverage detected