C implementation of a QuadTree-like BST for image segmentation and compression.
A C implementation of a Binary Search Tree (BST) data structure used to manage rectangular regions (quads) of an image.
This project demonstrates how image segmentation can be performed using recursive quadtree-like splitting, based on pixel similarity thresholds.
- Quad Structure: Represents rectangular image regions with metadata
(tx, ty, w, h, sx, wsplit, key). - BST Operations:
- Insert, Search, Delete nodes
- Inorder, Preorder, Postorder traversals
- Recursive memory cleanup
- Image Processing Functions:
get_colour: Compute average pixel colour of a quadsimilar: Determine if a quad’s pixels are within a similarity thresholdsplit_tree: Recursively split quads into smaller regionsdrawOutline: Draw outlines of quads on the imagesave_Quad: Replace quad pixels with averaged colour for compression
- Load a grayscale image into memory
- Initialize the root Quad (whole image as one region)
- Build a BST of quads
- Recursively split quads using similarity threshold
- Save results:
- Outlined Image → highlights quad borders
- Compressed Image → quads filled with average colour
Quad.c→ Main implementation of BST + image functionsimgUtils.c→ Utility functions for image loading/saving (provided with assignment)
To compile:
gcc Quad.c -o quad