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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
David Goodmanson
2018-10-30
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!