I've spent over a week writing Sp00kyFox's modified Scale2x algorithm in Python, along with adding rules for long staircases of up to 3 pixels.

This is the algorithm in pseudocode after calculating the luma values:

*Note: Equality is used as being synonymous with "similar enough".*
```
J
A B C
K D E F L
G H I
M

E >> 1 2
3 4

if ( # top left
B == D and B != F and D != H and (
E != A or E == C or E == G or A == J or A == K)):

E1 = min(B, D)

if C != G: # 2px staircase
if B == D == G == J and B != CJ: B4 = E
if B == C == D == K and D != GK: D4 = E

if CL != GM: # 3px staircase
if B == D == G == J == JJ == GM and B != CJ: E3 = min(B, D)
if B == C == D == K == KK == CL and D != GK: E2 = min(B, D)

if ( # top right
B == F and B != D and F != H and (
E != C or E == A or E == I or C == J or C == L)):

E2 = min(B, F)

if A != I: # 2px staircase
if A == B == F == L and F != IL: F3 = E
if B == F == I == J and B != AJ: B3 = E

if AK != IM: # 3px staircase
if A == B == F == L == LL == AK and F != IL: E1 = min(B, F)
if B == F == I == J == JJ == IM and D != AJ: E4 = min(B, F)

if ( # bottom left
D == H and B != D and F != H and (
E != G or E == A or E == I or G == K or G == M)):

E3 = min(D, H)

if A != I: # 2px staircase
if A == D == H == M and H != IM: H2 = E
if D == H == I == K and D != AK: D2 = E

if AJ != IL: # 3px staircase
if A == D == H == M == MM == AJ and H != IM: E1 = min(D, H)
if D == H == I == K == KK == IL and D != AK: E4 = min(D, H)

if ( # bottom right
F == H and B != F and D != H and (
E != I or E == C or E == G or I == L or I == M)):

E4 = min(F, H)

if C != G: # 2px staircase
if F == G == H == L and F != CL: F1 = E
if C == F == H == M and H != IM: H1 = E

if CL != GM: # 3px staircase
if F == G == H == L == LL == GJ and F != CL: E3 = min(F, H)
if C == F == H == M == MM == CJ and H != IM: E2 = min(F, H)
```
As much as I love xBRZ, I dislike that it adds antialiasing, and it doesn't straighten staircases longer than 2px.


My Scale2xSFX derivative may have trouble with thin anti-aliased lines (and I have yet to figure out how to solve this without bringing back old Scale2x artifacts), but at least my staircase rules work (and hopefully I wrote the pseudocode correctly for you guys, or it won't work the same).

The purpose of this algorithm is to prep my pixel drawings for vectorization.
I've spent over a week writing Sp00kyFox's modified Scale2x algorithm in Python, along with adding rules for long staircases of up to 3 pixels. This is the algorithm in pseudocode after calculating the luma values: *Note: Equality is used as being synonymous with "similar enough".* ``` J A B C K D E F L G H I M E >> 1 2 3 4 if ( # top left B == D and B != F and D != H and ( E != A or E == C or E == G or A == J or A == K)): E1 = min(B, D) if C != G: # 2px staircase if B == D == G == J and B != CJ: B4 = E if B == C == D == K and D != GK: D4 = E if CL != GM: # 3px staircase if B == D == G == J == JJ == GM and B != CJ: E3 = min(B, D) if B == C == D == K == KK == CL and D != GK: E2 = min(B, D) if ( # top right B == F and B != D and F != H and ( E != C or E == A or E == I or C == J or C == L)): E2 = min(B, F) if A != I: # 2px staircase if A == B == F == L and F != IL: F3 = E if B == F == I == J and B != AJ: B3 = E if AK != IM: # 3px staircase if A == B == F == L == LL == AK and F != IL: E1 = min(B, F) if B == F == I == J == JJ == IM and D != AJ: E4 = min(B, F) if ( # bottom left D == H and B != D and F != H and ( E != G or E == A or E == I or G == K or G == M)): E3 = min(D, H) if A != I: # 2px staircase if A == D == H == M and H != IM: H2 = E if D == H == I == K and D != AK: D2 = E if AJ != IL: # 3px staircase if A == D == H == M == MM == AJ and H != IM: E1 = min(D, H) if D == H == I == K == KK == IL and D != AK: E4 = min(D, H) if ( # bottom right F == H and B != F and D != H and ( E != I or E == C or E == G or I == L or I == M)): E4 = min(F, H) if C != G: # 2px staircase if F == G == H == L and F != CL: F1 = E if C == F == H == M and H != IM: H1 = E if CL != GM: # 3px staircase if F == G == H == L == LL == GJ and F != CL: E3 = min(F, H) if C == F == H == M == MM == CJ and H != IM: E2 = min(F, H) ``` As much as I love xBRZ, I dislike that it adds antialiasing, and it doesn't straighten staircases longer than 2px. My Scale2xSFX derivative may have trouble with thin anti-aliased lines (and I have yet to figure out how to solve this without bringing back old Scale2x artifacts), but at least my staircase rules work (and hopefully I wrote the pseudocode correctly for you guys, or it won't work the same). The purpose of this algorithm is to prep my pixel drawings for vectorization.
0 Comments 0 Shares 9 Views
InkBlot Art https://beta.inkblot.art