MATLAB - Image Processing - Douday's rabbit fractal

  1. 1. The problem statement, all variables and given/known data

    13.2 A quadratic Julia set has the form

    z(n+1)=z(n)^2+c

    The special case where c=-.123+.745i is called Douday's rabbit fractal. Follow example 13.1, and create an image using this value of c. For the Madelbrot image, we started with all z-values equal to 0. You'll need to start with z=x+yi. Let both x and y vary from -1.5 to 1.5.

    2. Relevant equations



    3. The attempt at a solution

    I'm really confused by this question. Here's my attempt at a solution. I really hope someone can point me in the right direction. My book did a very bad explaining the matter.

    Code (Text):
    >> iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y*i;
    map=x+y*i;
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    colormap(jet)
    ??? Error using ==> image
    Error using ==> image
    Image CData can not be complex
     
  2. jcsd
  3. Should I have posted this in the calculus and beyond section?
     
  4. Hi,
    Does anybody has idea about lbp(local binary pattern)?
     
  5. No sorry I don't.
     
  6. I feel less bad for not knowing how to solve this problem lol
     
  7. I'm serious.
     
  8. So am I have no clue.
     
  9. uart

    uart 2,767
    Science Advisor

    Hi Greenprint. Your immediate problem is in this line, "map=x+y*i;".

    You have a secondary problem, that will cause your printout to be monochrome (but otherwise correct) in the code related to "map(a)=k;"

    But work on the immediate problem first. Can you think of a better way to initialize the map?
     
  10. I'm glad I ran into someone who's familiar with this topic, I guess there aren't many. This problem was my first exposure to Mandelbrot sets and of the such and my book didn't do that great of a job explaining this subject matter in the least.

    Simply removing "map=x+y*i;" does seem to produce a result. I don't know why I included that in there. I used the example in my book as a guide as I'm sort of lost on this subject.

    This seems to produce a image like you suggested.
    Code (Text):
    iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y*i;
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    colormap(jet)
    Code (Text):
    %Example 13.1 Mandelbrot Image
    clear, clc
    iterations = 80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.0,gird_size),linspace(-1.5,1.5,grid_size));
    c=x+i*y;
    z=zeros(size(x));           %set the intial matrix to 0
    map=zeros(size(x));         %create a map of all grid points equal to 0
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5)); %Determine which elements have exceeded sqrt(5)
        map(a)=k;
    end
    figure(1)
    image(map)                  %Create an image
    colormap(jet)
    I did some more research on Mandelbrot images and must say that it's a rather fascinating topic. I have a better understanding of what exactly Mandelbrot images are but as far as creating them, not so much. I will see if I can dissect this some, as far as initializing the map, no clue.
     
    Last edited: Jul 19, 2011
  11. Code (Text):
    iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y*i;
    map=zeros(size(x));
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    colormap(jet)
    Don't know if it's right or not.
     

    Attached Files:

  12. http://mathworld.wolfram.com/DouadysRabbitFractal.html
    It would appear as if it's correct. It's just my image is rotated a bit I guess lol. If I wanted to label the axises, whatever the plural form of axis is, what exactly would I put for labels. I can't seem to find a similar plot with labels.
     
  13. uart

    uart 2,767
    Science Advisor

    "Simply removing "map=x+y*i;" does seem to produce a result"

    Yeah you don't really want to just remove it. You want to initialize it with all zeros.
     
  14. uart

    uart 2,767
    Science Advisor

    "Don't know if it's right or not."

    Yes that looks right, but I don't know how you're getting more than two color levels. There is still a mistake near the line "map(a)=k" that will cause it to constantly overwrite parts of the map that have a lower "k" value with whatever the largest value of "k" is. Effectively giving you only a monochrome image.

    Perhaps the map initialization problem (failure to initialize) is masking the other problem.
     
  15. I'm not exactly sure.

    Code (Text):
    z=x+y*i;
    map=zeros(size(x));
    My best bet is that there's something wrong with these lines, the only reason why I did "map=zeros(size(x))" was because it is what the example had in their problem, but that was when z was set equaled to the same exact vector. In the example they are essentially setting the map = z but doing so with my code doesn't produce any results.

    Something tells me that instead of setting the map equal to k in the loop I'm suppose to use k for some other aspect like
    z(k)=z.^2+c;
    z(k)=z(k).^2+c;
    z=z(k).^2+c;
    but an image is not produce with either of these options

    Something seems weird about imputing a into the map function map(a)=k;

    I'm really unsure...
     
  16. Code (Text):
    iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y.*i;
    map=zeros(grid_size,grid_size);
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    title('Douday''s rabbit fractal')
    colormap(jet)
    Is this better?
     
  17. uart

    uart 2,767
    Science Advisor

    Yeah that's good. And are you getting a monochrome (two tone) fractal now?
     
  18. Yes. I'm oddly getting the same image that I did before I made the change.

    Also what exactly would be the proper x and y labels on these types of graphs?
     
    Last edited: Jul 19, 2011
  19. uart

    uart 2,767
    Science Advisor

    Code (Text):

    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
     
    Once abs(z) exceeds sqrt(5) on one iteration, it will exceed sqrt(5) on every subsequent iteration. Do you agree?

    So the set of all points where |z|>sqrt(5) at a given iteration level "k" is a superset of that from all previous iterations. Do you agree?

    So that section of your code keeps overwriting previously written elements of "map" with newer larger values of "k". This means that in the end "map" only has two levels, zero (or whatever map was initialized with) and the final value of "k". That's the reason that I think your map can only be monochrome. Are you sure you haven't changed the code subtly and not told us? Like changing the ">" for "<" for example (hint hint).
     
  20. No I did not accidentally change a thing

    Code (Text):
    iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y*i;
    map=zeros(size(x));
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    colormap(jet)
    both codes produce the same exact image, at least from what I can see
    Code (Text):
    iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y.*i;
    map=zeros(grid_size,grid_size);
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)>sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    title('Douday''s rabbit fractal')
    colormap(jet)
    you can copy and paste and run both codes for yourself

    and yes I agree to both statements

    your suggested code produces the same results except the inside is colored red instead of black
    Code (Text):
    iterations=80;
    grid_size=500;
    [x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
    c=-.123+.745*i;
    z=x+y.*i;
    map=zeros(grid_size,grid_size);
    for k=1:iterations
        z=z.^2+c;
        a=find(abs(z)<sqrt(5));
        map(a)=k;
    end
    figure(1)
    image(map)
    title('Douday''s rabbit fractal')
    colormap(jet)

    Is that what you meant by monochrome?
     
    Last edited: Jul 21, 2011
  21. uart

    uart 2,767
    Science Advisor

    Yes that's monochrome, it basically means there are only two colors (as in a single color foreground and single color background).

    The image you showed in your attachment at reply #10 in this thread was not just black and red though, it had multiple colors and shades. It was from this that I couldn't understand how your code was producing those results. Can you explain where the results in the mentioned attachment can from?
     
Know someone interested in this topic? Share a link to this question via email, Google+, Twitter, or Facebook

Have something to add?
Similar discussions for: MATLAB - Image Processing - Douday's rabbit fractal
Loading...