[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Recursive Method for Spliting an Image into 4 quadrants

Posted on 2005-05-03
4
Medium Priority
?
492 Views
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.

THanks
0
Comment
Question by:ZUBAIR
4 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 13920217
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
    {
        recursiveMethod(leftUpperQuadrant);
        recursiveMethod(leftLowerQuadrant);
        recursiveMethod(rightUpperQuadrant);
        recursiveMethod(rightLowerQuadrant);
    }
}

// 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.

;JOOP!
0
 

Author Comment

by:ZUBAIR
ID: 13920327
I need some code... that will make it easy for me to understant
0
 
LVL 15

Expert Comment

by:JakobA
ID: 13920643
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
0
 
LVL 2

Accepted Solution

by:
limaideal earned 1000 total points
ID: 13922266
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;
      }
      else
      {
            List ret = new ArrayList();
            ret.add( TheImage.getPart(x,y,width, height));
      }
}
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 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