I am getting an error while extracting texture feature. Can anyone please help me to remove those?

2 vues (au cours des 30 derniers jours)
I am trying to extract features of an image. And getting an error as following
Undefined function 'conv2' for input arguments of type 'double' and attributes 'full 3d real'.
Error in Horizondal_Motion (line 85)
A=conv2(img, B, 'same');
Error in vulome (line 34)
[LH3 ,HL3]=Horizondal_Motion(I);
hiriontal function is stated in program as comment:
I = imread('7.jpg');
m=imresize(I,[256 256]);
scale_extraction(m);
% wmane = db1
% % % % 1st level decomp
[LL LH HL HH] = dwt2(m,'db1');
% % % % 2nd level decomp
[LL1 LH1 HL1 HH1] = dwt2(LL,'db1');
% % % 3rd level Decomp
[LL2 LH2 HL2 HH2] = dwt2(LL1,'db1');
% % % 4th level Decomp
[LL3 LH3 HL3 HH3] = dwt2(LL2,'db1');
aa = [LL LH;HL HH];
aa1 = [LL3 LH3;HL3 HH3];
aa2 = [aa1 LH2;HL2 HH2];
aa3 = [aa2 LH1;HL1 HH1];
aa4 = [aa3 LH;HL HH];
Calibration(m);
[LH3 ,HL3]=Horizondal_Motion(I);
LH3 = uint8(LH3);
Min_val = min(min(LH3));
Max_val = max(max(LH3));
level = round(Max_val - Min_val);
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);
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);
7.jpg
% function [ LH3 ,HL3] = Horizondal_Motion( I )
% %UNTITLED3 Summary of this function goes here
% % Detailed explanation goes here
%
% A=I;
% %figure,imshow(A);
% Img=A;
%
% im = I;
%
% [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')
% %WINDOW SIZE
% M=10;
% N=20;
%
%
% mid_val=round((M*N)/2);
%
% %FIND THE NUMBER OF ROWS AND COLUMNS TO BE PADDED WITH ZERO
% in=0;
% for i=1:M
% for j=1:N
% in=in+1;
% if(in==mid_val)
% PadM=i-1;
% PadN=j-1;
% break;
% end
% end
% end
% %PADDING THE IMAGE WITH ZERO ON ALL SIDES
% B=padarray(A,[PadM,PadN]);
%
% for i= 1:size(B,1)-((PadM*2)+1)
%
% for j=1:size(B,2)-((PadN*2)+1)
% cdf=zeros(256,1);
% inc=1;
% for x=1:M
% for y=1:N
% %FIND THE MIDDLE ELEMENT IN THE WINDOW
% if(inc==mid_val)
% ele=B(i+x-1,j+y-1)+1;
% end
% pos=B(i+x-1,j+y-1)+1;
% cdf(pos)=cdf(pos)+1;
% inc=inc+1;
% end
% end
%
% %COMPUTE THE CDF FOR THE VALUES IN THE WINDOW
% for l=2:256
% cdf(l)=cdf(l)+cdf(l-1);
% end
% Img(i,j)=round(cdf(ele)/(M*N)*255);
% end
% end
%
% img = I;
% %figure, subplot(1,2,1),imshow(img);
% %img = rgb2gray(img);
% img = double (img);
% %Value for Thresholding
% T_Low = 0.075;
% T_High = 0.175;
% %Gaussian Filter Coefficient
% B = [2, 4, 5, 4, 2; 4, 9, 12, 9, 4;5, 12, 15, 12, 5;4, 9, 12, 9, 4;2, 4, 5, 4, 2 ];
% B = 1/159.* B;
% %Convolution of image by Gaussian Coefficient
% A=conv2(img, B, 'same');
% %Filter for horizontal and vertical direction
% KGx = [-1, 0, 1; -2, 0, 2; -1, 0, 1];
% KGy = [1, 2, 1; 0, 0, 0; -1, -2, -1];
% %Convolution by image by horizontal and vertical filter
% Filtered_X = conv2(A, KGx, 'same');
% Filtered_Y = conv2(A, KGy, 'same');
% %Calculate directions/orientations
% arah = atan2 (Filtered_Y, Filtered_X);
% arah = arah*180/pi;
% pan=size(A,1);
% leb=size(A,2);
% %Adjustment for negative directions, making all directions positive
% for i=1:pan
% for j=1:leb
% if (arah(i,j)<0)
% arah(i,j)=360+arah(i,j);
% end;
% end;
% end;
% arah2=zeros(pan, leb);
% %Adjusting directions to nearest 0, 45, 90, or 135 degree
% for i = 1 : pan
% for j = 1 : leb
% if ((arah(i, j) >= 0 ) && (arah(i, j) < 22.5) || (arah(i, j) >= 157.5) && (arah(i, j) < 202.5) || (arah(i, j) >= 337.5) && (arah(i, j) <= 360))
% arah2(i, j) = 0;
% elseif ((arah(i, j) >= 22.5) && (arah(i, j) < 67.5) || (arah(i, j) >= 202.5) && (arah(i, j) < 247.5))
% arah2(i, j) = 45;
% elseif ((arah(i, j) >= 67.5 && arah(i, j) < 112.5) || (arah(i, j) >= 247.5 && arah(i, j) < 292.5))
% arah2(i, j) = 90;
% elseif ((arah(i, j) >= 112.5 && arah(i, j) < 157.5) || (arah(i, j) >= 292.5 && arah(i, j) < 337.5))
% arah2(i, j) = 135;
% end;
% end;
% end;
% %figure, imagesc(arah2); colorbar;
% %Calculate magnitude
% magnitude = (Filtered_X.^2) + (Filtered_Y.^2);
% magnitude2 = sqrt(magnitude);
% BW = zeros (pan, leb);
% %Non-Maximum Supression
% for i=2:pan-1
% for j=2:leb-1
% if (arah2(i,j)==0)
% BW(i,j) = (magnitude2(i,j) == max([magnitude2(i,j), magnitude2(i,j+1), magnitude2(i,j-1)]));
% elseif (arah2(i,j)==45)
% BW(i,j) = (magnitude2(i,j) == max([magnitude2(i,j), magnitude2(i+1,j-1), magnitude2(i-1,j+1)]));
% elseif (arah2(i,j)==90)
% BW(i,j) = (magnitude2(i,j) == max([magnitude2(i,j), magnitude2(i+1,j), magnitude2(i-1,j)]));
% elseif (arah2(i,j)==135)
% BW(i,j) = (magnitude2(i,j) == max([magnitude2(i,j), magnitude2(i+1,j+1), magnitude2(i-1,j-1)]));
% end;
% end;
% end;
% BW = BW.*magnitude2;
% %figure, imshow(BW);
% %Hysteresis Thresholding
% T_Low = T_Low * max(max(BW));
% T_High = T_High * max(max(BW));
% T_res = zeros (pan, leb);
% for i = 1 : pan
% for j = 1 : leb
% if (BW(i, j) < T_Low)
% T_res(i, j) = 0;
% elseif (BW(i, j) > T_High)
% T_res(i, j) = 1;
% %Using 8-connected components
% elseif ( BW(i+1,j)>T_High || BW(i-1,j)>T_High || BW(i,j+1)>T_High || BW(i,j-1)>T_High || BW(i-1, j-1)>T_High || BW(i-1, j+1)>T_High || BW(i+1, j+1)>T_High || BW(i+1, j-1)>T_High)
% T_res(i,j) = 1;
% end;
% end;
% end;
% edge_final = uint8(T_res.*255);
% %Show final edge detection result
% figure;
% title('Reconstruction');
% imshow(edge_final);
%
%
%
% end
%

Réponse acceptée

Geoff Hayes
Geoff Hayes le 14 Avr 2019
shweta - I think the problem may be due to your img matrix still being three-dimensional. It looks like you may have commented out the line
% %img = rgb2gray(img);
which would take your 3D image and convert it a 2D mxn grayscale image. From conv2 input array, the input array is expected to be a vector or matrix, which suggests a 1D or 2D input. If I use the following code
myImage = imread('someImage.jpeg');
B = [2, 4, 5, 4, 2; 4, 9, 12, 9, 4;5, 12, 15, 12, 5;4, 9, 12, 9, 4;2, 4, 5, 4, 2 ];
B = 1/159.* B;
A=conv2(myImage, B, 'same');
then I get the same error as you. So try calling the rgb2gray function and see if that helps.
  1 commentaire
Image Analyst
Image Analyst le 14 Avr 2019
You'll need to convert to double since imread() returns integers
myImage = imread('someImage.jpeg');
B = [2, 4, 5, 4, 2; 4, 9, 12, 9, 4; 5, 12, 15, 12, 5; 4, 9, 12, 9, 4; 2, 4, 5, 4, 2 ];
B = B / sum(B(:)); % Normalize to 1 so we don't change the mean gray level.
filteredImage = conv2(double(myImage), B, 'same');
filteredImage = uint8(filteredImage); % OPTIONAL - just if you want it back into an integer image.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by