how to rearrange each block into a column vector?

5 views (last 30 days)
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
Tia on 11 May 2013
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

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 11 May 2013
Edited: Image Analyst on 11 May 2013
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);
Image Analyst
Image Analyst on 13 May 2013
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.

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!