Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Converting animation into lossy charset - how ?
2015-07-12 12:14
Oswald

Registered: Apr 2002
Posts: 5094
Converting animation into lossy charset - how ?

I've always wondered how an algorithm decides how far is a char from another. any pointers ?
 
... 38 posts hidden. Click here to view all posts....
 
2015-07-13 10:28
Oswald

Registered: Apr 2002
Posts: 5094
Quote: @Oswald: You might wanna check out the endless guru-zoomer in Sharp

I'd rather check out a least squares method in pseudo code for a 8x8 matrix :)
2015-07-13 10:30
Oswald

Registered: Apr 2002
Posts: 5094
Quote: I used ELBG for creating an optimal charset, downsampling to c64 colours + dithering should happen after optimal charset was found. For PETSCII however the simple approach was enough so far, but one might restrict the chars being used to have a more graphical appearance without too many letters being used.

okay guys how do you manage to implement those algorithms, its all cryptic to me at Wikipedia. Maybe its my non existant university degree ? I saw in some places partial derivation and shit like that, totally over the top of my head.

- downsampling to c64 colors before dithering ?
- simple method = counting different bits on same loc ? why would one need a better one if character set is not fixed ?
2015-07-13 10:41
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: okay guys how do you manage to implement those algorithms, its all cryptic to me at Wikipedia. Maybe its my non existant university degree ? I saw in some places partial derivation and shit like that, totally over the top of my head.

- downsampling to c64 colors before dithering ?
- simple method = counting different bits on same loc ? why would one need a better one if character set is not fixed ?


Why you need a better version?

Imagine you want:

0001
0011
0111
1111


but you only have these two:
0001 1001
0111 1011
1111 0111
1111 1111


Both have 2 pixels wrong, which one appeals to you most?
2015-07-13 11:04
Oswald

Registered: Apr 2002
Posts: 5094
finally an example which shows that my "gut feeling" method would be better than bit counting. ie: check the 9 pixels around each pixel. some weighing may help, more for the middle, bit less for the diagonals than for the ortogonals.
2015-07-13 13:52
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: finally an example which shows that my "gut feeling" method would be better than bit counting. ie: check the 9 pixels around each pixel. some weighing may help, more for the middle, bit less for the diagonals than for the ortogonals.

This problem generally falls into a domain called pattern matching. Don't forget to weight your selection agains the frequency of the chars. F.e. the screen might be covered by a background char used in 75% of all screen positions. This char is much more important to get right, than a char seldom used. It all boils down to choosing in a way to fool the human brain, especially when you start doing multicolour and gradient, when f.e. luminosity is much more important than actual color.
2015-07-13 14:00
Oswald

Registered: Apr 2002
Posts: 5094
I've googled hours by now on this but no consumable finds for me, I dont know enough to turn wikipedia or papers into code of this subject.

nice pointer with the frequency tho, thanks :)

btw I always tought the mekanix rotator (chess?) is made of an ordered set. this makes it twice as cool.
2015-07-13 16:19
Bitbreaker

Registered: Oct 2002
Posts: 508
Quoting Oswald
okay guys how do you manage to implement those algorithms, its all cryptic to me at Wikipedia. Maybe its my non existant university degree ? I saw in some places partial derivation and shit like that, totally over the top of my head.

- downsampling to c64 colors before dithering ?
- simple method = counting different bits on same loc ? why would one need a better one if character set is not fixed ?


Downsampling in the meaning of reducing a RGB pic to 4 colors charset + dithering. Or interlaced charsets and alike. As for ELBG, it is implemened in ffmpeg/libav. I just wrote a codec to be plugged into ffmpeg and you then can easily use teh elbg implementation form ffmpeg, as well as read all kind of videpo and picture formats as input without any further effort.

I have a degree, but not in computer science. That does not count :-)
2015-07-13 16:34
ChristopherJam

Registered: Aug 2004
Posts: 1409
OK, hope this python script is a little more digestible than wikipedia. Code's not as tidy as it would have been if I'd used numpy array operations instead of looping over indices, but hopefully it's a little clearer what's going on this way. It's pretty naive and has plenty of scope for improvement, but should demonstrate the basic principles.


from random import randint

w,h=64,32
pixels=[[int(((x-25)**2+(y-18)**2)**.5/4)%2 for x in range(w)]for y in range(h)]

for row in pixels:
    print(" ".join(['.@'[x] for x in row]))

tiles=[[pixels[k//(w//8)*8+j//8][k%(w//8)*8+j%8] for j in range(64)] for k in range(w*h//64)]


num_tiles=len(tiles)
cset_size=20

charset=[]
indices=[]
for i in range(cset_size):
    charset.append(tiles[randint(0,len(tiles)-1)])


last_error=1e33

for iteration in range(10):
    # first, find indices
    indices=[]
    counts=[0,]*cset_size
    error_this_iteration=0
    for i in range(num_tiles):
        best_error=1e30
        for j in range(cset_size):
            this_error=0
            for p in range(64):
                delta=(tiles[i][p]-charset[j][p])
                this_error+=delta*delta
            if this_error<best_error:
                best_error=this_error
                best_index=j
        error_this_iteration+=best_error
        indices.append(best_index)
        counts[best_index]+=1
    print"total error =",error_this_iteration
    if error_this_iteration==last_error:
        break
    last_error=error_this_iteration

    #then, replace each char with the average of all the source tiles it's meant to approximate
    charset=[[0 for i in range(64)] for j in range(cset_size)]
    for i in range(num_tiles):
        index=indices[i]
        for p in range(64):
            charset[index][p]+=float(tiles[i][p])/counts[index]

    #..and replace any unused chars with random selections from the original
    for i in range(cset_size):
        if counts[i]==0:
            charset[i]=(tiles[randint(0,len(tiles)-1)])


print("")
for y in range(h):
    for x in range(w):
        i=indices[y//8*(w//8)+x//8]
        print ".@"[int(0.5+charset[i][(y%8)*8+(x%8)])],
    print



(my degree's in Engineering, but I did do some CS units..)
2015-07-13 16:44
Mixer

Registered: Apr 2008
Posts: 452
Quote:
I have a degree, but not in computer science. That does not count :-)


"partial derivative"-stuff -> trick is to find the code example for all the math notated stuff. Everyone can understand code, very few understand math notation.

<offtopic rant>

I've done CS-major studies and some math and in my opinion the best representation of an algorithm is a code example. The mathematical notation used in academia has almost zero practical value. It is a notation for mathematicians and researchers so that they can prove a point. In comparison to that the code example shows the steps that even the mathematician has to take in order to calculate the result.

Also, the math notation is not supported by most charsets anyway and one has to write latex-code or similar coding anyway to show those characters. Not very practical in that sense either. It is too late to stop that train in academia, though. The academia is too deep in that shit already.

</end rant>
2015-07-13 16:56
Oswald

Registered: Apr 2002
Posts: 5094
thanks a lot, totally readable :)
Previous - 1 | 2 | 3 | 4 | 5 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
csabanw
/Panor..
iAN CooG/HVSC
algorithm
Guests online: 88
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.098 sec.