Skip to content

Instantly share code, notes, and snippets.

@windytan
Last active October 11, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windytan/3844771 to your computer and use it in GitHub Desktop.
Save windytan/3844771 to your computer and use it in GitHub Desktop.
Perl script to read an image of digits
#!/usr/bin/perl
use feature "switch";
open(S,"convert bitit.png gray:-|");
for $y (0..434) {
for $x (0..699) {
read(S,$a,1);
$b[int($x / 27)][int($y / 27)] ++ if (ord($a) < 127);
}
}
close(S);
for $y (0..15) {
$byte = 0;
for $x (0..25) {
$byte <<= 1;
given ($b[$x][$y] // 0) {
when ($_ < 10) { print " "; }
when ($_ < 90) { print "1 "; $byte++; }
default { print "0 "; }
}
}
printf (" 0x%07x\n",$byte);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment