Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

MATLAB CODE for quadtree

clc;
clear all;
rgbImage = imread('Given_image.png');
% Convert the RGB image to grayscale
grayImage = rgb2gray(rgbImage);
imwrite(grayImage, 'grayscale_example.jpg');
grayImage = imread('grayscale_example.jpg');
[height, width] = size(grayImage);
targetSize = [200, 200];
% Resize the image
resizedImage = imresize(grayImage, targetSize);
imshow(resizedImage);
imwrite(resizedImage, 'resized_grayscale_example.jpg');
% Read the grayscale image
grayImage = imread('resized_grayscale_example.jpg');
%imshow(grayImage)
% Load your 200x200 grayscale image
inputImage = imread('resized_grayscale_example.jpg');
desiredSize = 256; % For a 4x4 quadtree representation
resizedImage = imresize(inputImage, [desiredSize, desiredSize]);
max_level = 4; %Minimum pixel size
threshold = 0.14;
quadtree = qtdecomp(resizedImage, threshold, max_level);
quadtreeImage = uint8(zeros(size(resizedImage)));
% Traverse the quadtree and mark the blocks
for level = 1:max_level
[nr, nc] = size(quadtree);
for i = 1:nr
for j = 1:nc
if quadtree(i, j) == level
x0 = (i - 1) * desiredSize / nr + 1;
x1 = i * desiredSize / nr;
y0 = (j - 1) * desiredSize / nc + 1;
y1 = j * desiredSize / nc;
quadtreeImage(x0:x1, y0:y1) = 255;
end
end
end
end
imshow(quadtreeImage, 'InitialMagnification', 'fit');
title('4x4 Quadtree Representation');
Quadtree representation

Gray Scale represenation

You might also like