MATLAB Answers

how to combine the image sub blocks back to the image???

조회 수: 10(최근 30일)
user06 13 Mar 2015
편집: user06 13 Mar 2015
i have divide the 256*256 image into 4 blocks and into the each block i have performed some operation. now i want that all the blocks will combine back to the image. how to to that. i have divided the image by the following code.
% Read the image from disk.
rgbImage = imread(fullFileName);
rgbImage=imresize(a,[512 512]);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage)
% The first way to divide an image up into blocks is by using mat2cell().
blockSizeR = 128; % Rows in block.
blockSizeC = 128; % Columns in block.
% Figure out the size of each block in rows.
% Most will be blockSizeR but there may be a remainder amount of less than that.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
% Figure out the size of each block in columns.
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
% Create the cell array, ca.
% Each cell (except for the remainder cells at the end of the image)
% in the array contains a blockSizeR by blockSizeC by 3 color array.
% This line is where the image is actually divided up into blocks.
if numberOfColorBands > 1
% It's a color image.
ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
ca = mat2cell(rgbImage, blockVectorR, blockVectorC);
% Now display all the blocks.
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
% Specify the location for display of the image.
subplot(numPlotsR, numPlotsC, plotIndex);
% Extract the numerical array out of the cell
rgbBlock = ca{r,c};
imshow(rgbBlock); % Could call imshow(ca{r,c}) if you wanted to.
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
% Make the caption the block number.
caption = sprintf('Block #%d of %d\n%d rows by %d columns', ...
plotIndex, numPlotsR*numPlotsC, rowsB, columnsB);
% Increment the subplot to the next location.
plotIndex = plotIndex + 1;
% Display the original image in the upper left.
subplot(4, 6, 1);
title('Original Image');
this code belongs to imageAnalyst.

  댓글 수: 0

로그인 to comment.


이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by