Error in extracting wavelet based features from images

2 次查看(过去 30 天)
I am trying to extract wavelet based features from images. The wavelet decomposition is accomplished
on the original ROI. The output lowpass sub-band of the wavelet transform is further decompressed into
two more sequences. This three-level of decompositions is done to filter out redundant information and obtain the image
compressed enough. Then, putting together the last four sub-bands are used to build a matrix of four sub-bands. To further
compress them, principal components of this matrix are driven for feature extraction. My code works fine for a single image. But when I try to
extract the features of all the images in the folder, Matlab throws me an error message. Any suggestions would be helpful.
myFolder = 'D:\regionGrowing_MLT\newim\Segmentation Results';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
% I=imread('segFP1.jpg');% intensity image
[HH,HL,LL,LH] = dwt2(imageArray,'sym4','mode','per');
[HH1,HL1,LL1,LH1] = dwt2(LL,'sym4','mode','per');
[HH2,HL2,LL2,LH2] = dwt2(LL1,'sym4','mode','per');
p=pca([HH2,HL2,LL2,LH2]);
glcms = graycomatrix(p);
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
Mean = mean2(p);
Standard_Deviation = std2(p);
Entropy = entropy(p);
RMS = mean2(rms(p));
Skewness = skewness(double(p(:)));
Kurtosis = kurtosis(double(p(:)));
Variance = mean2(var(double(p)));
a = sum(double(p(:)));
Smoothness = 1-(1/(1+a));
% Inverse Difference Movement
m = size(i,1);
n = size(i,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = p(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff);
ff(k,:) = [Contrast, Correlation, Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Skewness, Kurtosis, Variance, Smoothness, IDM];
end
The following error message is being displayed:
Error using bsxfun
Non-singleton dimensions of the two input arrays must match each other.
Error in pca>localSVD (line 481)
x = bsxfun(@times, x, PhiSqrt);
Error in pca (line 354)
[U,sigma, coeff, wasNaN] = localSVD(x, n,...
Error in win (line 26)
p=pca([HH2,HL2,LL2,LH2]);

回答(1 个)

Prabhan Purwar
Prabhan Purwar 2021-7-28
Hi,
I tried to replicate the issue in R2021a but the code seems to work without any error with all the three images. Could you elaborate upon the reproduction steps so that we can replicate the issue.
Thanks

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by