conversion of floating point to integer

My code to match a image with the images in database is :
img=handles.y;
mat=sum(img,1);
mat=mat(:);
k=zeros(30,1);
for i=1:30
str=strcat(int2str(i),'.pgm');
%concatenates two strings that form the name of the image
eval('img1=imread(str);');
mat1=sum(img1,1);
mat1=mat1(:);
k(i)=max(abs(normxcorr2(mat1,mat)));
end
%take maximum from matrix & store its value & position
vmax=max(k)
uval=int8(fix(vmax))
if uval>=1
figure(11);
op=imread('match.jpg');
imshow(op);
else
figure(12);
dp=imread('mismatch.jpg');
imshow(dp);
why int8(fix(x)) or int16(fix(x)) or int32(fix(x)) or int64(fix(x)) gives value 1 for vmax=1.0000 for few input images and gives value 0 for vmax=1.0000 for few other input images??

답변 (1개)

Walter Roberson
Walter Roberson 2012년 4월 10일

1 개 추천

댓글 수: 3

prateek
prateek 2012년 4월 10일
Actually there are two test images which I have to check for matching with the images in my database.
When I display the value of vmax on command window for first image,it shows 1.0000 and int8(fix(vmax)) converts this value to 1. Till here its okay.
But for the second image when I display the value of vmax on command window for first image,it shows 1.0000 and int8(fix(vmax)) converts this value to 0.
Why is it so?
I know 1.0000 is slightly greater than 1 but int8(fix(x)) should convert all values of x>1 to 1.But this is not happening in my case.
Walter Roberson
Walter Roberson 2012년 4월 10일
1.0000 is not necessarily slightly greater than 1. When you use "format short" then MATLAB displays all numbers within 5/10000 of 1 as 1.0000 including exactly 1 itself.
Display
vmax - 1
to see the difference between vmax and 1 .
prateek
prateek 2012년 4월 11일
Thanks a lot...it helped..

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

질문:

2012년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by