News

Making Octave for Mac draw images

I have never had a version of Octave on the Mac that lets me handle images. They would all crash with a variety of fun errors. Finally, I now have it working. This is what I did. It may or may not work for you depending on what version of Octave you have, and how far into the future you are.

Last known working version: Octave installed via MacPorts that could draw plots to X11, but crashed on doing anything with images. Last checked working on Snow Leopard.

Start point: OSX Lion 10.7.3 with an outdated MacPorts install.

First update macports. This may take a looooong time if you have fun stuff like, OpenCV, octave, atlas, vxl, etc installed. I had not done this since upgrading to Lion.

sudo port selfupdate
sudo port upgrade outdated

At some point the update will undoubtably fail. Try running again. If you are getting errors like this one, then try:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

Anyway, lets assume you have got macports updated, and have not thrown your Mac out of the window.

Remove octave if you have it installed

sudo port remove octave

If you have dependencies or multiple versions remove those as well. I had to do

sudo port uninstall qtoctave-mac @0.10.1_0+universal octave @3.2.4_6+atlas+gcc44 octave @3.2.4_7+atlas+gcc44 octave-image

Now lets follow this guide at shifteleven.com:

sudo port install octave-devel +gcc45 +x11

Once done, run octave and try load an image.

im = imread('test.png');

This should work. Then try and draw it:

imshow(im)

and it will probably fail. The same will probably happen now for plotting. Great so we cannot display anything. If your errors look like this:

dyld: Library not loaded: /usr/X11/lib/libfreetype.6.dylib
  Referenced from: /usr/X11/lib/libfontconfig.1.dylib
  Reason: Incompatible library version: libfontconfig.1.dylib requires version 14.0.0 or later, but libfreetype.6.dylib provides version 13.0.0
dyld: Library not loaded: /usr/X11/lib/libfreetype.6.dylib
  Referenced from: /usr/X11/lib/libfontconfig.1.dylib
  Reason: Incompatible library version: libfontconfig.1.dylib requires version 14.0.0 or later, but libfreetype.6.dylib provides version 13.0.0
/usr/bin/gnuplot: line 71: 79893 Trace/BPT trap: 5       GNUTERM="${GNUTERM}" GNUPLOT_HOME="${GNUPLOT_HOME}" PATH="${PATH}" DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}" HOME="${HOME}" GNUHELP="${GNUHELP}" DYLD_FRAMEWORK_PATH="${DYLD_FRAMEWORK_PATH}" GNUPLOT_PS_DIR="${GNUPLOT_PS_DIR}" DISPLAY="${DISPLAY}" GNUPLOT_DRIVER_DIR="${GNUPLOT_DRIVER_DIR}" "${ROOT}/bin/gnuplot-4.4.3" "$@"
/usr/bin/gnuplot: line 71: 79899 Trace/BPT trap: 5       GNUTERM="${GNUTERM}" GNUPLOT_HOME="${GNUPLOT_HOME}" PATH="${PATH}" DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}" HOME="${HOME}" GNUHELP="${GNUHELP}" DYLD_FRAMEWORK_PATH="${DYLD_FRAMEWORK_PATH}" GNUPLOT_PS_DIR="${GNUPLOT_PS_DIR}" DISPLAY="${DISPLAY}" GNUPLOT_DRIVER_DIR="${GNUPLOT_DRIVER_DIR}" "${ROOT}/bin/gnuplot-4.4.3" "$@"
warning: broken pipe -- some output may be lost
warning: broken pipe -- some output may be lost
warning: broken pipe -- some output may be lost

Then there is a solution (or two) as noted here on the Octave repository site. Pick one. I went for the replace DYLD_LIBRARY_PATH with DYLD_FALLBACK_LIBRARY_PATH one, as the Gnuplot that my system is using is one installed in the applications folder (from a previously bad octave install I think). So, open /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot in a text editor. Use the editor search-and-replace feature to replace
DYLD_LIBRARY_PATH with DYLD_FALLBACK_LIBRARY_PATH. There are four instances that need to be replaced.

Relaunching Octave now lets me draw plots and images. Yay!

Addendum: To use X11 instead of aqua term I added these to my .bash_profile

export GNUTERM=x11
export OCTAVE_TERMINAL=X11

Tags: , ,

1 comments

Feel free to join the discussion by leaving your own comment
  1. Olli Warelius
    May 26, 2012 at 10:57 #

    Thank you for sharing. Not to many people in your position are so gracious. Your article was very poignant and understandable. It helped me to understand very clearly. Thank you for your help.

This site uses Cookies - By using this site or closing this you agree to our Cookies policy.
Accept
x