How to read RGB values from each block after running this code?
Show older comments
I have written a code for segment an image into 12 blocks.
clear; clc;
i=imread('./train/aa.png');
i2=imresize(i,[400,300]);
[rows columns numberOfColorBands] = size(i2);
%divide image up into blocks
blockSizeR = 100; %Rows in block
blockSizeC = 100; %Columns in block
%Figure out the size of each block in rows.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows)];
% Figure out the size of each block in columns.
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols)];
% Create the cell array, ca.
% 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(i2, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(i2, blockVectorR, blockVectorC);
end
% 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
% just for tutorial purposes.
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);
title(caption);
drawnow;
% Increment the subplot to the next location.
plotIndex = plotIndex + 1;
end
end
Now,I want to read the RGB values from each block and calculate their mean and standard deviation and make a 72 element feature vector that would be feeded in to the feature vector storage. Please help. I need to submit the project. Thank you very much.
Accepted Answer
More Answers (0)
Categories
Find more on Sources in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!