Hi, by running this code, for 'val3-val1' it returns zero, would you please help me solve this weird problem?!
조회 수: 1 (최근 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
댓글 수: 0
채택된 답변
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
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
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!