nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
type_convert.hpp File Reference

Image type-conversion helpers. More...

#include <limits>
#include <memory_resource>
#include <string>
#include <tuple>
#include <nk/value/value.hpp>

Go to the source code of this file.

Functions

Value nk::image::im2double (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Convert to DOUBLE in [0, 1] (B = im2double(A)).
Value nk::image::im2single (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Convert to SINGLE in [0, 1] (B = im2single(A)).
Value nk::image::im2uint8 (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Convert to UINT8 (B = im2uint8(A)).
Value nk::image::im2uint16 (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Convert to UINT16 (B = im2uint16(A)).
Value nk::image::im2int16 (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Convert to INT16 (B = im2int16(A)).
Value nk::image::mat2gray (const Value &x, double lo=std::numeric_limits< double >::quiet_NaN(), double hi=std::numeric_limits< double >::quiet_NaN(), std::pmr::memory_resource *mr=nullptr)
 Linear rescale to [0, 1] DOUBLE (B = mat2gray(A, lo, hi)).
Value nk::image::im2gray (const Value &x, std::pmr::memory_resource *mr=nullptr)
 RGB → grayscale dispatcher (Y = im2gray(X)).
Value nk::image::rgb2gray (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Rec.
Value nk::image::getrangefromclass (const Value &I, std::pmr::memory_resource *mr=nullptr)
 Class display range (r = getrangefromclass(I)).
std::tuple< Value, Value > nk::image::gray2ind (const Value &I, int n, std::pmr::memory_resource *mr=nullptr)
 Grayscale → indexed ([ind, map] = gray2ind(I, n)).
Value nk::image::ind2gray (const Value &idx, const Value &map, std::pmr::memory_resource *mr=nullptr)
 Indexed → grayscale (I = ind2gray(idx, map)).
Value nk::image::ind2rgb (const Value &idx, const Value &map, std::pmr::memory_resource *mr=nullptr)
 Indexed → RGB (RGB = ind2rgb(idx, map)).
Value nk::image::iptnum2ordinal (double n, std::pmr::memory_resource *mr=nullptr)
 English ordinal-form string (s = iptnum2ordinal(n)).
Value nk::image::imcast (const Value &I, const std::string &type, std::pmr::memory_resource *mr=nullptr)
 Generic class converter (B = imcast(I, type)).
Value nk::image::isbw (const Value &BW, const std::string &mode, std::pmr::memory_resource *mr=nullptr)
 Binary-image predicate (tf = isbw(BW, mode)).
Value nk::image::isgray (const Value &I, std::pmr::memory_resource *mr=nullptr)
 Grayscale-image predicate (tf = isgray(I)).
Value nk::image::isind (const Value &I, std::pmr::memory_resource *mr=nullptr)
 Indexed-image predicate (tf = isind(I)).
Value nk::image::isrgb (const Value &I, std::pmr::memory_resource *mr=nullptr)
 RGB-image predicate (tf = isrgb(I)).
Value nk::image::iscolormap (const Value &cmap, std::pmr::memory_resource *mr=nullptr)
 Colormap-shape predicate (tf = iscolormap(cmap)).
Value nk::image::intlut (const Value &A, const Value &LUT, std::pmr::memory_resource *mr=nullptr)
 Apply a look-up table to an integer image (B = intlut(A, LUT)).

Detailed Description

Image type-conversion helpers.

Scaling conventions:

  • Float input is assumed to be in [0, 1] (clipped on conversion to integer).
  • Integer ↔ float conversions scale by class range:
    • uint8 ↔ [0, 1]: ÷255 / ×255
    • uint16 ↔ [0, 1]: ÷65535 / ×65535
    • int16 ↔ [0, 1]: (x + 32768) / 65535 / round(x · 65535) - 32768
  • Integer-to-integer conversions use bit-replication for upscaling (uint8 → uint16: 0xAB → 0xABAB) and rounded scaling for downscaling.

Definition in file type_convert.hpp.