% Display the original image in the upper left. % Increment the subplot to the next location. PlotIndex, numPlotsR*numPlotsC, rowsB, columnsB) = size(rgbBlock) Ĭaption = sprintf('Block #%d of %d\n%d rows by %d columns'. Imshow(rgbBlock) % Could call imshow(ca) if you wanted to. % Extract the numerical array out of the cell Subplot(numPlotsR, numPlotsC, plotIndex) % Specify the location for display of the image. % This line is where the image is actually divided up into blocks.Ĭa = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands) Ĭa = mat2cell(rgbImage, blockVectorR, blockVectorC) įprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r) % in the array contains a blockSizeR by blockSizeC by 3 color array.
% Each cell (except for the remainder cells at the end of the image) WholeBlockCols = floor(columns / blockSizeC) īlockVectorC = % Figure out the size of each block in columns. WholeBlockRows = floor(rows / blockSizeR) īlockVectorR = % Most will be blockSizeR but there may be a remainder amount of less than that. % Figure out the size of each block in rows. Set(gcf, 'units','normalized','outerposition',) % Uncomment line below if you want to see how it works with a gray scale image. % Test code if you want to try it with a gray scale image. Check the search path for it.įullFileName = baseFileName % No path this time.ĮrrorMessage = sprintf('Error: %s does not exist.', fullFileName)
% Get the full filename, with path prepended.įullFileName = fullfile(folder, baseFileName) % Read in a standard MATLAB color demo image.įolder = fullfile(matlabroot, '\toolbox\images\imdemos') Workspace % Make sure the workspace panel is showing. % In this demo, I demonstrate that method with a grayscale image.Ĭlose all % Close all figures (except those of imtool.) % Another way to split the image up into blocks is to use indexing. % In this demo, I demonstrate that with a color image. % The first way to divide an image up into blocks is by using mat2cell(). % Demo to divide an image up into blocks (non-overlapping tiles).
This demo code shows how to split an image into non-overlapping blocks or tiles: