Auto create patches and extract glcm of the patches from multi-image file
1 次查看(过去 30 天)
显示 更早的评论
hi.. im working on image processing using matlab. actually i'm sorry, it's the first time im working on matlab. i tried to do to get the pathes of multi-image file and also extract the glcm of every patch of those image. i want to do it automatically. i have following this code and add code for extracting glcm from each patch. but i think i still make mistakes coz still get error report in :
Error in GLCM1 (line 53)
baseFileName = ca(k).name;
if u guys could guide me it realt means a lot for me, please. here's the code that i was trying to create :
folder = fullfile('D:\Program Files\MATLAB\R2017a\bin\DATABC1\Train\G1');
fileNames = dir(fullfile(folder, '*.tif'));
baseFileName1 = '6a.tif';
fullFileName = fullfile(folder, baseFileName1);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName1;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
h=zeros(28,4);%row->no. of image, column->no. of feature
% Create blocks
rgbImage = imread(fullFileName);
gr = rgb2gray(rgbImage);
imshow(gr);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
[rows, columns, numberOfColorBands] = size(gr);
blockSizeR = 100; % Rows in block.
blockSizeC = 100; % Columns in block.
% The size of each block in rows.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
% The size of each block in columns.
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
% Create the cell array
% Divided up into blocks.
if numberOfColorBands > 1
ca = mat2cell(gr, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(gr, blockVectorR, blockVectorC);
end
% Display all the blocks.
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
for k = 1:length(ca)
baseFileName = ca(k).name;
I = imread(baseFileName);
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r, I);
subplot(numPlotsR, numPlotsC, plotIndex);
rgbBlock = ca{r,c,I};
imshow(rgbBlock);
GLCM = graycomatrix(rgbBlock,'Offset', [0 1;-1 1;-1 0;-1 -1],'NumLevel', 8,'Symmetric',true);
stats = GLCM_Features1(GLCM,'Contrast, Correlation, Energy, Homogeneity');
h(k,1)= stats.contr(1);%contrast
h(k,2)= stats.corrp(1);%Correlation
h(k,3)= stats.homom(1);%Homogeneity
h(k,4)= stats.energ(1);%Energy
[rowsB, columnsB, numberOfColorBandsB] = size(rgbBlock);
caption = sprintf('Block #%xzd of %d\n%d rows by %d columns', ...
plotIndex, numPlotsR*numPlotsC, rowsB, columnsB);
title(caption);
drawnow;
plotIndex = plotIndex + 1;
end
end
end
what should i do ? i realy need your help, please.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!