home


Useful code snippets

I have released the following code into the public domain (except fitellipse and meanshift, which I can't). Feedback is welcome. Email <yotam (strudel) yotamgingold.com>.

NOTE: Most new code snippets are going up on GitHub or as Gists. I also release code with my academic publications.


YImage (updated 2012-01-09): GitHub | yimg.tgz | README | YImage.hpp | YImage.cpp | showpng.cpp

YImage:
	A simple pixel buffer class that can
		- save and load itself as a PNG (preserving alpha channel)
		- set color-plane layout (compile-time)
		- resize/flip/mirror/greyscale

showpng:
	An example GLUT application using YImage that takes a PNG file as
	argument and displays it over a horrible green background.

(Example GLUT image viewer needs GL.framework, also from this page!)


MiniParser (updated 2007-09-20): GitHub | miniparser.tgz | README | MiniParser.hpp | MiniParser.cpp | example.cpp

MiniParser:
	A simple C++ expression parser with no external dependencies whatsoever
	that can
		- generate a parse tree from an expression
			- parentheses
			- constants
			- symbolic variables
			- binary operators:
				- add: +
				- subtract: -
				- multiply: *
				- divide: /
				- modulus: %
				- exponent: ^, **
			- unary operators:
				- negate: -
			- functions:
				- sin()
				- cos()
				- log() (base 10)
				- ln() (base e)
				- exp()
				- sqrt()
			- constants (override any variable with the same name):
				- PI = 3.14...
	NOTE: Order-of-operations is entirely left-associative.  There is no
	      operator precedence.  Use parentheses everywhere!

example:
	An example command line application that demonstrates a class
	with a predefined expression evaluated via operator()
	as well as an expression with an arbitrary number of variables.
	Can be called with two values (x,y) or with an expression followed
	by an arbitrary number of values assigned to the letters of the
	alphabet (a, b, c, ...).


GL.framework: GL.framework.tgz A framework of symlinks for Mac OS X to allow OpenGL #include's the same way as every other platform: <GL/gl.h>, <GL/glu.h>, <GL/glut.h>. Put it in /Library/Frameworks/.


Half-edge data structures in python [GitHub] and C++ [GitHub] with no external dependencies (well, the python one makes basic use of NumPy).


fitellipse.py: fitellipse.py

Ellipse fitting ported from the matlab file fitellipse.m by Richard Brown. This code is verified: After I ported the matlab code to python, I verified that both versions compute the same things internally and return the same results in all branches (two kinds of linear and nonlinear).

A proper readme (but using MATLAB) can be found here.

The original code can be found here. Note that the test code is embedded as a function in fitellipse.py.


MeanShiftCluster.py: MeanShiftCluster.py

Mean Shift clustering ported from the matlab file MeanShiftCluster.m by Bart Finkston.

The original code can be found here. Note that there is a small test function embedded inside which is performed if the script is run as main.


home