how to rearrange each block into a column vector?

2 visualizzazioni (ultimi 30 giorni)
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
  2 Commenti
Cedric
Cedric il 11 Mag 2013
Modificato: Cedric il 11 Mag 2013
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.
Tia
Tia il 11 Mag 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

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 11 Mag 2013
Modificato: Image Analyst il 11 Mag 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.
%
clc;
clearvars;
close all;
workspace;
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 = [];
end
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) theBlockStructure.data(:);
% 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);
  4 Commenti
Tia
Tia il 13 Mag 2013
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
Image Analyst
Image Analyst il 13 Mag 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by