PixelArt fun

Written by sergio on July 12, 2011 Categories: programación

I recently stumbled upon this neat algorithm by Johannes Kopf and Dani Lischinski. In short, their algorithm takes a pixelart image, such as  those found in 8-bit video games, and produces a new image that somehow makes you think “hey, that looks like what the artist actually had in mind”. In other words, it tries to generate the ideal image for which the pixel art is only an imperfect representation. The results explain it better:

Mario - before, after

Mario from Super Mario Bros 3, using my own implementation. Click to zoom.

If you are interested in this kind of stuff, I really recommend you read their paper, it is well written, easy to understand even for people with no deep knowledge of computer graphics (like myself) or for people with no programming training. I partially implemented their algorithm using Common Lisp and Zach Beane’s Vecto library, here’s a very very short description, just to illustrate the different steps. Some eye-candy at the end!

Finding Vicinities

First, we find which regions of the original image are part of a single feature.

Different regions are found. Notice the blue cross near the center of the image, where we need to decide which diagonal should be kept as part of a single feature

Re-shaping Pixels

Once different regions have been found, pixels are re-shaped so that each region has a well defined contour.

Each pixel is re-shaped to a voronoi cell calculated using the center point of each cell and points defined by its vicinities

Smoothing Edges

Finally, edges are identified …

Edges are identified

Edges are identified

… and smoothed

Smoothing

Smooth edges. Have a look at Mario’s eyes.

Keep in mind that this is only a partial implementation, the original algorithm also re-shapes edges to make them look more natural, reducing zig-zag curves for example. (they also use a different type of curve, b-splines, which works better than what I’m using, catmull rom) and therefore produces much better results. Have a look at their examples in the linked article.

Some Examples!

Click on the images to enlarge

Spartan

Donkey Kong

zelda

karate champ

Captain America and the Avengers

mario kart

mario kart

sagat ftw

 Thanks to Javier Moreno, Norman Garcia and Angie Bloor for their comments.

14 Comments

How to extend Oasis Montaj using C#

Written by sergio on May 10, 2011 Categories: programación

Oasis Montaj allows its users to program their own extensions. The “standard” way of creating an Oasis Montaj extension is by using the GX language, a C-like language, and its companion user interface definition language. I find this good enough for most cases. Actually, the standard actions in Oasis Montaj seem to be implemented as GX scripts that validate user input and then calls some inner functionality.

However, for more complex programs, I like to have all the bells and whistles of a main stream high level language, such as C#. In this post I will explain step by step how to create a “Hello World” C# Oasis Montaj extension.

I will be using Microsoft Visual C# 2010 express, you can download for free here. You will also need to have a licensed copy of Oasis Montaj installed (I’m using version 7.2.1). Finally, you’ll need the corresponding GX developer toolkit that you can download for free here.

1. Create a new project in Visual C# 2010 express.  Choose class library as the type of project and name it HelloWorld, for example.

2. Save the project.

3. Go to the project properties (Project -> HellowWorld Properties) and change the Target framework to .NET framework 3.5. This is the version that seem to work well for Oasis Montaj 7.2.1, but I guess it might change in the future. Anyway, version 4.0 does not seem to work. UPDATE: starting from Oasis Montaj 7.3, the target platform should be set to .NET framework 4.0. Yay!

4. In the Solution Explorer tab, right-click the HelloWorld project and then choose Add Reference. Select Browse in the dialog window and then navigate to the folder where you installed GX Developer (usually C:Program FilesGeosoftGX Developer). Then navigate through the folders apps -> redist -> bin. Select geonet.dll and Geosoft.GX.Controls.dll

5. Repeat the previous step to add a new reference, but instead of selecting the Browse tab, select .NET, then add System.Windows.Forms

6. Create a new class named  HelloWorld:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Geosoft.GX.Controls;
using Geosoft.GXNet;
using System.Windows.Forms;

namespace HelloWorldGX
{
class HelloWorldGX : BaseForm
{
public HelloWorldGX(int i) : base(i) { InitializeForm(); }
public int Run() {
MessageBox.Show("Hello World");
return 0;
}
}
}

7. In Visual C#, click on Build -> Build Solution. Then go to your project folder -> bin -> Release, and copy the HelloWorld.dll to the bin folder of your Oasis Montaj install

8. Create a new menu file named HelloWorld.omn in the omn folder of your Oasis Montaj install folder (C:Program GilesGeosoftOasis Montaj, usually) with the following content:

 MENU "&HelloWorld" ITEM "&HelloWorld" ,HelloWorld.dll(HelloWorldGX.HelloWorldGX;Run) <standard.bmp[1]> 

9. Copy the geonet.dll, Geosoft.GX.Controls.dll and geoexceptions.dll from the GX Developer -> apps -> redist -> bin to the bin folder of your Oasis Montaj install. Important note: you might need to copy other dll’s when you start using some real functions from the oasis montaj API.

10. From Oasis Montaj, load the HelloWorld Menu (GX -> Load Menu), and then run the Hello World item.

At Abitibi Geophysics we have been writing Oasis Montaj’s extensions using C# with very good results.

6 Comments