Borrar filtros
Borrar filtros

i've divided the image into non-overlapping blocks i.e 16 x 16. i'want to convert these blocks to array using mat2cell... can u tell me hoe to do so?

2 visualizaciones (últimos 30 días)
i've read the tutorial of mat2cell but unable to generalize it for 16x16 blocks.
the code is:
grayImage=imread('inpImage');
grayImage=rgb2gray(grayImage);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
figure;
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Divide the image up into 4 blocks.
% Let's assume we know the block size and that all blocks will be the same size.
blockSizeR = 16;% Rows in block.
blockSizeC = 16; % Columns in block.
% Figure out the size of each block.
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
fprintf('\nSize of whole block is %d x %d\n\n',wholeBlockRows,wholeBlockCols);
% Now scan though, getting each block and putting it as a slice of a 3D array.
blockNumber = 1;
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2);
% Determine starting and ending columns.
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2); % Don't let it go outside the image.
% Extract out the block into a single subimage.
oneBlock = grayImage(row1:row2, col1:col2);
subplot(12,16,blockNumber);
imshow(oneBlock);
caption2 = sprintf('Block #%d\n of %d', blockNumber,blocks);
title(caption2, 'FontSize', fontSize);
drawnow;
blockNumber = blockNumber + 1;
end
end
'oneBlock' represents the intensity matrix of the block...i want to apply the 'mat2cell' function..can u tell me how to do so?
  1 comentario
Image Analyst
Image Analyst el 28 de Mzo. de 2013
Why do you want to do that? Seems to me it would just complicate the matter. Using cell arrays is almost always more complicated. Why do you want all these blocks stored in a cell array? Any reason for storing the blocks instead of just using them and moving on to the next block? What are you wanting to do with each block, besides display it?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mzo. de 2013
mat2cell(grayImage, [repmat(wholeBlockRows, 1, 15), rows-15*wholeBlockRows], [repmat(wholeBlockCols, 1, 15), cols-15*wholeBlockCols], numberOfColorBands)

Más respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by