Twitter Image

June 18th, 2009 rjzii No comments

Background

This project arose out of a contest that was held on StackOverflow that grew out someone else’s project involving image compression. The overall objective of the project is to be able to encode an image in such a way that you can send it via a 140 character tweet on Twitter.

Algorithm

The basic idea behind the algorithm is as follows:

  1. Down sample the image to gray-scale such that there are about 16 shades of gray.
  2. Set a sampling block size for the image.
  3. Encode the image using RLE.
  4. Pack the results into the UTF-16 characters such that there are two run lengths to a character and four color shades to a character.
  5. Preform additional RLE on the packed data such that duplicated run-leghts are replaced by a number followed by a value.
  6. Check to see if the resulting string is less than or equal to 140 characters, if so return it, otherwise, return to step two.

Results

Reference Image Tweet Output Image Output Run Time Tweet Size
cornell-box.png cornell-box.txt cornell-box.bmp 61ms 135 characters
cornell-box-large.png cornell-box-large.txt cornell-box-large.bmp 365ms 124 characters
lena.png lena.txt lena.bmp 39ms 103 characters
lena-large.png lena-large.txt lena-large.bmp 1159ms 137 characters
mona-lisa.png mona-lisa.txt mona-lisa.bmp 26ms 97 characters
mona-lisa-large.png mona-lisa-large.txt mona-lisa-large.bmp 2187ms 131 characters
stackoverflow-logo.png stackoverflow-logo.txt stackoverflow-logo.bmp 37ms 111 characters

Discussion

Twitter makes use of Unicode characters; however, based upon discussion on the contest page it seems that web submission only recognizes UTF-16 where as the API can use the full UTF-32 space. For the purposes of this implementation the code is limited to making use of the UTF-16 space which is also conveniently the char data type in C#.

Give the simple nature of the algorithm it is unlikely that this project broke any new ground; however, it did server as an excellent exercise for my own skills in that it exposed me to image manipulation which is not something I do in the course of my job and likewise, it had been a long time since I had to do any bitwise manipulations to data.

Source Code

There are two main files for this project: program.cs and twitterimage.cs. The following is the cloc output for the files:

http://cloc.sourceforge.net v 1.07  T=0.5 s (4.0 files/s, 832.0 lines/s)
-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
C#                    2        23       106       303 x   1.36 =         412.08
-------------------------------------------------------------------------------
	
Categories: Experiments Tags: , ,

Kiva World

June 4th, 2009 rjzii No comments

Kiva World is a project that arose out of a recent graduate course I took in dynamic web development and while it is it is not the first one of its type it is the version that I wrote and as such I do have a bit of an attachment to it. This particular application was written using a combination of PHP and JavaScript to provide the dynamic interaction in the user’s browser and leans heavily upon the Google Maps API along with the API exposed by Kiva.

One of the interesting things about the version that I wrote, that does not appear to have been implemented by the other version as of the time of this writing, is the ability to see lender data as well as lendee data. This actually presented an interesting challenge due to the fact that Kiva exposes their data with extremly accurate geocoding for the lendees, but lenders are able to free text their location. As such aggreigating the lenders is exteremly hard and coupled with anonomyous lenders, I actually filter out a lot of them from the displayed results.

For those of you that are not familar with Kiva they are a charitable service that provides microloans to those living in poverty with the purpose of helping them develop their own business.  Since it is a charitable service, lenders do not get any interest, but if the loan is successfully repaid, they can get their money back.

Greetings

June 4th, 2009 rjzii No comments

Greetings! Welcome to my small, little coner of the internet. The purpose of this “blog” is provide a small area where I can discuss various technological issues that I have encountered and hopefully help others to avoid some of the many pitfalls that are part of Information Technology and software development.

Categories: Uncategorized Tags: