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

◆ read_normalized_at() [1/2]

MAYAFLUX_API double MayaFlux::Kakshya::read_normalized_at ( const DataVariant &  v,
ImageFormat  format,
const std::optional< DataDimension::ValueRange > &  range,
size_t  elem_index 
)

Read one element as a normalised double, with optional range remapping.

Same as read_normalized_at, but if range is provided, the value is linearly remapped from [range.min, range.max] to [0.0, 1.0]. Values outside the range are clamped to 0.0 or 1.0.

Parameters
vSource variant.
formatPixel format governing the uint16 interpretation.
rangeOptional value range for remapping.
elem_indexElement index. Returns 0.0 when out of range.

Definition at line 166 of file PixelStorage.cpp.

170{
171 return std::visit(
172 [&](const auto& vec) -> double {
173 using T = typename std::decay_t<decltype(vec)>::value_type;
174
175 if constexpr (std::is_same_v<T, uint8_t>
176 || std::is_same_v<T, uint16_t>
177 || std::is_same_v<T, float>) {
178
179 if (elem_index >= vec.size())
180 return 0.0;
181
182 double raw {};
183 double type_max = 1.0;
184
185 if constexpr (std::is_same_v<T, uint8_t>) {
186 raw = static_cast<double>(vec[elem_index]);
187 type_max = 255.0;
188 } else if constexpr (std::is_same_v<T, uint16_t>) {
189 if (is_float_format(format)) {
190 raw = static_cast<double>(decode_half(vec[elem_index]));
191 } else {
192 raw = static_cast<double>(vec[elem_index]);
193 type_max = 65535.0;
194 }
195 } else {
196 raw = static_cast<double>(vec[elem_index]);
197 }
198
199 if (!range)
200 return raw / type_max;
201
202 if (range->invalid && raw == *range->invalid)
203 return std::numeric_limits<double>::quiet_NaN();
204
205 const double span = range->max - range->min;
206 if (span <= 0.0)
207 return 0.0;
208
209 return std::clamp((raw - range->min) / span, 0.0, 1.0);
210 } else {
211 return 0.0;
212 }
213 },
214 v);
215}
bool format
std::vector< double > range(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Value range (max - min) per window.
Definition Analysis.cpp:452

References format, and is_float_format().

Referenced by MayaFlux::Kakshya::VideoStreamContainer::get_value_impl(), and read_normalized_at().

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