| |
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.... |
| |
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 :) |
| |
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 ? |
| |
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? |
| |
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. |
| |
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. |
| |
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. |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Quoting Oswaldokay 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 :-) |
| |
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..) |
| |
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> |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
thanks a lot, totally readable :) |
Previous - 1 | 2 | 3 | 4 | 5 - Next |