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

x
?
Solved

Need Help - It is urgent. Please do comment

Posted on 2005-05-10
11
Medium Priority
?
360 Views
Last Modified: 2012-06-27
Hi everybody,

An overview of this method is that i want to implement a quad tree structure on an image. Lets suppose if we have an image of 8x8 pixels, the image will be split into four quadrants each of 4x4 and so on until it reach single pixel value.
In the below code, i have tried to implement some thing similar but I am having problem in the recursion method, when i am dividing the image into its quadrant the following error occur: "Raster Format Exception (y+height) is outside of raster".

I have attached the code for your kind persual, please comment.


public class QuadTreeNode{
 
    static final byte  NW = 0, SW = 1, NE = 2, SE = 3;
    int xSize, ySize;
   
    QuadTreeNode(int xMin, int yMin, int xMax, int yMax, BufferedImage image){
       
   this.xSize = xMax - xMin;
   this.ySize = yMax - yMin;

   if ( xSize > 1 || ySize > 1 )
    {
         if( xSize < 4 || ySize <4)
         {
            for(int i = 0; i <4; i++)
             {
               parent.addSubTree(new TreeFunctions("NWleafs"),parent,NW);
               
                parent.addSubTree(new TreeFunctions("SWleafs"),parent,SW);
               
               parent.addSubTree(new TreeFunctions("NEleafs"),parent,NE);
             
              parent.addSubTree(new TreeFunctions("SEleafs"),parent,SE);
                    }//end for loop
                }//end nested if
                         
  else
  {
 new QuadTreeNode( xMin, yMin, (xMin+xMax)/2, (yMin+yMax)/2,    
segmentImage(image,xMin,yMin,xMax/2,yMax/2));

new QuadTreeNode( xMin, (yMin+yMax)/2, (xMin+xMax)/2, yMax,           segmentImage(image,xMin+xMax/2,yMin,xMax/2,yMax/2));

new QuadTreeNode( (xMin+xMax)/2, (yMin+yMax)/2, xMax, yMax,            segmentImage(image,xMin,yMin+yMax/2,xMax/2,yMax/2));

new QuadTreeNode( (xMin+xMax)/2, yMin, xMax, (yMin+yMax)/2,            segmentImage(image,xMin+xMax/2,yMin+yMax/2,xMax/2,yMax/2));

     }//end else
   }//end if
}//end QuadTreeNode

//Method for spliting the image into quadrants
BufferedImage segmentImage(BufferedImage modImg,int xmin, int ymin, int xmax, int ymax)

{
return modImg.getSubimage(xmin,ymin,xmax,ymax);      
} //end segmentImage
}//end of class
0
Comment
Question by:ZUBAIR
  • 5
  • 4
  • 2
11 Comments
 
LVL 3

Expert Comment

by:Mig-O
ID: 13973394
this is by far the worst code i've seen ever...

Btw... where is parent defined. And what is TreeFunctions?

Debugging this is really worth more points than 128 ;)

0
 
LVL 2

Expert Comment

by:limaideal
ID: 13973428
what does modImg.getSubimage(xmin,ymin,xmax,ymax);     do?
return reference to modImg or return a new object of farction of modImg?

If return a new instance of fraction of original image, you cannot use xmin, ymin, xmax, ymax. Need to use x, y, width, height instead.

0
 

Author Comment

by:ZUBAIR
ID: 13975769
Thanks for the reply,

As far the points are concern i am increasing them but please help me out.

Secondly i have already mention that i am implementing the quad tree data structure. So the TreeFunction is a class and parent is the top node of the tree.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ZUBAIR
ID: 13975785
thanks limaideal

modImg.getSubimage(xmin,ymin,xmax,ymax);    

It returns reference to a new object of fraction of modImg.

Please could you tell me how to implement your above idea in the code.

0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13976439
yor forgot the parenteses in you code (at the xMin+xMax/2 stuff):
Try:

 new QuadTreeNode( xMin, yMin, (xMin+xMax)/2, (yMin+yMax)/2,           segmentImage(image,xMin,yMin,xMax/2,yMax/2));

new QuadTreeNode( xMin, (yMin+yMax)/2, (xMin+xMax)/2, yMax,           segmentImage(image,xMin+xMax/2,yMin,xMax/2,yMax/2));

new QuadTreeNode( (xMin+xMax)/2, (yMin+yMax)/2, xMax, yMax,            segmentImage(image,xMin,(yMin+yMax)/2,(xMax/2,yMax/2));  <- This is where your code breaks.

new QuadTreeNode( (xMin+xMax)/2, yMin, xMax, (yMin+yMax)/2,            segmentImage(image,(xMin+xMax)/2,(yMin+yMax)/2,xMax/2,yMax/2));  <- change this, or your code breaks here, too.
0
 

Author Comment

by:ZUBAIR
ID: 13976990
Dear Mig-O
 thanks for your comment.

I have add the parenthesis but the same error is occuring.

What should i do ?
0
 
LVL 2

Accepted Solution

by:
limaideal earned 1000 total points
ID: 13979450
Try something as below:

public class QuadTreeNode{
 
    static final byte  NW = 0, SW = 1, NE = 2, SE = 3;
   
    QuadTreeNode(int width, int height, BufferedImage image){
       
   if ( width > 1 || height > 1 )
    {
         if( width < 4 || height <4)
         {
            for(int i = 0; i <4; i++)
             {
               parent.addSubTree(new TreeFunctions("NWleafs"),parent,NW);
               
                parent.addSubTree(new TreeFunctions("SWleafs"),parent,SW);
               
               parent.addSubTree(new TreeFunctions("NEleafs"),parent,NE);
             
              parent.addSubTree(new TreeFunctions("SEleafs"),parent,SE);
             }//end for loop
          }//end nested if
                         
            else
            {
                  new QuadTreeNode( width/2, height/2,    
                        segmentImage(image,0, 0,width/2,height/2));

                  new QuadTreeNode( width/2, height/2,          
                        segmentImage(image,0, height/2,width/2,height/2));
                  
                  new QuadTreeNode( width/2, height/2,          
                        segmentImage(image,width/2, height/2, width/2, height/2));
                  
                  new QuadTreeNode( width/2, height/2,            
                        segmentImage(image,width/2, 0, width/2, height/2));

     }//end else
   }//end if
}//end QuadTreeNode

BufferedImage segmentImage(BufferedImage modImg,int x, int y, int width, int height)

{
return modImg.getSubimage(x, y, width, height);    
} //end segmentImage


I didnt compile it, so you might need to fix minor syntax issues. But it should illustrate the idea.
Assuming you want to split the whole original image.
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13980282
replace return modImg.getSubimage(xmin,ymin,xmax,ymax);    
with return modImg.getSubimage(xmin,ymin,xmax-xmin,ymax-ymin);    
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13980289
and fix the fourth missing pair of parenthesis.
0
 

Author Comment

by:ZUBAIR
ID: 13981111
I really don't have words to thank you.

Thanks a lot :)

0
 

Author Comment

by:ZUBAIR
ID: 14148332
HI guyz

Please have a look on the question below, i think you can answer it.

Thanks

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21444805.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 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