Info

此问题已关闭。 请重新打开它进行编辑或回答。

the problem with loop

2 次查看(过去 30 天)
juveria fatima
juveria fatima 2018-9-12
关闭: MATLAB Answer Bot 2021-8-20
test1 images and reference images imagedb exceeds 6 mb size so i couldn't attach the image for test you can take any images for test
the problem is am getting only surface roughness 1 is displayed
am unable to get the rest surface roughness
test1=imread('D:\HD\Images\5 0.75 30\5 0.75 30 4.bmp');
imagedb{1}=imread('D:\HD\Images\5 0.75 30\5 0.75 30 1.bmp');
imagedb{2}=imread('D:\HD\Images\5 1.25 30\5 1.25 30 1.bmp');
imagedb{3}=imread('D:\HD\Images\10 0.25 30\10 0.25 30 1.bmp');
imagedb{4}=imread('D:\HD\Images\10 0.75 30\10 0.75 30 1.bmp');
imagedb{5}=imread('D:\HD\Images\10 0.75 50\10 0.75 50 1.bmp');
imagedb{6}=imread('D:\HD\Images\15 1.25 30\15 1.25 30 1.bmp');
resizetest=imresize(test1,[256,256]);
eqtest=histeq(resizetest);
gtest=rgb2gray(eqtest);
imhist(eqtest)
%imhist()
for x=1:6
resize{x}=imresize(imagedb{x},[256,256]);
eq{x}=histeq(resize{x});
g{x}=rgb2gray(eq{x});
end
%count=0;
%rg{1}=imresize(g{1},[20 20]);
%rgtest=imresize(gtest,[20 20]);
%hamming=pdist2(rg{1},rgtest,'hamming');
%disp(hamming)
%for i=1:20
% for j=1:20
%count=hamming(j,i)+count;
% end
%end
%answer=count/400;
%disp(answer)
min=10^5;
for i=1:6
dist{i}= (1/6) * (sum((g{i} - gtest)) );
if dist{i}< min
min=dist{i};
index=i;
end
end
disp(min)
disp(index)
switch(index)
case 1
fprintf('The Surface Roughness Is 2.403\n');
case 2
fprintf('The Surface Roughness Is 3.22\n');
case 3
fprintf('The Surface Roughness Is 1.595\n');
case 4
fprintf('The Surface Roughness Is 2.236\n');
case 5
fprintf('The Surface Roughness Is 2.125\n');
case 6
fprintf('The Surface Roughness Is 1.055\n');
end
%Dist1 = (1/6)*(sum((g1(:).* g2(:) );
%Dist2 = (1/6)*(sum((g1(:).* g3(:) );
%Dist3 = (1/6)*(sum((g1(:).* g2(:) );
%disp(Dist1)
%disp(Dist2)
%disp(Dist3)
  2 个评论
Walter Roberson
Walter Roberson 2018-9-12
histeq() with one parameter is only valid for intensity (grayscale) images, and in that case returns the equalized grayscale image. You record that in eq{x}. But why do you rgb2gray() that, since you can be sure it is already gray?
juveria fatima
juveria fatima 2018-9-12
yeah ok that i will change ,please help me with the loop

回答(1 个)

Walter Roberson
Walter Roberson 2018-9-12
You have
dist{i}= (1/6) * (sum((g{i} - gtest)) );
where g{i} is a grayscale version of an image that was resized to 256 x 256 and then histogram equalized. Therefore g{i} will be a 2D array, 256 x 256. When you sum g{i}-gtest you are summing over the first dimension and will get a 1 x 256 result. dist{i} is therefore 1 x 256.
You then have
if dist{i}< min
min=dist{i};
index=i;
end
but remember dist{i} is a 1 x 256. When you < a 1 x 256 against a scalar, you get a 1 x 256 result. When you if a vector, the result is considered true only if all entries are non-zero, so your test is equivalent to if all(dist{i} < min) . And perhaps that only ever happens for i == 6 -- the other i values might lead to vectors in which some of the entries are less than the minimum but not all of them are.
Your code does not promise that index will be set at all. You only set index conditionally, and it could be the case that none of the conditions match.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by