Need Help - It is urgent. Please do comment

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
ZUBAIRAsked:
Who is Participating?
 
limaidealCommented:
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
 
Mig-OCommented:
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
 
limaidealCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ZUBAIRAuthor Commented:
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
 
ZUBAIRAuthor Commented:
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
 
Mig-OCommented:
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
 
ZUBAIRAuthor Commented:
Dear Mig-O
 thanks for your comment.

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

What should i do ?
0
 
Mig-OCommented:
replace return modImg.getSubimage(xmin,ymin,xmax,ymax);    
with return modImg.getSubimage(xmin,ymin,xmax-xmin,ymax-ymin);    
0
 
Mig-OCommented:
and fix the fourth missing pair of parenthesis.
0
 
ZUBAIRAuthor Commented:
I really don't have words to thank you.

Thanks a lot :)

0
 
ZUBAIRAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.