How can I concatenate a uint8 array in a for loop to form an image?

3 vues (au cours des 30 derniers jours)
CharlesB
CharlesB le 21 Avr 2017
Commenté : Image Analyst le 22 Avr 2017
%%Grayscale Baboon Image
I2 = imread('baboon.png');
%Splitting image into a cell array
chunk_size2 = [16 16]; % your desired size of the chunks image is broken into
sc2 = sz2 ./ chunk_size2; % number of chunks in each dimension; must be integer
% split to chunk_size(1) by chunk_size(2) chunks
X2 = mat2cell(I2, chunk_size2(1) * ones(sc2(1),1), chunk_size2(2) *ones(sc2(2),1));
[r, c] = size(X2);
%Extracting LBP features for each cell and concatinating them into a
%histogram
result = [];
for row = 1 : r
for col = 1 : c
Z = cell2mat(X2(row, col));
[row_cell, col_cell] = size(Z);
for rows = 2 : row_cell - 1
for cols = 2 : col_cell - 1
centerPixel = Z(rows,cols);
pixel7= Z(rows-1, cols-1) > centerPixel;
pixel6= Z(rows-1, cols) > centerPixel;
pixel5= Z(rows-1, cols+1) > centerPixel;
pixel4= Z(rows, cols+1) > centerPixel;
pixel3= Z(rows+1, cols+1) > centerPixel;
pixel2= Z(rows+1, cols) > centerPixel;
pixel1= Z(rows+1, cols-1) > centerPixel;
pixel0= Z(rows, cols-1) > centerPixel;
eightBitNumber = uint8(...
pixel7 * 2^7 + pixel6 * 2^6 + ...
pixel5 * 2^5 + pixel4 * 2^4 + ...
pixel3 * 2^3 + pixel2 * 2^2 + ...
pixel1 * 2 + pixel0);
localBinaryPatternImage(rows, cols) = eightBitNumber;
result = [result localBinaryPatternImage(rows,cols)];
end
end
end
end
localBinaryPatternImage results in a 15x15 unit8 image that represents the lbp features of the last cell in the cell array X2. The for loop is only giving the last 15x15 uint8 array of the last cell in the cell array X2. How can I concatenate all the localBinaryPatternImage 15x15 unit arrays of each cell to form the entire image?

Réponses (1)

Image Analyst
Image Analyst le 21 Avr 2017
Just use the original image, I2. Don't even bother with using X2 or Z - there's no point.
  2 commentaires
CharlesB
CharlesB le 22 Avr 2017
I cannot as that is what is requested from me to split the image into cells then apply the lbp.
Image Analyst
Image Analyst le 22 Avr 2017
You can make a 3-D array using cat(3,...)
if row == 1 && col == 1
localBinaryPatternImage3D = localBinaryPatternImage;
else
localBinaryPatternImage3D = cat(3, localBinaryPatternImage3D, localBinaryPatternImage);
end

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by