2D and 3D Perlin Noise in MATLAB

As an Amazon Associate I earn from qualifying purchases.

I am creating random 3D shapes for my post-doctoral research and need to generate 2D and 3D Perlin noise textures in MATLAB (for later use in OpenGL). If you’re not familiar with Perlin noise, it is procedurally generated random noise that appears organic due to it high and low-frequency noise content.

In my search for some MATLAB code, I found a page that had the following GNU Octave 2D Perlin noise generation code:

Since GNU Octave is so similar to MATLAB, it was very simple to translate:

I added the following code to normalize the output (making all values range from 0 to 1):

This code can create some nice 2D Perlin noise images, such as:

32 x 32
64 x 64
128 x 128
256 x 256

And since interp3 (and interpn) are higher-dimensional interpolation functions available in MATLAB, it was simple to create a 3D perlin noise function:

The earlier code creates 3D Perlin textures, such as: (please note that these are animated by slicing the texture in depth)

32 x 32
64 x 64

However interp3 is VERY memory intensive. Here are example MATLAB profiler outputs illustrating the peak memory used by MATLAB (note that I used the undocumented MATLAB profiler memory option “profile -memory on;”, described here):

32 x 32
64 x 64

Replacing interp3 with smooth3, I was able to reduce the memory requirements a bit:

As I mentioned, smooth3 then reduces the memory requirements:

32 x 32
64 x 64
128 x 128
256 x 256

And produces (subjectively) similar Perlin-style noise, but with lower contrast. We can increase the contrast by simply scaling the values using a simple cosine transform:


32 x 32
64 x 64

The contrast still isn’t as good as the “true” Perlin noise, so I’ll try to see how simplex noise is implemented..

Amazon and the Amazon logo are trademarks of Amazon.com, Inc, or its affiliates.

4 thoughts to “2D and 3D Perlin Noise in MATLAB”

  1. Dear mr. Steave,

    My name is Antonio,
    I’m from Genoa North Italy,
    Congratulations I follow many of his works.

    Escuse me but I’m trying this place because the other (contact me) does not accept my email.

    Your project of glcd scope is very nice.
    I made the oscilloscope and
    I used a PIC18f4550 instead of a PI18F2550
    I try to load this file .hex
    generated by this CCS code
    http://semifluid.com/wp-content/uplo…o-bootloader.c of your web site.

    I don’t understand……
    Show only the positive part of a sine wave and it is positioned at the bottom.
    The frequency and the line of zero-crossing dont’works.

    Can you send me a other .hex



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.