[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
Medium Priority
360 Views
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".

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++)
{

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

//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
Question by:ZUBAIR
• 5
• 4
• 2

LVL 3

Expert Comment

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

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

ID: 13975769

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

Author Comment

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

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

ID: 13976990
Dear Mig-O

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

What should i do ?
0

LVL 2

Accepted Solution

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

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++)
{

}//end for loop
}//end nested if

else
{
segmentImage(image,0, 0,width/2,height/2));

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

segmentImage(image,width/2, height/2, width/2, height/2));

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

}//end else
}//end if

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

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

ID: 13980289
and fix the fourth missing pair of parenthesis.
0

Author Comment

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

Thanks a lot :)

0

Author Comment

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

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ā¦