MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ transform_cross_correlate() [1/2]

template<OperationReadyData DataType>
DataType MayaFlux::Yantra::transform_cross_correlate ( DataType &  input,
const std::vector< double > &  template_signal,
bool  normalize,
std::vector< std::vector< double > > &  working_buffer 
)

Cross-correlation using FFT (convolution with time-reversed impulse) (OUT-OF-PLACE)

Template Parameters
DataTypeOperationReadyData type
Parameters
inputInput data - will NOT be modified
template_signalTemplate signal for correlation
normalizeWhether to normalize the result
working_bufferBuffer for operations (will be resized if needed)
Returns
Cross-correlated data

Definition at line 284 of file ConvolutionHelper.hpp.

285{
286 auto [target_data, structure_info] = OperationHelper::setup_operation_buffer(input, working_buffer);
287
288 std::vector<double> reversed_template(template_signal.rbegin(), template_signal.rend());
289
290 auto correlation_op = [](const Eigen::VectorXcd& input_fft,
291 const Eigen::VectorXcd& kernel_fft,
292 Eigen::VectorXcd& result_fft) {
293 std::ranges::transform(input_fft, kernel_fft, result_fft.begin(),
294 [](const std::complex<double>& a, const std::complex<double>& b) {
295 return a * std::conj(b);
296 });
297 };
298
299 for (size_t i = 0; i < target_data.size(); ++i) {
300 auto result = fft_convolve_helper(target_data[i], reversed_template, correlation_op);
301
302 if (normalize && !result.empty()) {
303 auto [min_it, max_it] = std::ranges::minmax_element(result);
304 double max_abs = std::max(std::abs(*min_it), std::abs(*max_it));
305 if (max_abs > 0.0) {
306 std::ranges::transform(result, result.begin(),
307 [max_abs](double val) { return val / max_abs; });
308 }
309 }
310
311 working_buffer[i].resize(result.size());
312 working_buffer[i] = std::move(result);
313 }
314
315 return OperationHelper::reconstruct_from_double<DataType>(working_buffer, structure_info);
316}

References fft_convolve_helper(), MayaFlux::normalize(), and MayaFlux::Yantra::OperationHelper::setup_operation_buffer().

+ Here is the call graph for this function: