ImageRGB(3pm)

πŸ“¦
version 2.085 Β· 4 versions
, in ubuntu noble

✨ ImageRGB(3pm) ✨

okay bestie, gather round, because this is PDL::ImageRGB β€” the Perl manual page for a whole lil grab-bag of utility functions for RGB image data handling πŸ’– and yes she's filed under section 3pm, she's a Perl module, she's iconic, periodt.


🌸 NAME 🌸

PDL::ImageRGB β€” some utility functions for RGB image data handling πŸŽ€


πŸ’… DESCRIPTION πŸ’…

So basically it's a collection of a few commonly used routines that are all about handling RGB, palette and grayscale images. ngl it's not much more than a start β€” she's giving "first draft, but cute". That said, it should be a good place to exercise some of the broadcast/map/clump PP stuff πŸ”₯ iykyk.

Other stuff that should/could go here (aka the someday-maybe wishlist):

  • color space conversion 🌈
  • common image filters ✨
  • image rebinning πŸ¦‹

🫢 SYNOPSIS 🫢

use PDL::ImageRGB;

that's it. that's the whole vibe check. slay.


πŸ‘‘ FUNCTIONS πŸ‘‘

πŸ“ cquant

quantize and reduce colours in 8-bit images

($out, $lut) = cquant($image [,$ncols]);

This one does color reduction for <=8bit displays, and she accepts 8bit RGB images and 8bit palette images, no cap. How? Through an interface to the ppm_quant routine from the pbmplus package, which implements the median cut routine β€” and that routine intellegently picks the 'best' colors to represent your image on a <= 8bit display (based on the median cut algorithm). main character energy fr fr.

Optional args: $ncols sets the maximum nunmber of colours used for the output image, and it defaults to 256 if you don't say anything.

Real talk tho: there are images where a different color reduction scheme gives better results β€” it seems this is true for images containing large areas with very smoothly changing colours 😭 so don't come for her if your gradient-heavy pic looks a lil crunchy.

Returns a list containing the new palette image (type PDL_Byte) and the RGB colormap. πŸ’–

πŸ¦‹ interlrgb

Make an RGB image from a palette image and its lookup table.

$rgb = $palette_im->interlrgb($lut)

Input should be of an integer type, and the lookup table should be (3,x,...). She'll perform the lookup for any N-dimensional input pdl β€” i.e. 0D, 1D, 2D, ... β€” so literally all shapes are welcome, we don't gatekeep 🫢.

She uses the index command, but she will not dataflow by default. If you want it to dataflow, the dataflow_forward flag must be set in the $lut ndarray. You can do that by saying:

$lut->set_dataflow_f(1)

and then it's dataflowing, bestie πŸ’…

🌈 rgbtogr

Converts an RGB image to a grey scale using standard transform

$gr = $rgb->rgbtogr

Performs a conversion of an RGB input image (3,x,....) to a greyscale image (x,.....) using the standard formula:

Grey = 0.301 R + 0.586 G + 0.113 B

math but make it fashion ✨

πŸŽ€ bytescl

Scales a pdl into a specified data range (default 0-255)

$scale = $im->bytescl([$top])

By default $top=255. Otherwise you have to give the desired top value as an argument to bytescl. Normally bytescl doesn't rescale data that already fits in the bounds 0..$top β€” she only does the type conversion if it's required. lowkey polite of her.

But if you want to force it to rescale so that the max of the output is at $top and the min is at 0, you give a negative $top value to indicate this. Negative = assertive, got it πŸ‘‘


πŸ’€ BUGS πŸ’€

This package doesn't yet contain enough useful functions! 😭 that's the whole bug report. she said it herself. we love a self-aware queen.


🌟 AUTHOR 🌟

Copyright 1997 Christian Soeller <c.soeller@auckland.ac.nz> All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.


and that's the whole page, bestie β€” this was ImageRGB(3pm) from perl v5.38.2, dated 2024-04-10. go forth and quantize responsibly πŸ’œπŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from