Hi, by running this code, for 'val3-val1' it returns zero, would you please help me solve this weird problem?!

3 ビュー (過去 30 日間)
xdd=-4.5 ydd=-4.5
xmid=6 ymid=6
xd=xdd+xmid; yd=ydd+ymid;
A=imread('1.tiff')
xd1=floor(xd); xd2=ceil(xd); yd1=floor(yd); yd2=ceil(yd);
val1=A(xd1,yd1) val2=A(xd2,yd1) val3=A(xd1,yd2) val4=A(xd2,yd2)
xd_abs=abs(xd) yd_abs=abs(yd)
xd_fract=xd_abs-floor(xd_abs) yd_fract=xd_abs-floor(xd_abs)
new_row0 = ((val3 - val1) * xd_fract) + val1 new_row1 = ((val4 - val2) * xd_fract) + val2
new_pxl_val =((new_row1 - new_row0) * yd_fract) + new_row0
where A =
253 203 187 186 230 251 225 228 250 254 253
243 145 164 141 184 246 206 212 240 255 252
243 152 167 147 190 243 192 197 235 255 252
249 122 98 90 189 225 179 218 230 253 253
248 127 110 102 189 231 196 217 226 252 253
248 126 109 97 182 248 218 231 234 255 252
248 126 109 97 184 238 216 217 206 255 252
248 126 108 100 187 254 240 239 228 255 252
248 128 110 101 189 247 223 244 239 255 252
248 121 102 92 185 247 223 229 221 255 251
250 159 144 138 203 255 250 240 237 254 252
val1 =
253
val3 =
203
val3-val1
ans =
0

採用された回答

Star Strider
Star Strider 2014 年 7 月 25 日
Check the type of integers you have. If they are unsigned integers (as they would be for images), no negative values exist by definition. All operations that evaluate to <0 will evaluate to zero. You have to cast them as int16 or double if you want negative values.
  1 件のコメント
Star Strider
Star Strider 2014 年 8 月 24 日
Nika Commented:
Thanks, everything was due to variable types, I changed to double so now it's working.
----------
My pleasure!

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

その他の回答 (1 件)

Ben11
Ben11 2014 年 7 月 25 日
編集済み: Ben11 2014 年 7 月 25 日
When I run your code I get -50. Did you do a clear before running the code? Here is what I used:
clear
clc
A = [253 203 187 186 230 251 225 228 250 254 253
243 145 164 141 184 246 206 212 240 255 252
243 152 167 147 190 243 192 197 235 255 252
249 122 98 90 189 225 179 218 230 253 253
248 127 110 102 189 231 196 217 226 252 253
248 126 109 97 182 248 218 231 234 255 252
248 126 109 97 184 238 216 217 206 255 252
248 126 108 100 187 254 240 239 228 255 252
248 128 110 101 189 247 223 244 239 255 252
248 121 102 92 185 247 223 229 221 255 251
250 159 144 138 203 255 250 240 237 254 252];
xdd=-4.5 ;
ydd=-4.5;
xmid=6;
ymid=6;
xd=xdd+xmid;
yd=ydd+ymid;
xd1=floor(xd); xd2=ceil(xd); yd1=floor(yd); yd2=ceil(yd);
val1=A(xd1,yd1);
val2=A(xd2,yd1);
val3=A(xd1,yd2);
val4=A(xd2,yd2);
xd_abs=abs(xd);
yd_abs=abs(yd);
xd_fract=xd_abs-floor(xd_abs);
yd_fract=xd_abs-floor(xd_abs);
new_row0 = ((val3 - val1) * xd_fract) + val1;
new_row1 = ((val4 - val2) * xd_fract) + val2;
new_pxl_val =((new_row1 - new_row0) * yd_fract) + new_row0;
val3 - val1
ans =
-50
  1 件のコメント
Nika
Nika 2014 年 8 月 24 日
Thanks, everything was due to variable types, I changed to double so now it's working.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by