I am trying to apply DCT compression on an image 1024 *1024 but I want to divide this image into 8*8 sub blocks. How can I divide this image to 8*8 sub blocks? can anybody help me please
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
image_folder= 'C:\Octave\Octave-4.2.1\share\octave\packages\images'
filename=dir(fullfile(image_folder,'*.jpg'))
n = 4
f=fullfile(image_folder,filename(n).name)
my_image=imread(f)
figure()
imshow(my_image)
0 commentaires
Réponses (1)
David Goodmanson
le 30 Oct 2018
Hi John,
Here is one approach. For 8x8 blocks, you basically have a 256x256 matrix where each 'element' is an 8x8 block. Then you can get the contents of the block in row i (out of 256 rows) and column j (out of 256 columns) with
Q = rand(1024,1024); % original matrix
R = zeros(size(Q));
bi = @(i) 8*(i-1)+(1:8); % block index function
i = 7; j = 77; % for example
q = Q(bi(i),bi(j)) % 8x8 block
Suppose you change q to qnew by some process. Then you can use for loops i,j and fill in R (or the original Q) with
R(bi(i),bi(j)) = qnew;
To make the bi call as short as possible, bi was hardwired for 8x8. For a general block of size mxn,
bi = @(n,i) n*(i-1)+(1:n); % block index function
q = Q(bi(m,i),bi(n,j))
R(bi(m,i),bi(n,j)) = qnew;
Other approaches are possible, such as stacking all the blocks into an 8x8x65536 array. but getting the blocks in and out is less easy.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!