From: Young Ryu on
Hi all,

I encountered strange problem. Please run the below code. To my mind, the size of data0 and data 1 should be same (and should be 48 by 48), but data0 is 49 by 49. Could you help me why this happens?

=========================
x=0.5;
b=5;
c=0.2;
data=rand(2400, 2400);

data0=imresize(data, x/b*c, 'nearest');
data1=imresize(data, 0.02, 'nearest'); % x/b*c=0.02

size(data0)
size(data1)
==========================
From: Paul on
Young Ryu,

This is a common problem, though a surprising place to find it. The number .2 is not exactly representable in binary. If you try ((x/b*c)==.2), you will see that it is false. Try rounding (x/b*c) [round(x/b*c)] and it should come out fine.

-Paul

"Young Ryu" <ryuyr77(a)gmail.com> wrote in message <hlv02c$geo$1(a)fred.mathworks.com>...
> Hi all,
>
> I encountered strange problem. Please run the below code. To my mind, the size of data0 and data 1 should be same (and should be 48 by 48), but data0 is 49 by 49. Could you help me why this happens?
>
> =========================
> x=0.5;
> b=5;
> c=0.2;
> data=rand(2400, 2400);
>
> data0=imresize(data, x/b*c, 'nearest');
> data1=imresize(data, 0.02, 'nearest'); % x/b*c=0.02
>
> size(data0)
> size(data1)
> ==========================
From: Jan Simon on
Dear Young!

> I encountered strange problem. Please run the below code. To my mind, the size of data0 and data 1 should be same (and should be 48 by 48), but data0 is 49 by 49. Could you help me why this happens?
>
> =========================
> x=0.5;
> b=5;
> c=0.2;
> data=rand(2400, 2400);
>
> data0=imresize(data, x/b*c, 'nearest');
> data1=imresize(data, 0.02, 'nearest'); % x/b*c=0.02
>
> size(data0)
> size(data1)

This effect is not concerned to IMRESIZE, so the question can be simplified to:
> x=0.5;
> b=5;
> c=0.2;
> x / b * c = 0.02 ?!?!?!?!

Please type it manually: 0.02 - x / b * c
and you won't get 0 due to round off errors.

See chapter 6.1 of: http://matlabwiki.mathworks.com/MATLAB_FAQ

Kind regards and welcome to Matlab! Jan
From: us on
"Young Ryu"
> data1=imresize(data, 0.02, 'nearest'); % x/b*c=0.02

no(!)... - FP evergreen...

x=0.5;
b=5;
c=0.2;
v1=x/b*c;
v2=c*x/b;
v3=.02;
sprintf('%22.20f\n',[v1,v2,v3])
%{
0.02000000000000000400 % <- !
0.02000000000000000000
0.02000000000000000000
%}

% also, look at
http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

us