Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to understand Quadtree concept and apply it to storing coloring info of an image

I've read so many articles, but none seem to answer this question. Or maybe I'm just not understanding. I'm attempting to build a quadtree so that it can represent an image. The leaf nodes are to hold pixels, and non-leaf nodes will hold the average value pixel of its children.

My question is:

How does it work that the leaf nodes only hold pixels? Why don't the other nodes hold pixels? And how do we know how many times to subdivide our original root node to represent that given image? Do we just subdivide it n times, where n is the height and width (for a square)?

Edit: So how do I keep track of leaf nodes, so I know when to add pixels at that location? Right now I have a helper function that divides the regions for me, keeping track of width and height.

like image 788
Snowman Avatar asked Mar 16 '11 01:03

Snowman


People also ask

What is quadtree images?

Quadtrees are the two-dimensional analog of octrees and are most often used to partition a two-dimensional space by recursively subdividing it into four quadrants or regions. The data associated with a leaf cell varies by application, but the leaf cell represents a "unit of interesting spatial information".

What is a quadtree used for?

Quadtrees are used in image compression, where each node contains the average colour of each of its children. The deeper you traverse in the tree, the more the detail of the image. Quadtrees are also used in searching for nodes in a two-dimensional area.

What is quadtree and octree?

Definition. A quadtree is a spatial data structure which has four branches attached to the branch point or node. The records exist in the leaf nodes of the tree. An octree is the same concept except the branches are in groups of eight. An octree can represent and image by subdividing the cubical volume.

Is a quadtree a KD tree?

The k-d tree stores records at all nodes, while the PR quadtree stores records only at the leaf nodes. Finally, the two trees have different structures. The k-d tree is a binary tree, while the PR quadtree is a full tree with 2d branches (in the two-dimensional case, 22 = 4).


1 Answers

Quadtrees work best for square images whose size is a power of 2 (for example, most textures). You shouldn't think of each node as representing a "pixel". Instead, think of it as representing a "square block of pixels of size 2^k". In the case of final leaves, k is 0, so each leaf node represents a square block of pixels of size 1, that is, a single pixel. Internal nodes in the tree represent increasingly large sections of image.

like image 150
Paul Z Avatar answered Oct 05 '22 23:10

Paul Z