Octave : [ VRML output and visualization | Gnuplot Interface | SIFT Image Features | Sudoku Solver ]

Perl : [ Misc | Portuguese Verbs Demo ]

[ Home ]

Programming in Octave

Octave is a free software clone of Matlab with a lively community of users and developers.

Octave-forge is a repository of extensions that haven't made their way to Octave yet or are too specialized to do so, including free substitutes of Matlab toolboxes.

The Octave Wiki is just that, a wiki to which Octave users are invited to contribute.

I work a lot with Octave and, in return, contribute to its development. Code that is clean enough and is of general utility I add to Octave-forge. I've put below code that is too specialized to fit in Octave-forge.

Octave VRML update

During my studies, I wrote some Octave functions to visualize 3D data using VRML. These functions went to the Octave-forge VRML package. I've used them again at my latest job, and my manager at Magic Leap is glad to let me open-source the fixes and improvements I bring.

I don't have the time or will to do a full maintenance job on Octave-Forge, so I just leave the latest files here:


Raw Octave-to-Gnuplot interface (2007-)

The g_xyz functions are available in the gnuplot package of Octave-forge

This collection of m-files, developed for my work at Tyzx, implements a raw octave-gnuplot interface: allows to create temp dirs, save data, and run arbitrary gnuplot commands. This interfaces is mostly for people who know how to use both gnuplot and octave but also has a shortcut function g_ez(...) that allows to do plots with a single command.

For installation, just run from the octave prompt "pkg install gnuplot-1.0.0.tar.gz", then "pkg load gnuplot", as indicated in this page.

For a fast start, type "demo g_ez" in the octave prompt, or try the g_demo() function, as it shows how to use the pm3d (and image) feature. You may also be interested by the 'myimage' function (uses the image viewer display, some functionality requires imagemagick) to manipulate/display images.

octave> help g_new
g = g_new ( ...)            - Create a new gnuplot_object and its directory

The g_XYZ() functions allow Octave to create plots with Gnuplot. They
are little more than an Octave front-end to Gnuplot, but allow to do
anything Gnuplot can do directly from Octave. In addition, there are some
commodity functions (g_cmd() with struct arg, g_locate()) that allow to nest
one figure in another.

g_new() creates a temporary directory in which data and commands will be
stored in a gnuplot-readable format.

g_new accepts key, value pairs of arguments, which will be passed to g_set.

Typical usage:

g = g_new  ()
g = g_data (g, "myChosenDataFileName", data, ...)
g = g_cmd  (g, ,\
               "plot 'myChosenDataFileName' with lines",...);
g_plot     (g,);

DEMO: Run g_demo(), or see http://gnuplot.sourceforge.net/demo_4.1 on how to
      do nice plots.

SEE ALSO: g_ez, g_delete, g_data, g_cmd, g_plot, g_set, g_locate.

TODO: an OO style of function call (see failed attempt at end of g_new code)
Snapshots from the output of g_demo():
A simple plot Four of the same, w/ different colors
1st demo plot 3rd demo plot
Octave's sombrero mascot The same, in color
1st demo plot 3rd demo plot
A graded checkerboard image The same, seen in 3D
1st demo plot 3rd demo plot

octave> help myimage
im2 = myimage (im,...) - Make im viewable by normalizing greylevels and more

Scales the values of im so that they range in [0,255]. The smallest element
of im (or range(1), if the "range" option is used) is mapped to zero, and the
largest (or range(2)) is mapped to 255.

If both dimensions are less than 180,

If the save option is not used, and nargout is 0, then im2 will be displayed,
rather than returned. NaN and Inf pixels become black or, if the image is
saved as a .png or .gif, transparent.

"range", [min,max]   : Graylevel range to be mapped to 0:255.
"qrange", [minq,maxq]: Map quantiles between minq and maxq to 0 and 255.
"minsz", [Rows,Cols] : Minimum dims of im2. im will be scale by an integral
                       factor so that at least one of its dimensions matches
                       minsz.                Default: [180 180]
"scl",   scl         : Scale image size up (scl>1) or down (scl<1)
"invert"             : Invert image (black becomes white and vice versa).

"is_col"             : Color image, consecutive rows being R, G and B.
"colormap",          : Convert greylevel image to a 'rainbow' colormap

"show_range"         : Place a graylevel scale below image.
"scale_sz",sz        : Width of graylevel scale. Implies show_range.

"text", [x,y], str   : Annotate image with str, at position x,y, with size sz
"text", [x,y,sz],str
"line", [x,y,x,y,R,G,B,W] or
"line", [x,y,x,y,R,G,B]   or
"line", [x,y,x,y,C,W]     or
"line", [x,y,x,y,C]       or
"line", [x,y,x,y]

"save",    filename  : Save im2 in filename.
"display", yesno     : Display im2 or not. Default: False iff save requested
                       or nargout!=0.

EXAMPLES: type "demo myimage" to run the examples below
myimage (randn(3,3),                    "show_range")
myimage (rand(9,3),                     "is_col")
myimage (randn(32,32),                  "minsz",[32,50])
myimage (ones(64,1)*linspace(0,1,256),  "colormap")
myimage (linspace(0,3,256)'*ones(1,64), "range",[3 1])
myimage (zeros(200,200), "text",[10,20],">> 1 + pi\nans = 4.1416\n>>")

im = kron (ones(4), kron (eye(2),ones(10)));
im += ones (80,1)*linspace(0,1/2,80);
myimage (im,"text",[11,5],"Hello","text", [10,30,30],"world")

FIXME: scl < 1 seems to be buggy
Snapshots from the output of myimage():
myimage (randn(3,3), "show_range"); myimage (rand(4,5,3));
1st demo plot 3rd demo plot
myimage (zeros(200,200), "text",[10,20],">> 1 + pi\nans = 4.1416\n>>") im = kron (ones(4), kron (eye(2),ones(10)));
im += ones (80,1)*linspace(0,1/2,80);
myimage (im, "text",[100,200,200],"Hello","text", [20,400,200],"world")
1st demo plot 3rd demo plot

SIFT for Octave (2005/12)

This patch for Version 4 of David Lowe's SIFT software could be of interest to Octave users who do image processing. It allows Version 4 of David Lowe's SIFT software to work under both Matlab and Octave. This patch is temporary: it should make it into the next release of the SIFT software.

The SIFT image detector identifies interest points, somewhat like a corner detector does, and gives them a local descriptor. The descriptor can then be used for matching purposes (another way to perform matching could be correlation of a small window around the feature). Wrt to corners + local window correlation, SIFT features are more robust to changes in illumination and viewpoint and they are increasingly used in computer vision. The siftDemo has functions to find sift features and to perform matching. I've tested the patch under octave+linux, matlab+linux (it works) and octave+win (it fails, probs w/ imagemagick + double). You can apply it to the matlab code in siftDemoV4 to allow Octave to extract SIFT image features with David Lowe's package.

Output of showkeys() Output of match()
photo of me photo of me

For more information on SIFT, see

Sudoku solver (2005/12)

here is a sudoku solver which I tried on 3 problems from The Providence Journal. It worked.

Programming in Perl

I enjoy programming in Perl although I haven't done much beyond one-liners recently. Guess what this does (when you feed it to the shell) :

            perl -e 'print map{("J CANT SPEL HUORK\n\t"=~/./sg)[-70+ord]}

Of the programming languages I know, Perl is the most useful and the most fun. This is just an opinion since I don't know all the programming languages around. More on that on the "Fun with Perl" mailing list.
Here are some programs I wrote and made presentable :

[ Octave | Perl | Home ]

Want to do something against software patents? patent_button