Register to reply

MATLAB - Image Processing - Douday's rabbit fractal

by GreenPrint
Tags: douday, fractal, image, matlab, processing, rabbit
Share this thread:
Aug7-11, 07:20 AM
Sci Advisor
P: 2,751
Mystery solved !!!

Ok once I got the python code running it didn't take long to figure out what was happening. In the end it turned out to be fairly simple, the gnu-Octave I'm using thinks infinity > sqrt(5), as do I, but Matlab and Python think otherwise.

Well actually it's the way the respective programs handle numerical overflow. There are regions on the map that begin with |z|>2, so not surprisingly when you keep repetitively squaring this you soon get a numerical overflow, (((2^2)^2)^2)^…, it only takes about 10 iterations to exceed even a double precision floating point capability. When this happens Octave returns "+inf" for the absolute value, while matlab and python return "nan" (not a number).

So that's it. All the lovely shading that Greenprint (and his matlab textbook) have been getting in their images have been purely the result of bad programming and a glitch in the way the matlab handles numerical overflow.
Aug7-11, 06:40 PM
PF Gold
P: 3,103
Ah, thanks.

Numpy has a hack around for the overflow that (efficiently) forces NaN's to zeros:

So that

    z = z**2 + c
    z = np.nan_to_num(z)
    a = np.where(np.abs(z)>sqrt5)
    map[a] = k
produces the attached image as you would expect
Attached Thumbnails
Aug11-11, 03:42 PM
PF Gold
P: 3,103
Python-Numpy comparison with Matlab:

Register to reply

Related Discussions
Image Processing Science & Math Textbooks 2
Image Processing Programming & Computer Science 4
Matlab Image Processing Help (Image Segmentation) Math & Science Software 1
Matlab Image Processing. Math & Science Software 1
Image processing matrix image rotation Engineering, Comp Sci, & Technology Homework 1