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

◆ transform_normalize() [2/2]

template<OperationReadyData DataType>
DataType MayaFlux::Yantra::transform_normalize ( DataType &  input,
const std::pair< double, double > &  target_range = { -1.0, 1.0 } 
)

Normalize transformation using existing infrastructure (IN-PLACE)

Template Parameters
DataTypeOperationReadyData type
Parameters
inputInput data - WILL BE MODIFIED
target_rangeTarget range [min, max]
Returns
Normalized data

Definition at line 536 of file MathematicalHelper.hpp.

536 { -1.0, 1.0 })
537{
538 auto [target_data, structure_info] = OperationHelper::extract_structured_double(input);
539
540 for (auto& span : target_data) {
541 auto [min_it, max_it] = std::ranges::minmax_element(span);
542 double current_min = *min_it;
543 double current_max = *max_it;
544
545 if (current_max == current_min)
546 return input;
547
548 double current_range = current_max - current_min;
549 double target_min = target_range.first;
550 double target_max = target_range.second;
551 double target_span = target_max - target_min;
552
553 std::ranges::transform(span, span.begin(),
554 [current_min, current_range, target_span, target_min](double x) {
555 return ((x - current_min) / current_range) * target_span + target_min;
556 });
557 }
558
559 auto reconstructed_data = target_data
560 | std::views::transform([](const auto& span) {
561 return std::vector<double>(span.begin(), span.end());
562 })
563 | std::ranges::to<std::vector>();
564
565 return OperationHelper::reconstruct_from_double<DataType>(reconstructed_data, structure_info);
566}

References transform_normalize().

Referenced by MayaFlux::Yantra::MathematicalTransformer< InputType, OutputType >::transform_implementation(), transform_normalize(), and transform_normalize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: