フィルターのクリア

why matlab rounding the result itself?

2 ビュー (過去 30 日間)
anika hossain
anika hossain 2015 年 8 月 15 日
コメント済み: anika hossain 2015 年 8 月 19 日
my code is given below-
w=imread('win.png');%its a 32X32 picture
for i=1:32
for j=1:32
wrr(i,j)=w(i,j)*.02;
end
end
disp('wrr');
disp(wrr);
the problem is- its rounding the pixel values,like if w(i,j)=178 then after multiplication with .02 wrr(i,j)=4 where it should be 3.56. i need the floating point for further work. can anyone help?
  7 件のコメント
Star Strider
Star Strider 2015 年 8 月 19 日
I’m not familiar enough with wavelets or watermarking to answer. Please post this as a new Question, so those with the necessary background can see it and respond to it.
I will delete it from this Question in a few days.
anika hossain
anika hossain 2015 年 8 月 19 日
ok

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2015 年 8 月 15 日
編集済み: Star Strider 2015 年 8 月 15 日
You need to cast ‘w’ as double before you do the calculations. You can recast it as whatever it was previously to save it later.
The easiest way might be:
w=imread('win.png');%its a 32X32 picture
wrr = double(w);
for i=1:32
for j=1:32
wrr(i,j)=wrr(i,j)*.02;
end
end
disp('wrr');
disp(wrr);
That preserves the original ‘w’ if you want to do that.
However the easiest way to do what you want is simply:
w=imread('win.png');%its a 32X32 picture
wrr = double(w) * 0.02;
  4 件のコメント
Image Analyst
Image Analyst 2015 年 8 月 19 日
I don't know why MATLAB doesn't "promote" variables to the more general class like other languages. If you do b=a*0.1234, and "a" is uint8 then b will be uint8. I think most languages would make b double.
Guillaume
Guillaume 2015 年 8 月 19 日
Yes, matlab is probably on its own in having implicit narrowing (lossy) conversion of numeric types. All other languages either only allow implicit widening conversion (no loss, narrowing conversion must be explicitly requested), or simply don't allow implicit conversions. See this nice explanation in the doc of Julia.
I believe I saw the reasoning behind mathworks decision somewhere but like many others of their decision I think it's bonkers.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by