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

◆ extract_implementation()

template<ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = std::vector<std::vector<double>>>
output_type MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::extract_implementation ( const input_type &  input)
inlineoverrideprotected

Core extraction implementation - delegates to ExtractionHelper.

Parameters
inputInput data with metadata
Returns
Extracted data with metadata

Definition at line 257 of file FeatureExtractor.hpp.

258 {
259 try {
260 auto [numeric_data, info] = OperationHelper::extract_structured_double(const_cast<input_type&>(input));
261 DataStructureInfo structure_info = info;
262
263 std::vector<std::span<const double>> channels;
264 channels.reserve(numeric_data.size());
265 for (auto& s : numeric_data)
266 channels.emplace_back(s.data(), s.size());
267
268 std::vector<std::vector<double>> extracted_data;
269
270 switch (m_method) {
271
273 extracted_data = extract_high_energy(channels,
274 this->template get_parameter_or_default<double>("energy_threshold", 0.1),
276 break;
277
279 extracted_data = extract_peaks(channels,
280 this->template get_parameter_or_default<double>("threshold", 0.1),
281 this->template get_parameter_or_default<double>("min_distance", 10.0),
282 this->template get_parameter_or_default<uint32_t>("region_size", 256));
283 break;
284
286 extracted_data = extract_outliers(channels,
287 this->template get_parameter_or_default<double>("std_dev_threshold", 2.0),
289 break;
290
292 extracted_data = extract_high_spectral(channels,
293 this->template get_parameter_or_default<double>("spectral_threshold", 0.1),
295 break;
296
298 extracted_data = extract_above_mean(channels,
299 this->template get_parameter_or_default<double>("mean_multiplier", 1.5),
301 break;
302
304 extracted_data = extract_overlapping_windows(channels,
306 this->template get_parameter_or_default<double>("overlap", 0.5));
307 break;
308
310 extracted_data = extract_zero_crossings(channels,
311 this->template get_parameter_or_default<double>("threshold", 0.0),
312 this->template get_parameter_or_default<double>("min_distance", 1.0),
313 this->template get_parameter_or_default<uint32_t>("region_size", 1));
314 break;
315
317 extracted_data = extract_silence(channels,
318 this->template get_parameter_or_default<double>("silence_threshold", 0.01),
319 this->template get_parameter_or_default<uint32_t>("min_duration", 1024),
321 break;
322
324 extracted_data = extract_onsets(channels,
325 this->template get_parameter_or_default<double>("threshold", 0.3),
326 this->template get_parameter_or_default<uint32_t>("region_size", 512),
327 this->template get_parameter_or_default<uint32_t>("fft_window_size", 1024),
328 m_hop_size);
329 break;
330
331 default:
332 error<std::invalid_argument>(Journal::Component::Yantra, Journal::Context::ComputeMatrix, std::source_location::current(), "Unknown extraction method");
333 }
334
335 output_type output = this->convert_result(extracted_data, structure_info);
336
337 output.template set_metadata<std::string>("extractor_type", "FeatureExtractor");
338 output.template set_metadata<std::string>("extraction_method", method_to_string(m_method));
339 output.template set_metadata<uint32_t>("window_size", static_cast<uint32_t>(m_window_size));
340 output.template set_metadata<uint32_t>("hop_size", static_cast<uint32_t>(m_hop_size));
341 output.template set_metadata<size_t>("extracted_samples", extracted_data.size());
342
343 return output;
344
345 } catch (const std::exception& e) {
346 MF_ERROR(Journal::Component::Yantra, Journal::Context::ComputeMatrix, "Feature extraction failed: {}", e.what());
347 return output_type {};
348 }
349 }
#define MF_ERROR(comp, ctx,...)
Core::GlobalInputConfig input
Definition Config.cpp:42
bool size
uint32_t channels
static std::string method_to_string(ExtractionMethod method)
Convert extraction method enum to string.
static std::tuple< std::vector< std::span< double > >, DataStructureInfo > extract_structured_double(T &compute_data)
Extract structured double data from Datum container or direct ComputeData with automatic container ha...
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::vector< Keypoint > extract_peaks(std::span< const float > response, uint32_t w, uint32_t h, float threshold, uint32_t nms_radius)
Extract peaks from a response map via non-maximum suppression.
Definition Harris.cpp:197
std::vector< std::vector< double > > extract_high_energy(const std::vector< std::span< const double > > &channels, double energy_threshold, uint32_t window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_zero_crossings(const std::vector< std::span< const double > > &channels, double threshold, double min_distance, uint32_t region_size)
std::vector< std::vector< double > > extract_outliers(const std::vector< std::span< const double > > &channels, double std_dev_threshold, uint32_t window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_silence(const std::vector< std::span< const double > > &channels, double silence_threshold, uint32_t min_duration, uint32_t window_size, uint32_t hop_size)
@ ABOVE_MEAN_DATA
Extract data above statistical mean.
@ SILENCE_DATA
Extract actual silent regions.
@ PEAK_DATA
Extract data around detected peaks.
@ OUTLIER_DATA
Extract data from statistical outlier regions.
@ ZERO_CROSSING_DATA
Extract actual data at zero crossing points.
@ HIGH_ENERGY_DATA
Extract data from high-energy regions.
@ HIGH_SPECTRAL_DATA
Extract data from high spectral energy regions.
@ OVERLAPPING_WINDOWS
Extract overlapping windowed data.
@ ONSET_DATA
Extract actual onset/transient regions.
std::vector< std::vector< double > > extract_onsets(const std::vector< std::span< const double > > &channels, double threshold, uint32_t region_size, uint32_t fft_window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_high_spectral(const std::vector< std::span< const double > > &channels, double spectral_threshold, uint32_t window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_overlapping_windows(const std::vector< std::span< const double > > &channels, uint32_t window_size, double overlap)
std::vector< std::vector< double > > extract_above_mean(const std::vector< std::span< const double > > &channels, double mean_multiplier, uint32_t window_size, uint32_t hop_size)

References MayaFlux::Yantra::ABOVE_MEAN_DATA, channels, MayaFlux::Journal::ComputeMatrix, MayaFlux::Yantra::extract_above_mean(), MayaFlux::Yantra::extract_high_energy(), MayaFlux::Yantra::extract_high_spectral(), MayaFlux::Yantra::extract_onsets(), MayaFlux::Yantra::extract_outliers(), MayaFlux::Yantra::extract_overlapping_windows(), MayaFlux::Kinesis::Vision::extract_peaks(), MayaFlux::Yantra::extract_silence(), MayaFlux::Yantra::OperationHelper::extract_structured_double(), MayaFlux::Yantra::extract_zero_crossings(), MayaFlux::Yantra::HIGH_ENERGY_DATA, MayaFlux::Yantra::HIGH_SPECTRAL_DATA, input, MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::m_hop_size, MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::m_method, MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::m_window_size, MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::method_to_string(), MF_ERROR, MayaFlux::Yantra::ONSET_DATA, MayaFlux::Yantra::OUTLIER_DATA, MayaFlux::Yantra::OVERLAPPING_WINDOWS, MayaFlux::Yantra::PEAK_DATA, MayaFlux::Yantra::SILENCE_DATA, MayaFlux::Journal::Yantra, and MayaFlux::Yantra::ZERO_CROSSING_DATA.

+ Here is the call graph for this function: