Error in graycomatrix while running following code?
15 次查看(过去 30 天)
显示 更早的评论
I am getting an error as :
Error using graycomatrix
Expected input number 1, I, to be two-dimensional.
Error in graycomatrix>ParseInputs (line 260)
validateattributes(I,{'logical','numeric'},{'2d','real','nonsparse'}, ...
Error in graycomatrix (line 167)
[I, Offset, NL, GL, makeSymmetric] = ParseInputs(varargin{:});
Error in internal (line 50)
GLCM = graycomatrix(LH3,'GrayLimits',[Min_val Max_val],'NumLevels',level);
For the code given as follows:
clc;
clear all;
close all;
m = imread('7.jpg');
scale_extraction(m);
im = m;
[LL LH HL HH] = dwt2(im,'db1');
aa = [LL LH;HL HH];
% % % % 2nd level decomp
[LL1 LH1 HL1 HH1] = dwt2(LL,'db1');
% aa1 = [LL1 LH1;HL1 HH1];
% % % 3rd level Decomp
[LL2 LH2 HL2 HH2] = dwt2(LL1,'db1');
% % % 4th level Decomp
[LL3 LH3 HL3 HH3] = dwt2(LL2,'db1');
aa1 = [LL3 LH3;HL3 HH3];
aa2 = [aa1 LH2;HL2 HH2];
aa3 = [aa2 LH1;HL1 HH1];
aa4 = [aa3 LH;HL HH];
A=im;
Calibration(A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I=imread('7.jpg');
Ig = rgb2gray(I);
[LH3 ,HL3]=Horizondal_Motion(I);
% LH3=I.LH3;
% HL3=I.HL3;
% % % Select the wavelet coefficients oly LH3 and HL3
% % % GLCM features for LH3
LH3 = uint8(LH3);
Min_val = min(min(LH3));
Max_val = max(max(LH3));
level = round(Max_val - Min_val);
%%glcms = graycomatrix(Ig,'numlevels',64,'Offset',[0 1; -1 1; -1 0; -1 -1]);
GLCM = graycomatrix(LH3,'GrayLimits',[Min_val Max_val],'NumLevels',level);
stat_feature = graycoprops(GLCM);
Energy_fet1 = stat_feature.Energy;
Contr_fet1 = stat_feature.Contrast;
Corrla_fet1 = stat_feature.Correlation;
Homogen_fet1 = stat_feature.Homogeneity;
% % % % % Entropy
R = sum(sum(GLCM));
Norm_GLCM_region = GLCM/R;
mn=length(GLCM)^2;
Ent_int = 0;
for k = 1:length(GLCM)^2
if Norm_GLCM_region(k)~=0
Ent_int = Ent_int + Norm_GLCM_region(k)*log2(Norm_GLCM_region(k));
end
end
Entropy_fet1 = -Ent_int;
HL3 = uint8(HL3);
Min_val = min(min(HL3));
Max_val = max(max(HL3));
level = round(Max_val - Min_val);
GLCM = graycomatrix(HL3,'GrayLimits',[Min_val Max_val],'NumLevels',level);
stat_feature = graycoprops(GLCM);
Energy_fet2 = stat_feature.Energy;
Contr_fet2 = stat_feature.Contrast;
Corrla_fet2= stat_feature.Correlation;
Homogen_fet2 = stat_feature.Homogeneity;
% % % % % Entropy
R = sum(sum(GLCM));
Norm_GLCM_region = GLCM/R;
Ent_int = 0;
for k = 1:length(GLCM)^2
if Norm_GLCM_region(k)~=0
Ent_int = Ent_int + Norm_GLCM_region(k)*log2(Norm_GLCM_region(k));
end
end
% % % % % % Ent_int = entropy(GLCM);
Entropy_fet2 = -Ent_int;
% % % % % Feature Sets
F1 = [Energy_fet1 Contr_fet1 Corrla_fet1 Homogen_fet1 Entropy_fet1];
F2 = [Energy_fet2 Contr_fet2 Corrla_fet2 Homogen_fet2 Entropy_fet2];
disp(F2);
Q = [F1 F2]';
stereo(mn);
% Update handles structure
I2 = imread('7.jpg');
AA4 =double(I2);
output = im2bw(AA4);
seg_image = output;
[r c] = size(seg_image);
Pcount = 0;
for h = 1:r
for w = 1:c
temp = seg_image(h,w);
if temp ~= 0
Pcount = Pcount+1;
end
end
end
Pixel_count = Pcount;
tarea = (sqrt(Pcount)).* 0.264;
disp(tarea);
mean_seg = mean(output(:));
var_seg = var(output(:));
std_seg = sqrt(var_seg);
ent_seg = entropy(output);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I = imread('7.jpg');
[IDX,sep]=Calculation(I,5);
Input_feature = I.Qfeature;
Database_feature= I.Dfeature;
[queryfeature features] = Extraction(Input_feature,Database_feature);
Q = queryfeature;
[r1 c1] = size(features);
str1 = 'image';str3 = '.mat';
for i = 1:c1
name = strcat(str1,num2str(i));
P = features(:,i);
save(name,'P');
end
M = 5;N =1;
[r1 c1] = size(features);
str1 = 'image';str3 = '.mat';
for i = 1:c1
name = strcat(str1,num2str(i));
valu = load(name);
P(:,i) = valu.P;
if M==0
N =N+1;
M = 4;
else
M = M-1;
end
T1 (1,i) = N;
end
disp(P);
disp(T1);
T1 = ind2vec(T1);
% Creation of Probabilistic Neural network
net = newpnn(P,T1);
I.net = net;
I.queryfeature = Q;
a=imread('7.jpg');
%imshow(a)
b = rgb2gray(a);
b = im2double(b);
shading flat
figure;
%colormap(hot)
title('Volume Estimation');
mesh(b);
0 个评论
回答(1 个)
Walter Roberson
2019-4-30
JPEG images are almost always RGB, 3 dimensional. 99.999% of the time that they look grayscale, they are actually RGB.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!