EECS 741 Computer Vision

Semester Project:
Random Character Stereogram

Kang SoonLai 546307
28 April 1996



  1. Introduction
  2. Theory
  3. Algorithm
  4. Requirement
  5. Source
  6. More Stereograms


Introduction

Stereograms are images that look like random dots or with repeating patterns, but if you "know" how to see it, you will see some 3D images in them. A random character stereogram uses ASCII characters as the random patterns to achive the goal of st ereograms. I have always had the interest in how the stereograms are made or generated, and one day I had the chance to come across to how they were made, so I picked it as my semester project.

The theory behind it is simple, and the algorithm is easy as well.

Theory

This section is just going to explain how random character stereograms work in brief, not in too detail.

Figure below shows one of the keys to stereograms: divergent viewing or focusing on one point behind the image.

			focus point
			    *
			   . .
			  .   .		picture
            	   ------a-----b-----
			.       .
		       .         .
		      .           .
		     .             .
		    LI		   RI
When our two eyes (LI=left eye, RI=right eye) focus on a point * behind the picture, we see two different things(LI sees a and RI sees b). Our brain mixes these two things into single image. Stereograms use this mixing to produce depth in our mind.





			focus point
			    *
		
	
	1234567890123456789012345678901234567890	




		    LI		   RI
The second basic concept is the repeating pattern. Figure on top shows a repeating pattern, 1234567890, runs from left to right and repeats itself for the width of the image. The repeating pattern must have these four propeties in order for the stereograms to work:
  1. The pattern runs horizontally.
  2. There is a fixed set of elements in the pattern.
  3. All elements in the pattern are same size.
  4. The width of the pattern is less than the distance between our eyes.
Among all, property 4 is critical with respect to a stereogram's final output. A good guess of the width is 1 inch, that is about 6 characters long. However, if one is to view it from far away, then it could be wider than that. According to my experience, it is easier to view it from farther away.

When an element is deleted from the repeating sequence,

			 1 (a 1 is removed)
                1234567890234567890 
our brain will see something like this:
		1234567890
			 1
			 234567890
Therefore, by deleting an element from the repeating sequence, we see something that is closer to us.

However, by adding an element to the pattern will create something that looks farther away from us.

			  A (an A is inserted)
		1234567890A1234567890
			
			we see
			
			 1234567890
			 A
		1234567890
Thus, by shortening and lenghtening the pattern, we are able to create an object which looks farther or closer to us, 3D effect. The amount of elements that we added or deleted creates different depth level. Difference of 1 creates a depth of 1, and difference of 3 creates depth level of 3, and so on.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-\BXSY-\B
If you can really see it, it should look something like this:
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000011000001100000000000000000000
000000000000000001111110111111000000000000000000
000000000000000011111111111111100000000000000000
000000000000000111111111111111110000000000000000
000000000000000111111111111111110000000000000000
000000000000000111111111111111110000000000000000
000000000000000011111111111111100000000000000000
000000000000000000111111111110000000000000000000
000000000000000000001111111000000000000000000000
000000000000000000000111110000000000000000000000
000000000000000000000001000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000

Algorithm

The algorithm involved here is simple and straight forward.
  1. Open the image file to be processed
  2. Read a line from the image file, $line
  3. $last_pix=substr($line,0,1)
  4. Loop through the $line
    1. $current_pix=substr($line,$i,1)
    2. if ($current_pix > $last_pix)
      shorten_pattern
    3. if ($current_pix < $last_pix)
      lengthen_pattern
    4. assign a char from the pattern to output line, $output
    5. $last_pix=$current_pix
  5. Perform random character substitution
  6. Go back to 2 until EOF
One hard part that I faced in the algorithm was the shortening and the lenghtening parts. I will explain that in more detail here.

Shortening
After a pattern is shortened, it carries the shortened pattern over the rest of the same line until it is shortened or lengthened again. For example, assume that the pattern width is 6:

Input:		000000000000000111111111222222222333333333

Output:		ABCDEFABCDEFABCEFABCEFABEFABEFABEABEABEABE
			       ^--------^========^________
			       | new    |	 |
			       | pattern|	 |
			       |	|	 |
			       | EFABC 	| EFAB	 | ABE
Notice that everytime the pattern is shortened, it remains at that length until it is shortened or lengthened again. For the above example, the length went from 6 -> 5 -> 4 -> 3.

Lengthening
Lengthening shares the same algorithm as the shortening. Instead of deleting element from the sequence, it adds element to the sequence pattern. There are two ways of inserting the extra element to the pattern:

For me, I used the the method. Here is another example of a more complex input:
	
Input:	333333333333333222222222222111111111100000000000000

Output:	ABCDEFABCDEFABCCDEFABCCDEFAABCCDEFAABBCCDEFAABBCCDE
		       ^-----------^=========^_____________
		       | new 	   |         |             
		       | pattern   |         |             
		       | CDEFABC   |ABCCDEFA | BCCDEFAAB   

Here I present with the phases of the process:

Phase 1, Input Image

000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000011000001100000000000000000000
000000000000000001111110111111000000000000000000
000000000000000011111111111111100000000000000000
000000000000000111111111111111110000000000000000
000000000000000111111111111111110000000000000000
000000000000000111111111111111110000000000000000
000000000000000011111111111111100000000000000000
000000000000000000111111111110000000000000000000
000000000000000000001111111000000000000000000000
000000000000000000000111110000000000000000000000
000000000000000000000001000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000



Phase 2, Sequencial Pattern
 
                     *     *                     
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFACDDEFACDEEFACDEEFACDEEFACDEEF
ABCDEFABCDEFABCDEABCDEAACDEAACCDEAACCDEAACCDEAAC
ABCDEFABCDEFABCDFABCDFABCDFABCDDFABCDDFABCDDFABC
ABCDEFABCDEFABCEFABCEFABCEFABCEFFABCEFFABCEFFABC
ABCDEFABCDEFABCEFABCEFABCEFABCEFFABCEFFABCEFFABC
ABCDEFABCDEFABCEFABCEFABCEFABCEFFABCEFFABCEFFABC
ABCDEFABCDEFABCDFABCDFABCDFABCDDFABCDDFABCDDFABC
ABCDEFABCDEFABCDEFBCDEFBCDEFBBCDEFBBCDEFBBCDEFBB
ABCDEFABCDEFABCDEFABDEFABDEEFABDEEFABDEEFABDEEFA
ABCDEFABCDEFABCDEFABCEFABCCEFABCCEFABCCEFABCCEFA
ABCDEFABCDEFABCDEFABCDEAABCDEAABCDEAABCDEAABCDEA
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF
ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF





Phase 3, Random Character Pattern

                     *     *                     
RV``8VRV``8VRV``8VRV``8VRV``8VRV``8VRV``8VRV``8V
)UJUZT)UJUZT)UJUZT)UJUZT)UJUZT)UJUZT)UJUZT)UJUZT
HaB8NCHaB8NCHaB8NCHaB8NCHaB8NCHaB8NCHaB8NCHaB8NC
YLP*UfYLP*UfYLP*UfYLP*UfYLP*UfYLP*UfYLP*UfYLP*Uf
1'LKK_1'LKK_1'LKK_1'LKK_1'LKK_1'LKK_1'LKK_1'LKK_
Q:CCbIQ:CCbIQ:CCbIQ:CCbIQ:CCbIQ:CCbIQ:CCbIQ:CCbI
lO422XlO422XlO422Xl4222Xl4222Xl4222Xl4222Xl4222X
==\bI'==\bI'==\bI==\bI==\bI==\\bI==\\bI==\\bI==\
*iNgE-*iNgE-*iNg-*iNg-*iNg-*iNgg-*iNgg-*iNgg-*iN
X:2P8OX:2P8OX:28OX:28OX:28OX:28OOX:28OOX:28OOX:2
"Ws$LU"Ws$LU"WsLU"WsLU"WsLU"WsLUU"WsLUU"WsLUU"Ws
9LQ5=C9LQ5=C9LQ=C9LQ=C9LQ=C9LQ=CC9LQ=CC9LQ=CC9LQ
:mbOIB:mbOIB:mbOB:mbOB:mbOB:mbOOB:mbOOB:mbOOB:mb
TJd'JQTJd'JQTJd'JQJd'JQJd'JQJJd'JQJJd'JQJJd'JQJJ
/U'DBU/U'DBU/U'DBU/UDBU/UDBBU/UDBBU/UDBBU/UDBBU/
URL=XMURL=XMURL=XMURLXMURLLXMURLLXMURLLXMURLLXMU
fOLWW@fOLWW@fOLWW@fOLWWffOLWWffOLWWffOLWWffOLWWf
f=KTO!f=KTO!f=KTO!f=KTO!f=KTO!f=KTO!f=KTO!f=KTO!
M]nNL(M]nNL(M]nNL(M]nNL(M]nNL(M]nNL(M]nNL(M]nNL(
P7LBl1P7LBl1P7LBl1P7LBl1P7LBl1P7LBl1P7LBl1P7LBl1
Z0I;ZKZ0I;ZKZ0I;ZKZ0I;ZKZ0I;ZKZ0I;ZKZ0I;ZKZ0I;ZK

Requirement

There are a few requirements that need to be fulfilled before the program can be run.
  1. Perl 4.X must be installed for kslstereo to run.
  2. All input images must be in ASCII/text format.
  3. Numbers should be used to define objects.
  4. All lines in input image should be equal length.

Source

You can get the source at http://freenshare.granax.com/programs/kslstereo. The program is written in Perl.

More Stereograms

                 *     *                 
;8bUoc;8bUoc;8bUoc;8bUoc;8bUoc;8bUoc;8bU
i4`C;Hi4`C;Hi4`C;Hi4`C;Hi4`C;Hi4`C;Hi4`C
TIS9A_TIS9A_TIS9A_TIS9A_TIS9A_TIS9A_TIS9
dW@Y@ddW@Y@ddW@Y@ddW@Y@ddW@Y@ddW@Y@ddW@Y
X]b`R5X]b`R5X`R5X`R5X`R`R5X`R`R5X`R`R5X`
8/i(@Q8/i(8/i(8/i(8/i(8/i(i(8/i(i(8/i(i(
?[K?lT?[lT?[lT?[lT?[lT?[lT?[?[lT?[?[lT?[
ZZn=-QZ=-QZ=-QZ=-QZ=-QZ=-QZ=-=-QZ=-=-QZ=
A@=a8V=a8V=a8V=a8V=a8V=a8V=a8V8V=a8V8V=a
m6ZGM/ZGM/ZGM/ZGM/ZGM/ZGM/ZGM/M/ZGM/M/ZG
,T-fZ[-fZ[-fZ[-fZ[-fZ[-fZ[-fZ[Z[-fZ[Z[-f
\0K?W'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4:I:II4:I:
Y&B@V5Y&V5Y&V5V5Y5V5Y5V5V5V5V5V5V5V5V5V5V5V5
.OLqJ..qJ..qJ.J...J...J.J.J.J.J.J.J.J.J.J.J.
;SCLj`;Lj`;Lj`;Lj`;Lj`;Lj`;Lj`;LjLj`;LjLj`;L
:9i'=U:'=U:'='='='='='='='='='='='='='='='='
.VSB_V.B_V.B_V_V_V_V_V_V_V_V_V_V_V_V_V_V_V_V
A2Lb&CA2LCA2LCACA2LCACA2LCA2LCACA2LCACA2LCAC
87;0@`87;0@7;0@7;0@7;0@7;0@7;7;0@7;7;0@7;7;0
(J_(RX(J_(RX(JRX(JRX(JRX(J(JRX(J(JRX(J(JRX(J
=)O5iJ=)O5iJ=)O5iJ=)O5iJ=)O5iJ=)O5iJ=)O5iJ=)
$7cUY7$7cUY7$7cUY7$7cUY7$7cUY7$7cUY7$7cUY7$7
`;^$Ud`;^$Ud`;^$Ud`;^$Ud`;^$Ud`;^$Ud`;^$Ud`;





ANSWERS


0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000222222222200000000000000000
0000000000222222222222222200000000000000
0000000022222222222222222222000000000000
0000000222222222222222222222200000000000
0000002222222222222222222222220000000000
0000002222222222222222222222220000000000
0000002222222222222222222222220000000000
0000000222222222222222222222220000000000
0000000022222222222222222222000000000000
0000000000222222222222222200000000000000
0000000000000222222222200000000000000000
0000000000000000000000000000000000000000

111111111111111222222222222222222111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111222222222222222222111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111



00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000
00000000001110000111000001110000000000000000
00000000001110000111000001110000000000000000
00000000001111111111000001110000000000000000
00000000001111111111000001110000000000000000
00000000001110000111000001110000000000000000
00000000001110000111000001110000000000000000
00000000001110000111000001110000000000000000
00000000001110000111000001110000000000000000
00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000
00000000000000222222222222000000000000000000
00000000000222222222222222222000000000000000
00000000022222222222222222222220000000000000
00000000222222000222222000222222000000000000
00000002222222000222222000222222200000000000
00000002222222222222222222222222200000000000
00000002222220022222222222002222200000000000
00000002222222002222222220022222200000000000
00000000022222200000000000222220000000000000
00000000000222222222222222222000000000000000
00000000000000222222222222000000000000000000
00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000