ASCII image processing

posted by: Ms. Martin 18 January 2011 No Comment

Recall from our second fancy pants project that ASCII art involves making images out of characters. It turns out that this is not very far from how images really are represented — they’re really just two dimensional arrays of colors. This short assignment will get you to explore how image manipulation programs work. Thanks to Baker Franke for inspiration.

For this assignment, images are represented as a single line of integers. The first two integers give the height and width of the image. The rest are ASCII values specifying which characters to display.

Your program will:

  • Read in an image file. Use homer.txt and mystery.txt for your testing.
  • Create a character array that represents the image.
  • Print out the image (display method). With the homer.txt file, your output should be:
                   ,---.
                ,.'-.   \
               ( ( ,'"""""-.
               `,X          `.
               /` `           `._
              (            ,   ,_\
              |          ,---.,'o `.
              |         / o   \     )
               \ ,.    (      .____,
                \| \    \____,'     \
              '`'\  \        _,____,'
              \  ,--      ,-'     \
                ( C     ,'         \
                 `--'  .'           |
                   |   |         .O |
                 __|    \        ,-'_
                / `L     `._  _,'  ' `.
               /    `--.._  `',.   _\  `
               `-.       /\  | `. ( ,\  \
              _/  `-._  /  \ |--'  (     \
             '  `-.   `'    \/\`.   `.    )
                   \  -hrr-    \ `.  |    |
    
  • Print out the image flipped horizontally (displayFlippedHoriz). With the homer.txt file, your output should be:
                        .---,
                       \   .-'.,
                    .-"""""', ( (
                  .`          X,`
               _.`           ` `/
              \_,   ,            (
            .` o',.---,          |
           )     \   o /         |
            ,____.      (    ., \
           \     ',____\    \ |\
           ',____,_        \  \'`'
             \     '-,      --,  \
            \         ',     C (
           |           '.  '--`
           | O.         |   |
           _'-,        \    |__
         .` '  ',_  _.`     L` /
        `  \_   .,'`  _..--`    /
       \  \, ( .` |  \/       .-`
      \     (  '--| \  /  _.-`  /_
     )    .`   .`\/\    '`   .-`  '
     |    |  .` \    -rrh-  \
    

    Note that the characters themselves don’t flip!

  • Print out the image flipped vertically (displayFlippedVert). With the homer.txt file, your output should be:
                   \  -hrr-    \ `.  |    |
             '  `-.   `'    \/\`.   `.    )
              _/  `-._  /  \ |--'  (     \
               `-.       /\  | `. ( ,\  \
               /    `--.._  `',.   _\  `
                / `L     `._  _,'  ' `.
                 __|    \        ,-'_
                   |   |         .O |
                 `--'  .'           |
                ( C     ,'         \
              \  ,--      ,-'     \
              '`'\  \        _,____,'
                \| \    \____,'     \
               \ ,.    (      .____,
              |         / o   \     )
              |          ,---.,'o `.
              (            ,   ,_\
               /` `           `._
               `,X          `.
               ( ( ,'"""""-.
                ,.'-.   \
                   ,---.
    

Extensions: rotate 90, enlarge, shrink, invert…

1 Star2 Stars3 Stars4 Stars5 Stars (20 votes, average: 3.20 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>