PDL::ImageRGB#
📦 stdpdl
Utility functions for RGB image data: palette quantisation, palette lookup, conversion to grey, and scaling to bytes.
use PDL;
use PDL::ImageRGB;
print rgbtogr(byte([[10, 20, 30]])), " ", bytescl(pdl(0, 500, 1000), 100), "\n"; # [18] [0 50 100]
my $lut = byte([[0, 0, 0], [255, 255, 255]]);
print interlrgb(byte(1, 0), $lut)->flat, "\n"; # [255 255 255 0 0 0]
An RGB image here is (3, width, height). cquant($image, $ncolours) reduces an RGB byte image to a palette image and its colour table; interlrgb($palette_image, $lut) turns one back into RGB; rgbtogr converts RGB to grey levels; bytescl scales an ndarray into 0..255 (or another top) as bytes.
This is PDL::ImageRGB of PDL 2.106: upstream’s Perl, unchanged, over PDL’s own cquant_c kernel (ppm_quant) run by pperl’s engine.