image.process\feature\hash_quality_integral_16f.mbt
90.7% · 215 / 237 points · 658 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 图像哈希/质量/积分 16-bit/float 变体 Image hash/quality/integral 16-bit/float variants - 3
/// - 4
/// 16位哈希/质量/积分 dhash_16 / ssim_16 / integral_image_16 - 5
/// 16位/浮点哈希/质量/积分 16-bit/float hash/quality/integral - 6
// 图像哈希 + 图像质量 + 积分图像 16-bit/float 变体 - 7
- 8
// ========== 辅助函数 ========== - 9
- 10
///| - 11
fn read_u16_le_iq(data : Bytes, offset : Int32) -> Int32 { - 12●
data[offset].to_int() + data[offset + 1].to_int() * 256 - 13
} - 14
- 15
///| - 16
fn read_float_le_iq(data : Bytes, offset : Int32) -> Float { - 17●
let b0 = data[offset].to_int() - 18●
let b1 = data[offset + 1].to_int() - 19●
let b2 = data[offset + 2].to_int() - 20●
let b3 = data[offset + 3].to_int() - 21
let bits = b0 | (b1 << 8) | (b2 << 16) | (b3 << 24) - 22●
Float::reinterpret_from_int(bits) - 23
} - 24
- 25
///| - 26
fn img16_to_img8_iq(img : @types.Image16) -> @types.Image { - 27●
let w = img.width - 28
let h = img.height - 29
let ch = img.channels - 30●
let data8 : Array[Byte] = Array::make(w * h * ch, b'\x00') - 31
for i in 0..<(w * h * ch) { - 32●
let v16 = read_u16_le_iq(img.data, i * 2) - 33●
data8[i] = (v16 / 257).to_byte() - 34
} - 35
@types.Image::{ - 36
width: w, - 37
height: h, - 38
channels: ch, - 39●
data: Bytes::from_array(data8), - 40
} - 41
} - 42
- 43
///| - 44
fn imgf_to_img8_iq(img : @types.ImageF) -> @types.Image { - 45●
let w = img.width - 46
let h = img.height - 47
let ch = img.channels - 48●
let data8 : Array[Byte] = Array::make(w * h * ch, b'\x00') - 49
for i in 0..<(w * h * ch) { - 50●
let vf = read_float_le_iq(img.data, i * 4) - 51●
let v8 = @types.clamp_int((vf * 255.0F).to_int(), 0, 255) - 52●
data8[i] = v8.to_byte() - 53
} - 54
@types.Image::{ - 55
width: w, - 56
height: h, - 57
channels: ch, - 58●
data: Bytes::from_array(data8), - 59
} - 60
} - 61
- 62
// ========== 图像哈希 16-bit ========== - 63
- 64
///| - 65
/// 16-bit 平均哈希。 - 66
/// @see ahash 8-bit 版本,本函数为 Image16 变体 - 67
pub fn ahash_16(img : @types.Image16) -> Array[Int32] raise @types.LoadError { - 68
// 输入验证 - 69●
if img.width <= 0 || img.height <= 0 { - 70●
raise @types.LoadError::DecodeFailed("ahash_16: 图像尺寸必须大于0") - 71
} - 72
if img.channels < 1 || img.channels > 4 { - 73●
raise @types.LoadError::DecodeFailed( - 74
"ahash_16: 通道数必须在1-4之间", - 75
) - 76
} - 77
let expected_size = img.width * img.height * img.channels * 2 - 78●
if img.data.length() != expected_size { - 79●
raise @types.LoadError::DecodeFailed( - 80
"ahash_16: 数据大小不匹配,期望 " + - 81●
expected_size.to_string() + - 82
",实际 " + - 83●
img.data.length().to_string(), - 84
) - 85
} - 86
- 87●
let img8 = img16_to_img8_iq(img) - 88●
ahash(img8) - 89
} - 90
- 91
///| - 92
/// 16-bit 差异哈希。 - 93
/// @see dhash 8-bit 版本,本函数为 Image16 变体 - 94
pub fn dhash_16(img : @types.Image16) -> Array[Int32] raise @types.LoadError { - 95
// 输入验证 - 96●
if img.width <= 0 || img.height <= 0 { - 97●
raise @types.LoadError::DecodeFailed("dhash_16: 图像尺寸必须大于0") - 98
} - 99
if img.channels < 1 || img.channels > 4 { - 100●
raise @types.LoadError::DecodeFailed( - 101
"dhash_16: 通道数必须在1-4之间", - 102
) - 103
} - 104
let expected_size = img.width * img.height * img.channels * 2 - 105●
if img.data.length() != expected_size { - 106●
raise @types.LoadError::DecodeFailed( - 107
"dhash_16: 数据大小不匹配,期望 " + - 108●
expected_size.to_string() + - 109
",实际 " + - 110●
img.data.length().to_string(), - 111
) - 112
} - 113
- 114●
let img8 = img16_to_img8_iq(img) - 115●
dhash(img8) - 116
} - 117
- 118
///| - 119
/// 16-bit 感知哈希。 - 120
/// @see phash 8-bit 版本,本函数为 Image16 变体 - 121
pub fn phash_16(img : @types.Image16) -> Array[Int32] raise @types.LoadError { - 122
// 输入验证 - 123●
if img.width <= 0 || img.height <= 0 { - 124●
raise @types.LoadError::DecodeFailed("phash_16: 图像尺寸必须大于0") - 125
} - 126
if img.channels < 1 || img.channels > 4 { - 127●
raise @types.LoadError::DecodeFailed( - 128
"phash_16: 通道数必须在1-4之间", - 129
) - 130
} - 131
let expected_size = img.width * img.height * img.channels * 2 - 132●
if img.data.length() != expected_size { - 133●
raise @types.LoadError::DecodeFailed( - 134
"phash_16: 数据大小不匹配,期望 " + - 135●
expected_size.to_string() + - 136
",实际 " + - 137●
img.data.length().to_string(), - 138
) - 139
} - 140
- 141●
let img8 = img16_to_img8_iq(img) - 142●
phash(img8) - 143
} - 144
- 145
// ========== 图像哈希 float ========== - 146
- 147
///| - 148
/// float 平均哈希。 - 149
/// @see ahash 8-bit 版本,本函数为 ImageF 变体 - 150
pub fn ahash_f(img : @types.ImageF) -> Array[Int32] raise @types.LoadError { - 151
// 输入验证 - 152●
if img.width <= 0 || img.height <= 0 { - 153●
raise @types.LoadError::DecodeFailed("ahash_f: 图像尺寸必须大于0") - 154
} - 155
if img.channels < 1 || img.channels > 4 { - 156●
raise @types.LoadError::DecodeFailed("ahash_f: 通道数必须在1-4之间") - 157
} - 158
let expected_size = img.width * img.height * img.channels * 4 - 159●
if img.data.length() != expected_size { - 160●
raise @types.LoadError::DecodeFailed( - 161
"ahash_f: 数据大小不匹配,期望 " + - 162●
expected_size.to_string() + - 163
",实际 " + - 164●
img.data.length().to_string(), - 165
) - 166
} - 167
- 168●
let img8 = imgf_to_img8_iq(img) - 169●
ahash(img8) - 170
} - 171
- 172
///| - 173
/// float 差异哈希。 - 174
/// @see dhash 8-bit 版本,本函数为 ImageF 变体 - 175
pub fn dhash_f(img : @types.ImageF) -> Array[Int32] raise @types.LoadError { - 176
// 输入验证 - 177●
if img.width <= 0 || img.height <= 0 { - 178●
raise @types.LoadError::DecodeFailed("dhash_f: 图像尺寸必须大于0") - 179
} - 180
if img.channels < 1 || img.channels > 4 { - 181●
raise @types.LoadError::DecodeFailed("dhash_f: 通道数必须在1-4之间") - 182
} - 183
let expected_size = img.width * img.height * img.channels * 4 - 184●
if img.data.length() != expected_size { - 185●
raise @types.LoadError::DecodeFailed( - 186
"dhash_f: 数据大小不匹配,期望 " + - 187●
expected_size.to_string() + - 188
",实际 " + - 189●
img.data.length().to_string(), - 190
) - 191
} - 192
- 193●
let img8 = imgf_to_img8_iq(img) - 194●
dhash(img8) - 195
} - 196
- 197
///| - 198
/// float 感知哈希。 - 199
/// @see phash 8-bit 版本,本函数为 ImageF 变体 - 200
pub fn phash_f(img : @types.ImageF) -> Array[Int32] raise @types.LoadError { - 201
// 输入验证 - 202●
if img.width <= 0 || img.height <= 0 { - 203●
raise @types.LoadError::DecodeFailed("phash_f: 图像尺寸必须大于0") - 204
} - 205
if img.channels < 1 || img.channels > 4 { - 206●
raise @types.LoadError::DecodeFailed("phash_f: 通道数必须在1-4之间") - 207
} - 208
let expected_size = img.width * img.height * img.channels * 4 - 209●
if img.data.length() != expected_size { - 210●
raise @types.LoadError::DecodeFailed( - 211
"phash_f: 数据大小不匹配,期望 " + - 212●
expected_size.to_string() + - 213
",实际 " + - 214●
img.data.length().to_string(), - 215
) - 216
} - 217
- 218●
let img8 = imgf_to_img8_iq(img) - 219●
phash(img8) - 220
} - 221
- 222
// ========== 图像质量 16-bit ========== - 223
- 224
///| - 225
/// 16-bit 均方误差。 - 226
/// @see mse 8-bit 版本,本函数为 Image16 变体 - 227
pub fn mse_16( - 228
img1 : @types.Image16, - 229
img2 : @types.Image16, - 230
) -> Double raise @types.LoadError { - 231
// 输入验证 - 232●
if img1.width <= 0 || img1.height <= 0 { - 233●
raise @types.LoadError::DecodeFailed("mse_16: 图像1尺寸必须大于0") - 234
} - 235
if img1.channels < 1 || img1.channels > 4 { - 236●
raise @types.LoadError::DecodeFailed( - 237
"mse_16: 图像1通道数必须在1-4之间", - 238
) - 239
} - 240
let img1_expected_size = img1.width * img1.height * img1.channels * 2 - 241●
if img1.data.length() != img1_expected_size { - 242●
raise @types.LoadError::DecodeFailed( - 243
"mse_16: 图像1数据大小不匹配,期望 " + - 244●
img1_expected_size.to_string() + - 245
",实际 " + - 246●
img1.data.length().to_string(), - 247
) - 248
} - 249
if img2.width <= 0 || img2.height <= 0 { - 250●
raise @types.LoadError::DecodeFailed("mse_16: 图像2尺寸必须大于0") - 251
} - 252
if img2.channels < 1 || img2.channels > 4 { - 253○
raise @types.LoadError::DecodeFailed( - 254
"mse_16: 图像2通道数必须在1-4之间", - 255
) - 256
} - 257
let img2_expected_size = img2.width * img2.height * img2.channels * 2 - 258●
if img2.data.length() != img2_expected_size { - 259○
raise @types.LoadError::DecodeFailed( - 260
"mse_16: 图像2数据大小不匹配,期望 " + - 261○
img2_expected_size.to_string() + - 262
",实际 " + - 263○
img2.data.length().to_string(), - 264
) - 265
} - 266
if img1.width != img2.width || img1.height != img2.height { - 267●
raise @types.LoadError::DecodeFailed("mse_16: 两图像尺寸必须一致") - 268
} - 269
- 270●
let img1_8 = img16_to_img8_iq(img1) - 271●
let img2_8 = img16_to_img8_iq(img2) - 272●
mse(img1_8, img2_8) - 273
} - 274
- 275
///| - 276
/// 16-bit 峰值信噪比。 - 277
/// @see psnr 8-bit 版本,本函数为 Image16 变体 - 278
pub fn psnr_16( - 279
img1 : @types.Image16, - 280
img2 : @types.Image16, - 281
) -> Double raise @types.LoadError { - 282
// 输入验证 - 283●
if img1.width <= 0 || img1.height <= 0 { - 284●
raise @types.LoadError::DecodeFailed("psnr_16: 图像1尺寸必须大于0") - 285
} - 286
if img1.channels < 1 || img1.channels > 4 { - 287●
raise @types.LoadError::DecodeFailed( - 288
"psnr_16: 图像1通道数必须在1-4之间", - 289
) - 290
} - 291
let img1_expected_size = img1.width * img1.height * img1.channels * 2 - 292●
if img1.data.length() != img1_expected_size { - 293●
raise @types.LoadError::DecodeFailed( - 294
"psnr_16: 图像1数据大小不匹配,期望 " + - 295●
img1_expected_size.to_string() + - 296
",实际 " + - 297●
img1.data.length().to_string(), - 298
) - 299
} - 300
if img2.width <= 0 || img2.height <= 0 { - 301●
raise @types.LoadError::DecodeFailed("psnr_16: 图像2尺寸必须大于0") - 302
} - 303
if img2.channels < 1 || img2.channels > 4 { - 304○
raise @types.LoadError::DecodeFailed( - 305
"psnr_16: 图像2通道数必须在1-4之间", - 306
) - 307
} - 308
let img2_expected_size = img2.width * img2.height * img2.channels * 2 - 309●
if img2.data.length() != img2_expected_size { - 310●
raise @types.LoadError::DecodeFailed( - 311
"psnr_16: 图像2数据大小不匹配,期望 " + - 312●
img2_expected_size.to_string() + - 313
",实际 " + - 314●
img2.data.length().to_string(), - 315
) - 316
} - 317
if img1.width != img2.width || img1.height != img2.height { - 318●
raise @types.LoadError::DecodeFailed("psnr_16: 两图像尺寸必须一致") - 319
} - 320
- 321●
let img1_8 = img16_to_img8_iq(img1) - 322●
let img2_8 = img16_to_img8_iq(img2) - 323●
psnr(img1_8, img2_8) - 324
} - 325
- 326
///| - 327
/// 16-bit 结构相似性。 - 328
/// @see ssim 8-bit 版本,本函数为 Image16 变体 - 329
pub fn ssim_16( - 330
img1 : @types.Image16, - 331
img2 : @types.Image16, - 332
) -> Double raise @types.LoadError { - 333
// 输入验证 - 334●
if img1.width <= 0 || img1.height <= 0 { - 335●
raise @types.LoadError::DecodeFailed("ssim_16: 图像1尺寸必须大于0") - 336
} - 337
if img1.channels < 1 || img1.channels > 4 { - 338●
raise @types.LoadError::DecodeFailed( - 339
"ssim_16: 图像1通道数必须在1-4之间", - 340
) - 341
} - 342
let img1_expected_size = img1.width * img1.height * img1.channels * 2 - 343●
if img1.data.length() != img1_expected_size { - 344●
raise @types.LoadError::DecodeFailed( - 345
"ssim_16: 图像1数据大小不匹配,期望 " + - 346●
img1_expected_size.to_string() + - 347
",实际 " + - 348●
img1.data.length().to_string(), - 349
) - 350
} - 351
if img2.width <= 0 || img2.height <= 0 { - 352●
raise @types.LoadError::DecodeFailed("ssim_16: 图像2尺寸必须大于0") - 353
} - 354
if img2.channels < 1 || img2.channels > 4 { - 355○
raise @types.LoadError::DecodeFailed( - 356
"ssim_16: 图像2通道数必须在1-4之间", - 357
) - 358
} - 359
let img2_expected_size = img2.width * img2.height * img2.channels * 2 - 360●
if img2.data.length() != img2_expected_size { - 361○
raise @types.LoadError::DecodeFailed( - 362
"ssim_16: 图像2数据大小不匹配,期望 " + - 363○
img2_expected_size.to_string() + - 364
",实际 " + - 365○
img2.data.length().to_string(), - 366
) - 367
} - 368
if img1.width != img2.width || img1.height != img2.height { - 369●
raise @types.LoadError::DecodeFailed("ssim_16: 两图像尺寸必须一致") - 370
} - 371
- 372●
let img1_8 = img16_to_img8_iq(img1) - 373●
let img2_8 = img16_to_img8_iq(img2) - 374●
ssim(img1_8, img2_8) - 375
} - 376
- 377
// ========== 图像质量 float ========== - 378
- 379
///| - 380
/// float 均方误差。 - 381
/// @see mse 8-bit 版本,本函数为 ImageF 变体 - 382
pub fn mse_f( - 383
img1 : @types.ImageF, - 384
img2 : @types.ImageF, - 385
) -> Double raise @types.LoadError { - 386
// 输入验证 - 387●
if img1.width <= 0 || img1.height <= 0 { - 388●
raise @types.LoadError::DecodeFailed("mse_f: 图像1尺寸必须大于0") - 389
} - 390
if img1.channels < 1 || img1.channels > 4 { - 391●
raise @types.LoadError::DecodeFailed( - 392
"mse_f: 图像1通道数必须在1-4之间", - 393
) - 394
} - 395
let img1_expected_size = img1.width * img1.height * img1.channels * 4 - 396●
if img1.data.length() != img1_expected_size { - 397●
raise @types.LoadError::DecodeFailed( - 398
"mse_f: 图像1数据大小不匹配,期望 " + - 399●
img1_expected_size.to_string() + - 400
",实际 " + - 401●
img1.data.length().to_string(), - 402
) - 403
} - 404
if img2.width <= 0 || img2.height <= 0 { - 405●
raise @types.LoadError::DecodeFailed("mse_f: 图像2尺寸必须大于0") - 406
} - 407
if img2.channels < 1 || img2.channels > 4 { - 408○
raise @types.LoadError::DecodeFailed( - 409
"mse_f: 图像2通道数必须在1-4之间", - 410
) - 411
} - 412
let img2_expected_size = img2.width * img2.height * img2.channels * 4 - 413●
if img2.data.length() != img2_expected_size { - 414●
raise @types.LoadError::DecodeFailed( - 415
"mse_f: 图像2数据大小不匹配,期望 " + - 416●
img2_expected_size.to_string() + - 417
",实际 " + - 418●
img2.data.length().to_string(), - 419
) - 420
} - 421
if img1.width != img2.width || img1.height != img2.height { - 422●
raise @types.LoadError::DecodeFailed("mse_f: 两图像尺寸必须一致") - 423
} - 424
- 425●
let img1_8 = imgf_to_img8_iq(img1) - 426●
let img2_8 = imgf_to_img8_iq(img2) - 427●
mse(img1_8, img2_8) - 428
} - 429
- 430
///| - 431
/// float 峰值信噪比。 - 432
/// @see psnr 8-bit 版本,本函数为 ImageF 变体 - 433
pub fn psnr_f( - 434
img1 : @types.ImageF, - 435
img2 : @types.ImageF, - 436
) -> Double raise @types.LoadError { - 437
// 输入验证 - 438●
if img1.width <= 0 || img1.height <= 0 { - 439●
raise @types.LoadError::DecodeFailed("psnr_f: 图像1尺寸必须大于0") - 440
} - 441
if img1.channels < 1 || img1.channels > 4 { - 442●
raise @types.LoadError::DecodeFailed( - 443
"psnr_f: 图像1通道数必须在1-4之间", - 444
) - 445
} - 446
let img1_expected_size = img1.width * img1.height * img1.channels * 4 - 447●
if img1.data.length() != img1_expected_size { - 448●
raise @types.LoadError::DecodeFailed( - 449
"psnr_f: 图像1数据大小不匹配,期望 " + - 450●
img1_expected_size.to_string() + - 451
",实际 " + - 452●
img1.data.length().to_string(), - 453
) - 454
} - 455
if img2.width <= 0 || img2.height <= 0 { - 456●
raise @types.LoadError::DecodeFailed("psnr_f: 图像2尺寸必须大于0") - 457
} - 458
if img2.channels < 1 || img2.channels > 4 { - 459○
raise @types.LoadError::DecodeFailed( - 460
"psnr_f: 图像2通道数必须在1-4之间", - 461
) - 462
} - 463
let img2_expected_size = img2.width * img2.height * img2.channels * 4 - 464●
if img2.data.length() != img2_expected_size { - 465○
raise @types.LoadError::DecodeFailed( - 466
"psnr_f: 图像2数据大小不匹配,期望 " + - 467○
img2_expected_size.to_string() + - 468
",实际 " + - 469○
img2.data.length().to_string(), - 470
) - 471
} - 472
if img1.width != img2.width || img1.height != img2.height { - 473●
raise @types.LoadError::DecodeFailed("psnr_f: 两图像尺寸必须一致") - 474
} - 475
- 476●
let img1_8 = imgf_to_img8_iq(img1) - 477●
let img2_8 = imgf_to_img8_iq(img2) - 478●
psnr(img1_8, img2_8) - 479
} - 480
- 481
///| - 482
/// float 结构相似性。 - 483
/// @see ssim 8-bit 版本,本函数为 ImageF 变体 - 484
pub fn ssim_f( - 485
img1 : @types.ImageF, - 486
img2 : @types.ImageF, - 487
) -> Double raise @types.LoadError { - 488
// 输入验证 - 489●
if img1.width <= 0 || img1.height <= 0 { - 490●
raise @types.LoadError::DecodeFailed("ssim_f: 图像1尺寸必须大于0") - 491
} - 492
if img1.channels < 1 || img1.channels > 4 { - 493●
raise @types.LoadError::DecodeFailed( - 494
"ssim_f: 图像1通道数必须在1-4之间", - 495
) - 496
} - 497
let img1_expected_size = img1.width * img1.height * img1.channels * 4 - 498●
if img1.data.length() != img1_expected_size { - 499●
raise @types.LoadError::DecodeFailed( - 500
"ssim_f: 图像1数据大小不匹配,期望 " + - 501●
img1_expected_size.to_string() + - 502
",实际 " + - 503●
img1.data.length().to_string(), - 504
) - 505
} - 506
if img2.width <= 0 || img2.height <= 0 { - 507●
raise @types.LoadError::DecodeFailed("ssim_f: 图像2尺寸必须大于0") - 508
} - 509
if img2.channels < 1 || img2.channels > 4 { - 510○
raise @types.LoadError::DecodeFailed( - 511
"ssim_f: 图像2通道数必须在1-4之间", - 512
) - 513
} - 514
let img2_expected_size = img2.width * img2.height * img2.channels * 4 - 515●
if img2.data.length() != img2_expected_size { - 516○
raise @types.LoadError::DecodeFailed( - 517
"ssim_f: 图像2数据大小不匹配,期望 " + - 518○
img2_expected_size.to_string() + - 519
",实际 " + - 520○
img2.data.length().to_string(), - 521
) - 522
} - 523
if img1.width != img2.width || img1.height != img2.height { - 524●
raise @types.LoadError::DecodeFailed("ssim_f: 两图像尺寸必须一致") - 525
} - 526
- 527●
let img1_8 = imgf_to_img8_iq(img1) - 528●
let img2_8 = imgf_to_img8_iq(img2) - 529●
ssim(img1_8, img2_8) - 530
} - 531
- 532
// ========== 积分图像 16-bit ========== - 533
- 534
///| - 535
/// 16-bit 积分图像。 - 536
/// @see integral_image 8-bit 版本,本函数为 Image16 变体 - 537
pub fn integral_image_16( - 538
img : @types.Image16, - 539
) -> IntegralImage raise @types.LoadError { - 540
// 输入验证 - 541●
if img.width <= 0 || img.height <= 0 { - 542●
raise @types.LoadError::DecodeFailed( - 543
"integral_image_16: 图像尺寸必须大于0", - 544
) - 545
} - 546
if img.channels < 1 || img.channels > 4 { - 547●
raise @types.LoadError::DecodeFailed( - 548
"integral_image_16: 通道数必须在1-4之间", - 549
) - 550
} - 551
let expected_size = img.width * img.height * img.channels * 2 - 552●
if img.data.length() != expected_size { - 553●
raise @types.LoadError::DecodeFailed( - 554
"integral_image_16: 数据大小不匹配,期望 " + - 555●
expected_size.to_string() + - 556
",实际 " + - 557●
img.data.length().to_string(), - 558
) - 559
} - 560
- 561●
let img8 = img16_to_img8_iq(img) - 562●
integral_image(img8) - 563
} - 564
- 565
///| - 566
/// 16-bit 平方积分图像。 - 567
/// @see integral_image_sq 8-bit 版本,本函数为 Image16 变体 - 568
pub fn integral_image_sq_16( - 569
img : @types.Image16, - 570
) -> IntegralImageSq raise @types.LoadError { - 571
// 输入验证 - 572●
if img.width <= 0 || img.height <= 0 { - 573●
raise @types.LoadError::DecodeFailed( - 574
"integral_image_sq_16: 图像尺寸必须大于0", - 575
) - 576
} - 577
if img.channels < 1 || img.channels > 4 { - 578●
raise @types.LoadError::DecodeFailed( - 579
"integral_image_sq_16: 通道数必须在1-4之间", - 580
) - 581
} - 582
let expected_size = img.width * img.height * img.channels * 2 - 583●
if img.data.length() != expected_size { - 584●
raise @types.LoadError::DecodeFailed( - 585
"integral_image_sq_16: 数据大小不匹配,期望 " + - 586●
expected_size.to_string() + - 587
",实际 " + - 588●
img.data.length().to_string(), - 589
) - 590
} - 591
- 592●
let img8 = img16_to_img8_iq(img) - 593●
integral_image_sq(img8) - 594
} - 595
- 596
// ========== 积分图像 float ========== - 597
- 598
///| - 599
/// float 积分图像。 - 600
/// @see integral_image 8-bit 版本,本函数为 ImageF 变体 - 601
pub fn integral_image_f( - 602
img : @types.ImageF, - 603
) -> IntegralImage raise @types.LoadError { - 604
// 输入验证 - 605●
if img.width <= 0 || img.height <= 0 { - 606●
raise @types.LoadError::DecodeFailed( - 607
"integral_image_f: 图像尺寸必须大于0", - 608
) - 609
} - 610
if img.channels < 1 || img.channels > 4 { - 611●
raise @types.LoadError::DecodeFailed( - 612
"integral_image_f: 通道数必须在1-4之间", - 613
) - 614
} - 615
let expected_size = img.width * img.height * img.channels * 4 - 616●
if img.data.length() != expected_size { - 617●
raise @types.LoadError::DecodeFailed( - 618
"integral_image_f: 数据大小不匹配,期望 " + - 619●
expected_size.to_string() + - 620
",实际 " + - 621●
img.data.length().to_string(), - 622
) - 623
} - 624
- 625●
let img8 = imgf_to_img8_iq(img) - 626●
integral_image(img8) - 627
} - 628
- 629
///| - 630
/// float 平方积分图像。 - 631
/// @see integral_image_sq 8-bit 版本,本函数为 ImageF 变体 - 632
pub fn integral_image_sq_f( - 633
img : @types.ImageF, - 634
) -> IntegralImageSq raise @types.LoadError { - 635
// 输入验证 - 636●
if img.width <= 0 || img.height <= 0 { - 637●
raise @types.LoadError::DecodeFailed( - 638
"integral_image_sq_f: 图像尺寸必须大于0", - 639
) - 640
} - 641
if img.channels < 1 || img.channels > 4 { - 642●
raise @types.LoadError::DecodeFailed( - 643
"integral_image_sq_f: 通道数必须在1-4之间", - 644
) - 645
} - 646
let expected_size = img.width * img.height * img.channels * 4 - 647●
if img.data.length() != expected_size { - 648●
raise @types.LoadError::DecodeFailed( - 649
"integral_image_sq_f: 数据大小不匹配,期望 " + - 650●
expected_size.to_string() + - 651
",实际 " + - 652●
img.data.length().to_string(), - 653
) - 654
} - 655
- 656●
let img8 = imgf_to_img8_iq(img) - 657●
integral_image_sq(img8) - 658
}