MATLAB Answers


how to rearrange each block into a column vector?

Asked by Tia
on 11 May 2013

example, i have an image,it's 256x256pixel,then i split it into 8x8. How to rearrange each block 8x8 into column vector and form it as 256x256 size image matrix?

Thank you


Are blocks stored in a cell array? Why column vectors? You don't want to reaggregate blocks in a 256x256 array in a way that corresponds to how you split the original image? If not, you will have to define how/where these column vectors have to appear in the image.

yes..all blocks're in a cell array.if an image has size in 256x256. i'll split it into 8x8, then i get 32 subblocks. actually i want to move 8x8 to another block based on 32 subblocks. i don't have an idea about that. could you tell me what should i do to move it?

thank you for your time

Log in to comment.


No products are associated with this question.

1 Answer

Answer by Image Analyst
on 11 May 2013
Edited by Image Analyst
on 11 May 2013
 Accepted answer

An 8 by 8 block is 64 elements, so your columns will be 64 rows tall. And with a block size of 8, you are going to have 32 of these columns for each 8 row tall strip. And there will be 32 8-row-tall strips going down your image. So you're going to have 32*32 = 1024 of these 64 row tall columns. Explain to me how these 1024 columns are supposed to be reorganized into a 256x256 matrix.

You may be after something like this, which uses blockproc():

% Demo code to divide the image up into 8 pixel by 8 pixel blocks
% and replace each pixel in the block by the column vector
% of all the pixels in the block.
close all;
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
if ~exist(folder, 'dir')
	% If that folder does not exist, don't use a folder
	% and hope it can find the image on the search path.
	folder = [];
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize')); 
set(gcf,'name','Image Analysis Demo','numbertitle','off') 
% Define the function that we will apply to each block.
% First in this demo we will take the block and shape it into a column vector.
myFunction = @(theBlockStructure);
% Block process the image to replace every pixel in the 
% 8 pixel by 8 pixel block by the column vector of the pixels in the block.
blockSize = [8 8];
blockyImage8 = blockproc(single(grayImage), blockSize, myFunction); % Works.
[rows, columns] = size(blockyImage8);
% Display the block image.
subplot(2, 2, 2);
imshow(blockyImage8, []);
caption = sprintf('Block Image\n32 by 32 blocks. Input block size = 8\n%d rows by %d columns', rows, columns);
title(caption, 'FontSize', fontSize);


I don't know what that means.

oh.. i'm sorry. could you tell me how to extract dc coefficient from dct?Where can i get more information about it? I honestly don't have the words to thank you for your kindness

That would be just the element at (1,1), unless you've called fftshift() on it, in which case it will be the element near the center.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!