Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Export metrics for glyph scoring? Or return a list of top-scoring codepoints for each character. #126

Open
clort81 opened this issue Jan 29, 2023 · 8 comments
Labels
feature New feature or request

Comments

@clort81
Copy link

clort81 commented Jan 29, 2023

I'd like to have an export of top scored codepoints for each character - not just the best one, but a list of the best scoring glyphs with their codepoint and score number, for each character compared.

Maybe only via the api, or possibly to a file.

I'm just reserving space here others to weigh in with their thoughts on this.

It might be interesting if chafa could report somehow the ideal glyph it's seeking?

To provide something useful, I attach a .png of my current top 256 most popular glyphs, based on a mixed input set of 2300 images.

It was generated by a bash script running chafa:

Piped output to a big ansi file, then

cat chafa_outout.ans |unicp.pl |sort |uniq -c |sort -n > myscores.txt

top256_chafa_scores
Notice that most of these are 'connecting' which means they connect some region(s) between the 4 cardinal directions.
Remember our input images do not know or care where our chatacter boundaries are. When thinking about matching glyphs, don't assume things will line up to your font.

chafa_blapinus_high_score_list.txt.gz
BlapinusCMedium-12.pcf.gz (this is WIP and mappings WILL change)
Obligatory Blapinus pic, 140 columns, 47 lines.
baroque-fantasy-city

baroque-fantasy-city.ans.gz

Here's a sample where you can more easily see the importance of joining-glyphs for rendering real pictures. Since we have no ability to shift the input image to automatically best-match available glyphs, we need particularly horizontal connecting glyphs, at various y locations, including diagonal.

I could go on for pages about the subject. But it would be quite helpful to get an imagemap of poor scoring glyphs (with significant deviation) highlighted in some way, in the output image. Or maybe in an interactive editor.

leavs_align_blapinus2

An even more illustrative example:
blapinus_flower_veins_grid

Resolving text and icons:
blapinus-resolving_text_and_icons

@hpjansson
Copy link
Owner

Very interesting research. I used to have a simple scoring debug dump #ifdefed into part of the library; it was nowhere as comprehensive as this, but I also saw connecting glyphs (and "simple" glyphs -- i.e. borders and blocks, but few alphanumerics) doing well.

I think we can address statistics in two steps:

  1. Add an API method gdouble chafa_canvas_get_fidelity_at (ChafaCanvas *canvas, gint x, gint y); This can be called on each cell after an image has been drawn to the canvas. The returned fidelity denotes how close a match the chosen symbol is to the image material. It will be unitless (in the range 0.0..1.0), but internally I'll probably use squared error. Behind the scenes, it calculates the fidelity value on demand, so as not to clutter/slow down the paint function. Presumably this will be used rarely.
  2. Add a --dump-glyph-statistics switch to the command-line tool. This will actually call the new API method and print one or more tables detailing glyph usage and fidelity. Since the statistics can be gotten per cell, it would even be possible to do something fancy (maybe with a different switch --visualize-glyph-fidelity) that will print the image, replacing the colors with a scale indicating the fidelity of each cell.

How does that sound?

@hpjansson hpjansson added the feature New feature or request label Jan 31, 2023
@clort81
Copy link
Author

clort81 commented Jan 31, 2023

Actually, i discovered chafa does give me a score, based on how much it blends the color of the foreground with the background.
The closer matches get closer to the requested color, the worse matches are blended more.
glyph_fixing_15

I've created a lot more glyps now for blapinus but.. i can't tell how good they are.
I haven't gotten your k-means tests working (python grrrrrrr!)

Also I'd like to see how good a particular glyph is, compared to the next best glyph in the library. A relative score. To find which glyphs i'm drawing are significant and most useful.

I've drawn 4200+ glyphs now and i'm well into the range of diminishing returns for manual labor.

The big problem, as always, is a particular shape not matching well unless the source image is shifted a bit.
This could be changed if your use scenario allows shifting source images, but say a video game chafa'd, or an x server rendered in chafa doesn't allow shifting the input around.
[EDIT]
LOVE those ideas. And a score over nearest competitor statistic would be great.
Maybe you could help me get your k-means running someday if we could chat when you have time.

@hpjansson
Copy link
Owner

4200 is a lot :-)

Sure, we can chat sometime. Granted I haven't run k-means in a while. Are you on Discord or Matrix?

@clort81
Copy link
Author

clort81 commented Feb 1, 2023

Can make a matrix acct. Discord webclient is horribly heavy and slow.
Text is really 'the final frontier' for adding custom glyphs.

A 6x12 font has 2^(6*12) possible shapes, to get everything, which is 4,722,366,482,869,645,213,696 glyphs. 4000 glyphs doesn't cover much of that :)

Would be nice to generate an optimal set for the PUA range someday.

Obligatory pic:
blapinus-demo-prague

@cdluminate
Copy link
Collaborator

cdluminate commented Feb 5, 2023

Ummm.... may I ask the concrete command you used for printing images with the BlapinusCMedium-12.pcf.gz font? I'm trying to reproduce the results but I could not get it using these glyphs.

@clort81
Copy link
Author

clort81 commented Feb 6, 2023

/usr/local/bin/chafa --color-space=din99d --color-extractor=median -p on --symbols bad+diagonal+ue080..ufd7b-ue1ed-u2683-u25a4-u2610-uECD5-u25b3-u21e6-ue84d-u0425-u0432-ue781-ue840-uecce-u0430-u041d-u2662-u255c-u207f-u25e0-uec07-u2265-u0420-u25c5-u263a-u0434-ue846-ue462-ue472-ue4d7-ue1d1-ue1e1-ue49d-ue49b-ue4a8-ue721-ue1d6-u25db-ue70c-u2025-u25ad-u222a-u25a1 --glyph-file /usr/share/fonts/X11/misc/BlapinusDMedium-12.pcf.gz -w 8 -s $(tput cols) ${file}

Added some more glyphs
BlapinusDMedium-12.pcf.gz
blapinus_demo_2023_02
That's 80, 100 and 120 columns.

Manually adding more is getting into diminishing returns. While there's plenty of space left in the PUA range, I don't want to take it all up, so as to leave some for people's other uses.

blapinus-demo-grandmas_dining_room
No stinker glyphs here ^ !
blapinus-demo-medieval_village
Almost none there...

What would be best scoring?

I think the best would be a way for chafa to output the score of the selected glyph, the score of the next best glyph (to mesasure how much better a particular glyphs is from the nearest competitor) -- and optimally a b/w bitmap of the template it was trying to match.

@hpjansson
Copy link
Owner

Side note -- @clort81 you've posted a lot of nice art, would you be ok if I featured some of it on the gallery page? If so, how would you like to be credited? I'd love to add a permanent link to your custom font too if it has a home in a permanent location.

@clort81
Copy link
Author

clort81 commented Feb 21, 2023

Feel free to share the 'chafart' :) You can say Clort operated the tools. It is machine-generated so copyright-free.

The font is work (play) in progress but of course can be shared at any time. It is sil open license, and afaik there's no enforceable copyright on small bitmap glyphs anyway.

I'm working on some scoring for glyphs, samples below. Notice chafa is giving us a 'score' by the amount of blending with background. Sometimes the white source region is rendered almost black.

To automate, I'd like to write a script to use imagemagick to return a .png of the region of the source pic corresponding to each rendered glyph, along with the glyph itself, the codepoint, and a 'score' based on the color output. I can barely code my way out of a paper bag, so this stuff takes me several evenings.

Braille:
clort-chafa_braille_scaling
Blapinus:
clort-chafa_blapinus_scaling

BlapinusEMedium-12.pcf.gz

Having done textart for many years now I pretty well knew what kind of glyphs i really wanted, but with a limited range, it's tough to decide on the compromises. I just keep doing pics like this and seeing which glyphs really ought to get a better variant.
chafa_trees_blapinus
(169 columns, old painting)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants