how to rearrange each block into a column vector?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Cedric
2013-5-11
编辑:Cedric
2013-5-11
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.
采纳的回答
Image Analyst
2013-5-11
编辑:Image Analyst
2013-5-11
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 个评论
Image Analyst
2013-5-13
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!