how to divide an image to 4 equal parts and again divide those 4 images into another 4 parts and convert it to a matrix?

1 view (last 30 days)
Hi,
I am doing a project where I want to divide an image first into 4 parts and based on the threshold criteria each part of the main image has to be again divided into another 4 parts and it should carry on till the dim is 1xn or nx1? (As my image is 24x124 it should be divided till 1xn)
I could first divide the image into 4 parts and store as a matrix, but further i am unable to divide each image into another four parts?
Here is my code:
load LTP54
ROI = ZI(37:60,949:1072);
[rows, columns] = size(ROI);
n = 2;
r = rows/n;
c = columns/n;
k = r/n;
l = c/n;
output(:,:,n^2) = zeros(r,c);
op(:,:,n^2) = zeros(k,l);
cnt = 1;
for i=1:n
for j=1:n,
output(:,:,cnt) = ROI((j-1)*r+1:j*r, (i-1)*c+1:i*c);
% I = output(:,:,cnt);
% op(:,:,cnt) = I(((j-1)*k+1:k*r), ((i-1)*l+1:i*l));
cnt = cnt + 1;
end
end
cnt1 = 1;
for i = 1:n
for j = 1:n
I = output(:,:,1);
op(:,:,cnt1) = I(((j-1)*k+1:j*k), ((i-1)*l+1:i*l));
cnt1 = cnt1+1;
end
end
In the second for loop i am able to take only 1 part as my input and divide it into 4 parts, but not all 4 parts of the image.
Could any one help me with this?

Accepted Answer

Image Analyst
Image Analyst on 8 Jan 2015
Sounds similar to what qtdecomp() (quadtree decomposition) does.
  1 Comment
Rahul Krishna
Rahul Krishna on 8 Jan 2015
ya, we have qtdecomp() function but it only works when the size is 2^m x 2^n or 2^n x 2^n or 2^n x 2^n but it doesn't work for other multiples of 2.
My image is having a matrix of 24x128 pixels. I am unable to use qtdecomp(). So i want to divide it by making a function of my own.
Thanks for your reply.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!