in reply to Re^2: Imagecat - show color images in a terminal
in thread Imagecat - show color images in a terminal
Nice, but trying to play with this I found that it requires PDL::IO::Image which depends on Alien::FreeImage which won't build on modern g++ (it requires -std=c++14 and redefines powf64) and it has security issues (see issues).
Other than that, thanks! Some things to look back at when I encounter similar tasks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Imagecat - show color images in a terminal
by Anonymous Monk on Jul 06, 2023 at 10:12 UTC | |
I suspected result on Linux be wilder than "wrong_setup" because terminals are almost certain to use palette, not pure RGB. "Security"? Life corrects as always.
TIMTOWTDI. One reason to use PDL::IO::Image was to play with its rescale filters (which amounted to nothing) to average glyph bitmap to single pixel. In the end it's arithmetic mean with Imager::scale(qtype => 'mixing',... and itself not necessary neither, could be unpack '%32C*', ... (Another reason for PDL::IO::Image was to use the best what happened to image IO and basic manipulation, for PDL if not Perl. Very sad if it's abandoned. PDL::IO::GD and PDL::IO::Pic don't compare) | [reply] [d/l] [select] |
by Anonymous Monk on Jul 09, 2023 at 23:06 UTC | |
Computations above take noticeable time, as opposed to simple algorithm in OP. If final section is formatted as:
then time is 4.56991696357727 for, ultimately, a single Perl statement; using e.g. DejaVuSansMono and console/font size approximately as used to produce picture above. Not cheap. For 10 brushes (i.e. glyphs from this font) and all combinations of FG/BG colors (16*16), the palette size upper limit is 2560. It was reduced to 'only' 1854, excluding trivial duplicates. Distorted image size is 142 by 89. For each of its 12638 pixels, calculate 1854 distances with https://en.wikipedia.org/wiki/Color_difference#CIEDE2000and pick the best palette index, i.e. ~23e6 times. Maybe we are lucky we have PDL, and this horrible formula was already implemented in C. Unfortunately, it's immediately obvious it'll take same long time if image is a flat single color rectangle (or simple logo, etc.), while it must be 12638 times faster! For our test image, distorted and scaled to 142x89, only half (6265 out of 12638) RGB triplets are unique (Imager::getcolorcount). It follows, run time should be twice as low. I didn't find anything w.r.t. 'memoization' and PDL, maybe not tried hard enough? Duplication in arrays and expensive computations are inevitable. It only requires to reduce fat data to unique slim set, keeping track how to fatten result to original shape. Not 'memoization' per definition, but in spirit.
And time now is exactly as predicted: 2.25233697891235. (PDL has uniq and uniqind pair. But only uniqvec i.e. no uniqvecind. Hence workaround with vector enumeration) ############### In fact, RGB (or Lab) points in palette are spaced so very sparsely. If further speed is required, some precision can be sacrificed, and even slimmer dataset fed to expensive formula. With
i.e. RGB in image reduced to 7 bits (if GD always does it (to alpha), why can't we?), time becomes 1.3685450553894. With 2 bits zeroed, it's 0.765566825866699; and result is practically the same if observer was not warned. With reduction to 5 bits (again 2x faster) the picture is beginning to feel slightly uncomfortable compared to 'lossless' result. ############### W.r.t. need to sever above, I'm confused if clump creates dataflow. But what follows looks like plain bugs:
So far, only uniqvec looks weird. But:
What?! But I only printed the $y, compared to 1st demo. | [reply] [d/l] [select] |
by etj (Priest) on Feb 02, 2024 at 16:53 UTC | |
| [reply] [d/l] [select] |
by etj (Priest) on Feb 03, 2024 at 03:36 UTC | |
Here is the test I've constructed from your cases above. Interestingly, only the [0,1] case (don't physicalise the clump-ee, and mutate the clump-ee rather than the original) works perfectly, as you note above. Also interestingly, my first go at this using $pdl->flat->unpdl produced different results from $pdl->unpdl.
| [reply] [d/l] [select] |
by etj (Priest) on Feb 10, 2024 at 23:59 UTC | |
Interestingly enough, this bug got reported independently by different people as a GitHub issue, on here, and on the mailing-list, in the last month or so, despite having existed for nearly 2 years. | [reply] |
by etj (Priest) on Feb 02, 2024 at 20:55 UTC | |
Another way to read images into PDL with lots of capability is PDL::OpenCV::Imgcodecs. | [reply] [d/l] [select] |