i've read the tutorial of mat2cell but unable to generalize it for 16×16 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; endend
'oneBlock' represents the intensity matrix of the block…i want to apply the 'mat2cell' function..can u tell me how to do so?
Best Answer