Showing posts from August, 2015

Finding similar images

In this post we're going to implement a simple algorithm which finds images that look similar to each other.
# Overview In order to find images that look similar, we first need to normalize them to a simpler form and compute a fingerprint for each image.

The fingerprint is a binary sequence of ones and zeros and it's created from the average color of the image and the average color of each pixel.

In order to make the process faster and more flexible (and also to have fingerprints of the same length) the image is first resized to a fixed resolution, which defaults to 64x64.

# Algorithm This is the algorithm which creates the fingerprint of an image:

averages=[]foryinrange(height){forxinrange(width){rgb=img.get_pixel(x, y)averages.append(sum(rgb)/len(rgb))}}avg=sum(averages)/len(averages){|v|v<avg?1:0}
It first creates the "averages"array which is populated with the average values of each pixel, from which it takes the average value to repres…

Creating a programming language

In this post we're going to look over the main things required in designing and implementing a programming language.

# Overview Before writing any code and before designing any language construct, we need to think about the core of the language that we want to create. The core of the language is the most important part which defines the language itself.

We also have to choose a programming paradigm for our language from the following list:
A language can have more than one paradigm. For example, it can be imperative and object-oriented at the same time. This are called multi-paradigm languages.

After this two criteria are met, we can start thinking about a syntax for our language and begin carefully to design language constructs and implement them.
In order to implement our programming language, we need to write a parser which creates an abstract syntax tree (AST) from our source code. The abstract syntax tree is…