GNU Octave OS X

Why GNU Octave

Learning image processing using C++ is not practical for a newbie like myself as it is not conducive to trial and error. Besides, I would like create a model and explore it in an iterative fashion before I code it in C/C++/ObjectiveC.

I opted to install GNU Octave on the Mac Mini since all my dev is on that platform.  I did install it on Windows 7 a while back for an earlier project so I know what it can do. I also wanted a tool that was almost 100% compatible with MatLab code.

Installing GNU Octave

My dev box consists of a Mac Mini with 2.3 GHz Intel Core i7, 16GB RAM running OS X version 10.8.3 (Mountain Lion). There seems to be a lot of issues with installing Octave in OS X based on what I see on the web. I went down the MacPorts path since I used it for some other installation.

The Steps

  • Download and install Xcode from the Apple App Store
  • Command Line Tools need to be installed manually. Apparently, one can download them without Xcode (web rumour). I did not go down that path as I needed xCode for iOS development. To install the Command Line Tools, select Preferences from the Xcode menu as shown below. Then proceed to the download tab where you will find the Command Line Tool with the install button. Mine is already installed.

cmdline tools

  •  Install MacPorts as per instructions
  • Since I already had MacPorts installed, I ran sudo port selfupdate followed by sudo port upgrade outdated to bring everything up to the latest versions. Note,I use sudo to elevate the privilege required to run port.
  • The documented way to install e.g. sudo port install octave-devel +atlas+docs did not work for me. I kept getting errors and had to perform the installation with sudo port install octave-devel gcc47 I think it has to with atlas which forces everything to recompile.  I suppose one could run it with gcc48 as well.
  • When I reran sudo port install octave-devel +atlas+docs things worked ok.

Note atlas takes a long time to build. I thought the process was frozen but the activity monitor stated that it was busy. Eventually it completed.

Optional Packages

Octave comes with several optional packages depending on what you want to do.  I wanted the image and signal packages.  To install a package, run octave, (type octave in the terminal prompt) and  execute the command pkg install -force <package name> for images pkg install -force image.  The package is not automatically loaded. To load it, type pkg load <package name>. For the image package, pkg load image.

 Testing It Out

I tested my installation with the image package by taking a white square on black background, performed a 2D FFT, displayed the magnitude and phase of the signal, and recreated the original image by performing an inverse 2D FFT. For the curious, the FFT of the image results in a cross in the frequency domain which is in reality a 2D Sync function. In the 1D world, the FFT of a square wave is a sync function. In the 2D world, a square is the equivalent of a pulse. My phases looks wonky and at this point the goal was just to test the installation on OS X. Passed.

 Output

octave 2dFFT