Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mapping an array to an alphabet

9 views
Skip to first unread message

Vijay L

unread,
Nov 1, 2002, 11:46:40 AM11/1/02
to
I'm working (on and on and on ...) on a program that converts a BMP
image to text. I don't know what this is called, so I can't search for
it. I got it via email from a friend who got it from a friend ... so I
can't pin down the source either.
Here's the image that inspired me to start upon it:
Please note that /I did not do this/.

%Y=iiiii+VXRRXXXXXXXRRRBBBBMMMBBVYt=;,,tBBMMMBBBBMMR
%Y;:=+ttIYXRRXXXXXXXRRRRRRBMBBBRVYI+;,,:YMMMBBBBBMMR
%Y;;;;;=+XVtYVVVVVXXXRRRRXBMBBBRVYIt;,,,:RBBBBBBBBMX
%I=:;=+;=t==+ttIYYVVVXXXXXRXXXXVIt++=,,,,+BBBBBBBMMV
%I++ii:.++;;;;+tYVVVVXRRRRRRRRXXYtt+=,,,,,RBBBBBBMBX
%Y+tII:.I+=+=+IYVXXXXRRRXRRRRBRRVYYIi;,,,,IBBBBBBBBX
%Y+IYI..Vt++tIi+;:..:;iIIYVIii:,,,;===:::,iBBMMBMMMR
%YiIt+tiItiII;::+i++,..,=Yi,...:=++;,:;;;:+i=:IBMMMB
%YiI..;==iIXi=iit:..;=,=IXI;.:=+;,:ti=ii;:::,,:BMMMR
%Yit,+I+.+VXXYVi+++==+t+VXXt=;,,;==iiYYi=,,:+:YMMMMR
%Iii;I;.;+iVXYItIttIYVIIXRRViiYIttIYVVYt=+,:+IMMMMWR
%Yi:.tY;+i:tIVYXRRRRVtiXRRRXI=iYXRRRXVI+==;iXMMMMWWR
%Ii:,+XIIi++YXXVtIt=:YRXRRRVtVI:=iitIIi+++itMMWWWWWR
%It:=IBMRRV==i+;,..+ii+IYIti+===;,:====+YIIBMMMWWWWB
%It:;IBMXYI+;;,,.;YVYVt::..:,=IIII,,::=tYYRMMMWWWWWR
%II++IMBVBBY;:;,iii;:.......:;,:==t+;;+RBBMMMMWWWWWR
%It;=IMRYMBtY=;:+,=ti++;;;;;=;=+=;ii:+RBMBMBMMMWWWWR
%ti+XMWWBMBIBBt::itttiiIIIti=+ttit:,:=RBMBMBBMMMWWWB
%ti+BMWWWMMMMBRY;=tYI+===;===tItti:,:==IRMMBMMMMWWWR
%titMWWWWMMMBBBBXt;=iYVYYVVVVVt+:.,;++iiIXRBMMWWWWWX
%XtIWWWWMMMMBBBBRRt;,.,::::,,,,,,:==+tIVXXVVRBMWWWWX
%XtVWMMWMMMMMBBBRXI+==+:......,,,;ittIVXRXXXXRBRRWWX
%XtXBMMMWMMWMBBRBVI+t+.....,.,,:;+iIIIVXRRXXXRBRRRRX
%XtIYIYVXRRBBBBBRVY=::,:;::::==+tIYVVXVVXXRRBBBBRBBX

You must see it in some fixed-width font for it to make any sense.
Seeing it with a background darker than the foreground will show that
it is the picture of Mohandas Karamchand Gandhi, The Father of our
Indian Nation. (If you've never seen a picture of him before, then
just take my word upon it).

I've written the program to convert a two-bit color depth BMP image to
text, however, because only two colors are used I lose a lot of detail
in my images and the most important features of the face such as eyes,
nose, mouth don't come out very well.

In any conversion from image to text, the horizontal width will always
be less than the vertical. To make up for this, I take 8 pixels on the
horizontal and 14 on the vertical as an array and map this to an
alphabet.

Note that a sequence of numbers can be taken as a 2-D array of bits,
which is how I treat it. The vectors are as: (255 0 17 35 23
...fourteen numbers)
Each number is 8 pixels on the horizontal and there are 14 numbers for
the vertical. For example, a white block with a black cross running
along its vertical and horizontal centers would be:
(231 231 231 231 231 231 0 0 231 231 231 231 231 231)

11100111
11100111
11100111
11100111
11100111
11100111
00000000
00000000
11100111
11100111
11100111
11100111
11100111
11100111

0 - black; 1 - white

The mapping function is defined thus:
It takes one 8 x 14 portion of the image and maps it to a letter.
I know that instead of keeping the key of the alist ALPHA as a list, I
can keep it as the number of bits each numbers take, but since this is
not the completed program, I keep it so, so that I can visualize the
image. And it will be better as a hash table, but efficiency is not my
prime concern just yet.
(let
((alpha
'(((0 0 0 0 0 0 0 0 0 0 0 0 0 0) . (#\M #\W #\N))
((255 255 255 255 255 255 255 255 255 255 255 255 255 255) .
(#\Space))
((1 1 1 1 1 1 1 1 1 1 1 1 1 1) . (#\8 #\K #\B #\Space))
((3 3 3 3 3 3 3 3 3 3 3 3 3 3) . (#\O #\D #\B #\Q #\Space))
((7 7 7 7 7 7 7 7 7 7 7 7 7 7) . (#\T #\I #\H #\X #\J #\Space))
((15 15 15 15 15 15 15 15 15 15 15 15 15 15) . (#\*))
((0 0 0 0 0 0 0 1 1 1 1 1 1 1) . (#\Space))
((1 1 1 1 1 1 1 0 0 0 0 0 0 0) . (#\* #\^))
((64 64 64 64 64 64 64 64 64 64 64 64 64 64) . (#\| #\\ #\/ #\{
#\} #\!))
((127 127 127 127 127 127 127 127 127 127 127 127 127 127) . (#\.
#\`))
)))
(defun map-vect--alpha (numvect)
;;Assume that NUMVECT is a list
(flet ((heuristic (numvec1 numvec2)
(apply #'+ (mapcar #'(lambda (x y)
(abs (- x y)))
(mapcar #'logcount numvec1)
(mapcar #'logcount numvec2)))))
(let ((smallest most-positive-fixnum)
(smalli 0) ;smallest-index
(i 0))
(dolist (v alpha)
(let ((heur (heuristic (car v) numvect)))
(when (<= heur smallest)
(setf smallest heur
smalli i))
(when (zerop heur) (return)))
(incf i))
(random-item (cdr (elt alpha smalli)))))))

(defun random-item (sequence)
(elt (random (length sequence)) sequence))

Now my problem is that if I update this mapping to accomodate images
with 256 color depth I will be dealing with 64 bit numbers. While this
is possible in Lisp, I cannot enumerate so many combinations of lists
of length 14 and map them to each alphabet. Can someone please give me
a suggestion for a better mapping algorithm, or a link.

At first I thougth of including the code that seperates the image into
vectors, but, it is some 80+ lines, and this post is quite long in
itself. If however you need to see it, I can email it to you or post
it here. I don't have a webpage.

Thanks,

Vijay L

rif

unread,
Nov 1, 2002, 12:21:59 PM11/1/02
to

I assume you're familiar with AA-lib?
http://aa-project.sourceforge.net/aalib/

rif

Tim Lavoie

unread,
Nov 1, 2002, 2:40:29 PM11/1/02
to
>>>>> "Vijay" == Vijay L <vij...@lycos.com> writes:

Vijay> I'm working (on and on and on ...) on a program that
Vijay> converts a BMP image to text. I don't know what this is
Vijay> called, so I can't search for

Vijay> it. I got it via email from a friend who got it from a
Vijay> friend ... so I

Vijay> can't pin down the source either. Here's the image that
Vijay> inspired me to start upon it: Please note that /I did not
Vijay> do this/.

[ snip ]

Vijay> (defun random-item (sequence) (elt (random (length
Vijay> sequence)) sequence))

Vijay> Now my problem is that if I update this mapping to
Vijay> accomodate images with 256 color depth I will be dealing
Vijay> with 64 bit numbers. While this

Vijay> is possible in Lisp, I cannot enumerate so many
Vijay> combinations of lists of length 14 and map them to each
Vijay> alphabet. Can someone please give me

Vijay> a suggestion for a better mapping algorithm, or a link.

Hm. Instead of mapping groups of pixels to color indexes, why not
pre-process the image to be friendlier to your mapping? For instance,
you can average a group of pixels to one gray-scale value, using the
aspect ratio of the font to scale as you suggest. Once you have done
this for the entire image, you have much, *MUCH* less to map to an
arbitrary alphabet.

If you really want to preserve information about the group of pixels,
such as mapping to which pixels are "on" within each typeface
character, you would probably still map the pixels to a much smaller
bit-depth (i.e. 1), using a threshold or maybe some dithering, and
just compare the font characters to see which maps the closest for
that group of pixels. This might look pretty good actually, though of
course the results are text-dependent, and would vary more by typeface
than the first method.

Tim

--
"Some civil servants are neither servants nor civil."
-- Winston Churchill

Pierpaolo BERNARDI

unread,
Nov 1, 2002, 3:50:14 PM11/1/02
to

"Vijay L" <vij...@lycos.com> ha scritto nel messaggio news:1eaf81aa.02110...@posting.google.com...

> I'm working (on and on and on ...) on a program that converts a BMP
> image to text. I don't know what this is called, so I can't search for
> it.

What you are doing is called ascii-art.

There are several newsgroup which discuss this topic, and
gazillions of web sites.

P.

Vijay L

unread,
Nov 2, 2002, 12:09:27 PM11/2/02
to
"Pierpaolo BERNARDI" <pierpaolo...@hotmail.com> wrote in message news:<aOBw9.60257$aL4.1...@news1.tin.it>...

Ascii-Art, what an apt name. Thanks for the link Rif, no I wasn't
familiar with the link because I didn't know it was called Ascii-Art.
Thanks for the same Pierpaolo.

Also thanks for the tips Tim, I've forgotten what we learnt on
graphics 3 semesters ago, now is a good time for me to go back and
brush up upon them. Also I didn't know Lisp then so I've never had any
hands-on experience with things such as dithering etc. As for the
other suggestion: preprocessing, I only understand vaguely what your
talking about, therefore I need to do research.

Thanks

Vijay L

Tim Lavoie

unread,
Nov 2, 2002, 1:00:55 PM11/2/02
to
>>>>> "Vijay" == Vijay L <vij...@lycos.com> writes:

Vijay> Also thanks for the tips Tim, I've forgotten what we learnt
Vijay> on graphics 3 semesters ago, now is a good time for me to
Vijay> go back and brush up upon them. Also I didn't know Lisp
Vijay> then so I've never had any hands-on experience with things
Vijay> such as dithering etc. As for the other suggestion:
Vijay> preprocessing, I only understand vaguely what your talking
Vijay> about, therefore I need to do research.

Heh. Yeah, I was sort of rambling. I'll see if I can come with a
better explanation, or at least try some of it out myself and come
back with examples.

Tim

Larry Clapp

unread,
Nov 2, 2002, 2:33:07 PM11/2/02
to
In article <1eaf81aa.0211...@posting.google.com>, Vijay L wrote:
> "Pierpaolo BERNARDI" <pierpaolo...@hotmail.com> wrote in message news:<aOBw9.60257$aL4.1...@news1.tin.it>...
>> "Vijay L" <vij...@lycos.com> ha scritto nel messaggio news:1eaf81aa.02110...@posting.google.com...
>> > I'm working (on and on and on ...) on a program that
>> > converts a BMP image to text. I don't know what this is
>> > called, so I can't search for it.
>>
>> What you are doing is called ascii-art.
>>
>> There are several newsgroup which discuss this topic, and
>> gazillions of web sites.
>>
>> P.
>
> Ascii-Art, what an apt name. Thanks for the link Rif, no I
> wasn't familiar with the link because I didn't know it was
> called Ascii-Art. Thanks for the same Pierpaolo.

The link rif provided sure looks promising. This

http://netpbm.sourceforge.net/doc/pbmtoascii.html

might also help. I haven't tried it, but the manpage looks
promising.

-- Larry

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----

Rob Warnock

unread,
Nov 2, 2002, 4:31:46 PM11/2/02
to
Vijay L <vij...@lycos.com> wrote:
+---------------

| "Pierpaolo BERNARDI" <pierpaolo...@hotmail.com> wrote:
| > What you are doing is called ascii-art.
| > There are several newsgroup which discuss this topic, and
| > gazillions of web sites.
|
| Ascii-Art, what an apt name. Thanks for the link Rif, no I wasn't
| familiar with the link because I didn't know it was called Ascii-Art.
+---------------

Also note that ASCII art (both the name & the result) is *VERY* old!!
People were already doing it when I got into computing in the late 1960's.

In those days, one used line printers (I know, something most people
have gladly forgotten about!!) to print on fan-fold paper (another thing
probably best forgotten!) poster-sized pictures of various kinds. There
was even soft-porn already, in the form of life-sized pin-up girls... ;-}


-Rob

-----
Rob Warnock, PP-ASEL-IA <rp...@rpw3.org>
627 26th Avenue <URL:http://www.rpw3.org/>
San Mateo, CA 94403 (650)572-2607

Erik Naggum

unread,
Nov 2, 2002, 4:37:07 PM11/2/02
to
* rp...@rpw3.org (Rob Warnock)

| In those days, one used line printers (I know, something most people
| have gladly forgotten about!!) to print on fan-fold paper (another thing
| probably best forgotten!) poster-sized pictures of various kinds. There
| was even soft-porn already, in the form of life-sized pin-up girls... ;-}

Let us not forget the Snoopy Calendars. I grew up with those...

--
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

Brian Palmer

unread,
Nov 2, 2002, 7:51:36 PM11/2/02
to
Rob Warnock wrote:
>
> Also note that ASCII art (both the name & the result) is *VERY* old!!
> People were already doing it when I got into computing in the late 1960's.
>
> In those days, one used line printers (I know, something most people
> have gladly forgotten about!!) to print on fan-fold paper (another thing
> probably best forgotten!) poster-sized pictures of various kinds. There
> was even soft-porn already, in the form of life-sized pin-up girls... ;-}

It would also use overprinting to increase the resolution of the output.
Rather than a single line of output per line, it would use a CR (without
LF) to combine characters and get a really good approximation of pin-up
girls. :)

Vijay L

unread,
Nov 3, 2002, 9:35:05 AM11/3/02
to
Larry Clapp <la...@theclapp.org> wrote in message
>
> The link rif provided sure looks promising. This
>
> http://netpbm.sourceforge.net/doc/pbmtoascii.html
>
> might also help. I haven't tried it, but the manpage looks
> promising.
>
It is.
http://netpbm.sourceforge.net/doc/pbm.html
seems to have what I wanted: computer code ,in C, for the generation
of AA. Will follow it up in more detail when I get the time. It seems
to lead to pages and pages of C code.

Thanks,

Vijay L

Matthias Buelow

unread,
Nov 4, 2002, 3:00:40 PM11/4/02
to
Rob Warnock wrote:

> People were already doing it when I got into computing in the late 1960's.
>
> In those days, one used line printers (I know, something most people
> have gladly forgotten about!!) to print on fan-fold paper (another thing
> probably best forgotten!) poster-sized pictures of various kinds. There
> was even soft-porn already, in the form of life-sized pin-up girls... ;-}

This was also known entertainment in the mid-80s on 8-bit homecomputers,
where, despite many of the 9-pin matrix printers having had some kind of
(limited) bitmap graphics ability, there were programs available to
print whole posters of a nude Samantha Fox with the printer's monospaced
font.

--
Matthias Buelow

0 new messages