Recursive Method for Spliting an Image into 4 quadrants

Posted on 2005-05-03
Last Modified: 2009-07-29
Hi Everybody

I am trying to split an image (64*64 pixels), in to four quadrants. That means now i have four quadrants each of 32*32 pixels. Now i further want to divide one quadrant to 4 until it reaches the single pixel.

Please tell me a recursive code or an Algorithm to implement this.

Question by:ZUBAIR
    LVL 24

    Expert Comment

    This is all about recursion, and has few to do with the splitting:

    void recursiveMethod(argument)   // What ever the argument may be.
        if(argument is big enough to go on)   // Warning this is not JAVA but a META-notation

    // This might look like nonsense, but THIS IS RECURSION.
    You can apply it in several languages in several cases.

    The critirium for you is:  when doesn't it make sense to go on.
    Like: when is the given image too small for a reasonable split.


    Author Comment

    I need some code... that will make it easy for me to understant
    LVL 15

    Expert Comment

    in the inside (recursive) calls gives a 'piece of picture' as argument to the next level of recursion.
    that meand that the method itself must have a 'piece of picture' as parameter. it is that piece of picture that is then split into quarters inside.

    We really cannot help more than that, as this is obviously a homework assignment.

    Anuway look a scuriwaress pseudocode carefully. once you 'get' the idea the coding is pretty easy.

    regards JakobA
    LVL 2

    Accepted Solution

    should be like this:

    Class MyImage
          public MyImage getPart( int x, int y, int width, int height );

    List splitImage( MyImage TheImage, int x, int y, int width, int height )
          if ( width > 1 && height > 1 )
                List ret = new Arraylist();
                ret.addAll( splitImage( TheImage.getPart( x,y,width/2, height/2 )) );
                ret.addAll( splitImage( TheImage.getPart( x + width / 2 ,y,width/2, height/2 )) );
                ret.addAll( splitImage( TheImage.getPart( x ,y+heght/2,width/2, height/2 )) );
                ret.addAll( splitImage( TheImage.getPart( x + width / 2 ,y + height/2,width/2, height/2 )) );
                return ret;
                List ret = new ArrayList();
                ret.add( TheImage.getPart(x,y,width, height));

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    triangle challenge 4 34
    Updating Java 9 62
    strDist challenge 35 69
    firstChar challenge 13 53
    1. Package the applet into a JAR file. The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in  tag, replace the codebase …
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now