image.domain\remote_sensing\remote_sensing_enhancement.mbt

86.5% · 148 / 171 points · 719 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # 遥感增强 remote_sensing/remote_sensing_enhancement
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 遥感图像增强(v20.0.0)
  7. 7// 遥感图像处理、地物分类、变化检测、植被指数、光谱分析
  8. 8
  9. 9///|
  10. 10/// 遥感图像类型
  11. 11/// `#non_exhaustive` 表示未来可能添加新构造器
  12. 12#derive(Eq, @debug.Debug)
  13. 13#non_exhaustive
  14. 14pub(all) enum RemoteSensingImageType {
  15. 15 Optical
  16. 16 Multispectral
  17. 17 Hyperspectral
  18. 18 SAR
  19. 19 Thermal
  20. 20 LiDAR
  21. 21 Unknown
  22. 22}
  23. 23
  24. 24///|
  25. 25pub extend RemoteSensingImageType with Eq::{not_equal, equal}
  26. 26
  27. 27///|
  28. 28pub extend RemoteSensingImageType with @debug.Debug::{to_repr}
  29. 29
  30. 30///|
  31. 31/// 遥感图像
  32. 32pub(all) struct RemoteSensingImage {
  33. 33 width : Int32
  34. 34 height : Int32
  35. 35 bands : Int32
  36. 36 data : Array[Double]
  37. 37 image_type : RemoteSensingImageType
  38. 38 wavelength : Array[Double] // 每个波段的波长(nm)
  39. 39 resolution : Double // 空间分辨率(米)
  40. 40 acquisition_date : String
  41. 41 cloud_cover : Double // 云量百分比
  42. 42}
  43. 43
  44. 44///|
  45. 45/// 地物类别
  46. 46/// `#non_exhaustive` 表示未来可能添加新构造器
  47. 47#derive(Eq, @debug.Debug)
  48. 48#non_exhaustive
  49. 49pub(all) enum LandCoverClass {
  50. 50 Water
  51. 51 Forest
  52. 52 Grassland
  53. 53 Cropland
  54. 54 Urban
  55. 55 Barren
  56. 56 Wetland
  57. 57 Snow
  58. 58 Cloud
  59. 59 Shadow
  60. 60 Unknown
  61. 61}
  62. 62
  63. 63///|
  64. 64pub extend LandCoverClass with Eq::{not_equal, equal}
  65. 65
  66. 66///|
  67. 67pub extend LandCoverClass with @debug.Debug::{to_repr}
  68. 68
  69. 69///|
  70. 70/// 分类结果
  71. 71#derive(Eq, Default, @debug.Debug)
  72. 72pub(all) struct ClassificationResult {
  73. 73 width : Int32
  74. 74 height : Int32
  75. 75 labels : Array[Int32]
  76. 76 class_names : Array[String]
  77. 77 class_colors : Array[(Int32, Int32, Int32)]
  78. 78 num_classes : Int32
  79. 79 overall_accuracy : Double
  80. 80 kappa_coefficient : Double
  81. 81}
  82. 82
  83. 83///|
  84. 84pub extend ClassificationResult with @debug.Debug::{to_repr}
  85. 85
  86. 86///|
  87. 87pub extend ClassificationResult with Eq::{not_equal, equal}
  88. 88
  89. 89///|
  90. 90pub extend ClassificationResult with Default::{default}
  91. 91
  92. 92///|
  93. 93/// 变化检测结果
  94. 94#derive(Eq, Default, @debug.Debug)
  95. 95pub(all) struct ChangeDetectionResult {
  96. 96 width : Int32
  97. 97 height : Int32
  98. 98 change_mask : Array[Bool]
  99. 99 change_percentage : Double
  100. 100 num_changed_pixels : Int32
  101. 101 change_intensity : Array[Double]
  102. 102 threshold : Double
  103. 103}
  104. 104
  105. 105///|
  106. 106pub extend ChangeDetectionResult with @debug.Debug::{to_repr}
  107. 107
  108. 108///|
  109. 109pub extend ChangeDetectionResult with Eq::{not_equal, equal}
  110. 110
  111. 111///|
  112. 112pub extend ChangeDetectionResult with Default::{default}
  113. 113
  114. 114///|
  115. 115/// 植被指数
  116. 116#derive(Eq, Default, @debug.Debug)
  117. 117pub(all) struct VegetationIndices {
  118. 118 ndvi : Array[Double] // 归一化植被指数
  119. 119 ndwi : Array[Double] // 归一化水体指数
  120. 120 ndbi : Array[Double] // 归一化建筑指数
  121. 121 evi : Array[Double] // 增强植被指数
  122. 122 savi : Array[Double] // 土壤调整植被指数
  123. 123 msavi : Array[Double] // 修正土壤调整植被指数
  124. 124}
  125. 125
  126. 126///|
  127. 127pub extend VegetationIndices with @debug.Debug::{to_repr}
  128. 128
  129. 129///|
  130. 130pub extend VegetationIndices with Eq::{not_equal, equal}
  131. 131
  132. 132///|
  133. 133pub extend VegetationIndices with Default::{default}
  134. 134
  135. 135///|
  136. 136/// 光谱特征
  137. 137#derive(Eq, Default, @debug.Debug)
  138. 138pub(all) struct SpectralSignature {
  139. 139 wavelengths : Array[Double]
  140. 140 reflectance : Array[Double]
  141. 141 num_bands : Int32
  142. 142 mean_reflectance : Double
  143. 143 std_reflectance : Double
  144. 144 absorption_features : Array[(Double, Double)] // (波长, 深度)
  145. 145}
  146. 146
  147. 147///|
  148. 148pub extend SpectralSignature with @debug.Debug::{to_repr}
  149. 149
  150. 150///|
  151. 151pub extend SpectralSignature with Eq::{not_equal, equal}
  152. 152
  153. 153///|
  154. 154pub extend SpectralSignature with Default::{default}
  155. 155
  156. 156///|
  157. 157/// 纹理特征
  158. 158#derive(Eq, Default, @debug.Debug)
  159. 159pub(all) struct TextureFeatures {
  160. 160 contrast : Double
  161. 161 homogeneity : Double
  162. 162 energy : Double
  163. 163 correlation : Double
  164. 164 entropy : Double
  165. 165 variance : Double
  166. 166 dissimilarity : Double
  167. 167}
  168. 168
  169. 169///|
  170. 170pub extend TextureFeatures with @debug.Debug::{to_repr}
  171. 171
  172. 172///|
  173. 173pub extend TextureFeatures with Eq::{not_equal, equal}
  174. 174
  175. 175///|
  176. 176pub extend TextureFeatures with Default::{default}
  177. 177
  178. 178///|
  179. 179/// 遥感图像质量
  180. 180#derive(Eq, Default, @debug.Debug)
  181. 181pub(all) struct RemoteSensingQuality {
  182. 182 snr : Double
  183. 183 cloud_cover : Double
  184. 184 geometric_accuracy : Double
  185. 185 radiometric_accuracy : Double
  186. 186 overall_quality : Double
  187. 187}
  188. 188
  189. 189///|
  190. 190pub extend RemoteSensingQuality with @debug.Debug::{to_repr}
  191. 191
  192. 192///|
  193. 193pub extend RemoteSensingQuality with Eq::{not_equal, equal}
  194. 194
  195. 195///|
  196. 196pub extend RemoteSensingQuality with Default::{default}
  197. 197
  198. 198///|
  199. 199/// 创建默认遥感图像
  200. 200pub fn create_default_remote_sensing_image(
  201. 201 width : Int32,
  202. 202 height : Int32,
  203. 203 bands : Int32,
  204. 204) -> RemoteSensingImage {
  205. 205● let data : Array[Double] = []
  206. 206 let wavelength : Array[Double] = []
  207. 207 for _ in 0..<(width * height * bands) {
  208. 208● data.push(0.0)
  209. 209 }
  210. 210 for i in 0..<bands {
  211. 211● wavelength.push(400.0 + i.to_double() * 100.0)
  212. 212 }
  213. 213 RemoteSensingImage::{
  214. 214 width,
  215. 215 height,
  216. 216 bands,
  217. 217 data,
  218. 218 image_type: RemoteSensingImageType::Multispectral,
  219. 219 wavelength,
  220. 220 resolution: 10.0,
  221. 221 acquisition_date: "2024-01-01",
  222. 222 cloud_cover: 0.0,
  223. 223 }
  224. 224}
  225. 225
  226. 226///|
  227. 227/// 计算 NDVI(归一化植被指数)
  228. 228pub fn calculate_ndvi(
  229. 229 image : RemoteSensingImage,
  230. 230 red_band : Int32,
  231. 231 nir_band : Int32,
  232. 232) -> Array[Double] {
  233. 233● let w = image.width
  234. 234 let h = image.height
  235. 235 let total = w * h
  236. 236 let ndvi : Array[Double] = []
  237. 237
  238. 238 for i in 0..<total {
  239. 239● let red = image.data[i * image.bands + red_band]
  240. 240 let nir = image.data[i * image.bands + nir_band]
  241. 241 let denominator = nir + red
  242. 242 if denominator > 0.001 {
  243. 243● ndvi.push((nir - red) / denominator)
  244. 244 } else {
  245. 245● ndvi.push(0.0)
  246. 246 }
  247. 247 }
  248. 248
  249. 249 ndvi
  250. 250}
  251. 251
  252. 252///|
  253. 253/// 计算 NDWI(归一化水体指数)
  254. 254pub fn calculate_ndwi(
  255. 255 image : RemoteSensingImage,
  256. 256 green_band : Int32,
  257. 257 nir_band : Int32,
  258. 258) -> Array[Double] {
  259. 259● let w = image.width
  260. 260 let h = image.height
  261. 261 let total = w * h
  262. 262 let ndwi : Array[Double] = []
  263. 263
  264. 264 for i in 0..<total {
  265. 265● let green = image.data[i * image.bands + green_band]
  266. 266 let nir = image.data[i * image.bands + nir_band]
  267. 267 let denominator = nir + green
  268. 268 if denominator > 0.001 {
  269. 269● ndwi.push((green - nir) / denominator)
  270. 270 } else {
  271. 271● ndwi.push(0.0)
  272. 272 }
  273. 273 }
  274. 274
  275. 275 ndwi
  276. 276}
  277. 277
  278. 278///|
  279. 279/// 计算 NDBI(归一化建筑指数)
  280. 280pub fn calculate_ndbi(
  281. 281 image : RemoteSensingImage,
  282. 282 swir_band : Int32,
  283. 283 nir_band : Int32,
  284. 284) -> Array[Double] {
  285. 285● let w = image.width
  286. 286 let h = image.height
  287. 287 let total = w * h
  288. 288 let ndbi : Array[Double] = []
  289. 289
  290. 290 for i in 0..<total {
  291. 291● let swir = image.data[i * image.bands + swir_band]
  292. 292 let nir = image.data[i * image.bands + nir_band]
  293. 293 let denominator = swir + nir
  294. 294 if denominator > 0.001 {
  295. 295● ndbi.push((swir - nir) / denominator)
  296. 296 } else {
  297. 297● ndbi.push(0.0)
  298. 298 }
  299. 299 }
  300. 300
  301. 301 ndbi
  302. 302}
  303. 303
  304. 304///|
  305. 305/// 计算所有植被指数
  306. 306pub fn calculate_all_vegetation_indices(
  307. 307 image : RemoteSensingImage,
  308. 308) -> VegetationIndices {
  309. 309● let ndvi = if image.bands > 4 { calculate_ndvi(image, 2, 3) } else { [] }
  310. 310● let ndwi = if image.bands > 4 { calculate_ndwi(image, 1, 3) } else { [] }
  311. 311● let ndbi = if image.bands > 5 { calculate_ndbi(image, 4, 3) } else { [] }
  312. 312
  313. 313 VegetationIndices::{ ndvi, ndwi, ndbi, evi: ndvi, savi: ndvi, msavi: ndvi, }
  314. 314}
  315. 315
  316. 316///|
  317. 317/// 简单地物分类(基于光谱指数的决策树)
  318. 318pub fn classify_land_cover_simple(
  319. 319 image : RemoteSensingImage,
  320. 320) -> ClassificationResult {
  321. 321● let w = image.width
  322. 322 let h = image.height
  323. 323 let total = w * h
  324. 324 let labels : Array[Int32] = []
  325. 325
  326. 326● let ndvi = if image.bands > 4 { calculate_ndvi(image, 2, 3) } else { [] }
  327. 327● let ndwi = if image.bands > 4 { calculate_ndwi(image, 1, 3) } else { [] }
  328. 328
  329. 329 for i in 0..<total {
  330. 330● let mut label = 10 // Unknown
  331. 331● if ndvi.length() > 0 && ndwi.length() > 0 {
  332. 332● let n = ndvi[i]
  333. 333 let w_idx = ndwi[i]
  334. 334 if w_idx > 0.3 {
  335. 335○ label = 0 // Water
  336. 336● } else if n > 0.6 {
  337. 337○ label = 1 // Forest
  338. 338● } else if n > 0.3 {
  339. 339○ label = 2 // Grassland
  340. 340● } else if n > 0.1 {
  341. 341○ label = 3 // Cropland
  342. 342● } else if n < -0.1 {
  343. 343● label = 4 // Urban
  344. 344 } else {
  345. 345● label = 5 // Barren
  346. 346 }
  347. 347 }
  348. 348● labels.push(label)
  349. 349 }
  350. 350
  351. 351 let class_names : Array[String] = [
  352. 352 "Water", "Forest", "Grassland", "Cropland", "Urban", "Barren", "Wetland", "Snow",
  353. 353 "Cloud", "Shadow", "Unknown",
  354. 354 ]
  355. 355 let class_colors : Array[(Int32, Int32, Int32)] = [
  356. 356 (0, 0, 255),
  357. 357 (0, 128, 0),
  358. 358 (128, 255, 0),
  359. 359 (255, 255, 0),
  360. 360 (255, 0, 0),
  361. 361 (128, 128, 128),
  362. 362 (0, 255, 255),
  363. 363 (255, 255, 255),
  364. 364 (200, 200, 200),
  365. 365 (50, 50, 50),
  366. 366 (0, 0, 0),
  367. 367 ]
  368. 368
  369. 369 ClassificationResult::{
  370. 370 width: w,
  371. 371 height: h,
  372. 372 labels,
  373. 373 class_names,
  374. 374 class_colors,
  375. 375 num_classes: 11,
  376. 376 overall_accuracy: 0.0,
  377. 377 kappa_coefficient: 0.0,
  378. 378 }
  379. 379}
  380. 380
  381. 381///|
  382. 382/// 变化检测(基于图像差值)
  383. 383pub fn detect_changes_simple(
  384. 384 image1 : RemoteSensingImage,
  385. 385 image2 : RemoteSensingImage,
  386. 386 threshold : Double,
  387. 387) -> ChangeDetectionResult {
  388. 388● let w = image1.width
  389. 389 let h = image1.height
  390. 390 let total = w * h
  391. 391 let change_mask : Array[Bool] = []
  392. 392 let change_intensity : Array[Double] = []
  393. 393 let mut num_changed = 0
  394. 394
  395. 395 for i in 0..<total {
  396. 396● let mut sum_diff = 0.0
  397. 397 for b in 0..<image1.bands {
  398. 398● let idx = i * image1.bands + b
  399. 399● if idx < image1.data.length() && idx < image2.data.length() {
  400. 400● let diff = image1.data[idx] - image2.data[idx]
  401. 401 sum_diff += diff * diff
  402. 402 }
  403. 403 }
  404. 404 let intensity = if image1.bands > 0 {
  405. 405● (sum_diff / image1.bands.to_double()).sqrt()
  406. 406 } else {
  407. 407○ 0.0
  408. 408 }
  409. 409● change_intensity.push(intensity)
  410. 410 let changed = intensity > threshold
  411. 411● change_mask.push(changed)
  412. 412 if changed {
  413. 413● num_changed += 1
  414. 414 }
  415. 415 }
  416. 416
  417. 417 let change_percentage = if total > 0 {
  418. 418● num_changed.to_double() / total.to_double() * 100.0
  419. 419 } else {
  420. 420○ 0.0
  421. 421 }
  422. 422
  423. 423 ChangeDetectionResult::{
  424. 424 width: w,
  425. 425 height: h,
  426. 426 change_mask,
  427. 427 change_percentage,
  428. 428 num_changed_pixels: num_changed,
  429. 429 change_intensity,
  430. 430 threshold,
  431. 431 }
  432. 432}
  433. 433
  434. 434///|
  435. 435/// 计算纹理特征(基于灰度共生矩阵简化版)
  436. 436pub fn calculate_texture_features(
  437. 437 image : @types.Image,
  438. 438 x : Int32,
  439. 439 y : Int32,
  440. 440 window_size : Int32,
  441. 441) -> TextureFeatures raise @types.LoadError {
  442. 442 // 输入验证
  443. 443● if image.width <= 0 || image.height <= 0 {
  444. 444● raise @types.LoadError::DecodeFailed(
  445. 445 "calculate_texture_features: 图像尺寸必须大于0",
  446. 446 )
  447. 447 }
  448. 448 if image.channels < 1 || image.channels > 4 {
  449. 449● raise @types.LoadError::DecodeFailed(
  450. 450 "calculate_texture_features: 通道数必须在1-4之间",
  451. 451 )
  452. 452 }
  453. 453 let expected_size = image.width * image.height * image.channels
  454. 454● if image.data.length() != expected_size {
  455. 455● raise @types.LoadError::DecodeFailed(
  456. 456 "calculate_texture_features: 数据大小不匹配",
  457. 457 )
  458. 458 }
  459. 459 let w = image.width
  460. 460 let h = image.height
  461. 461 let half = window_size / 2
  462. 462 let mut sum = 0.0
  463. 463 let mut sum_sq = 0.0
  464. 464 let mut count = 0
  465. 465 let histogram : Array[Int32] = []
  466. 466 for _ in 0..<256 {
  467. 467● histogram.push(0)
  468. 468 }
  469. 469
  470. 470 for dy in -half..<(half + 1) {
  471. 471● for dx in -half..<(half + 1) {
  472. 472● let nx = x + dx
  473. 473 let ny = y + dy
  474. 474 if nx >= 0 && nx < w && ny >= 0 && ny < h {
  475. 475● let pixel = image.data[ny * w + nx].to_double()
  476. 476 sum += pixel
  477. 477 sum_sq += pixel * pixel
  478. 478 count += 1
  479. 479● histogram[pixel.to_int()] += 1
  480. 480 }
  481. 481 }
  482. 482 }
  483. 483
  484. 484● let mean = if count > 0 { sum / count.to_double() } else { 0.0 }
  485. 485 let variance = if count > 0 {
  486. 486● sum_sq / count.to_double() - mean * mean
  487. 487 } else {
  488. 488● 0.0
  489. 489 }
  490. 490
  491. 491 // 计算熵
  492. 492 let mut entropy = 0.0
  493. 493 for i in 0..<256 {
  494. 494● if histogram[i] > 0 && count > 0 {
  495. 495● let p = histogram[i].to_double() / count.to_double()
  496. 496 entropy -= p * (p * 10.0)
  497. 497 }
  498. 498 }
  499. 499
  500. 500 // 简化的对比度、同质性、能量、相关性
  501. 501 let contrast = variance
  502. 502● let homogeneity = if variance > 0.0 { 1.0 / (1.0 + variance) } else { 1.0 }
  503. 503 let energy = if count > 0 {
  504. 504● let mut e = 0.0
  505. 505 for i in 0..<256 {
  506. 506● let p = histogram[i].to_double() / count.to_double()
  507. 507 e += p * p
  508. 508 }
  509. 509 e
  510. 510 } else {
  511. 511● 0.0
  512. 512 }
  513. 513 let correlation = 0.5
  514. 514● let dissimilarity = variance.sqrt()
  515. 515
  516. 516 TextureFeatures::{
  517. 517 contrast,
  518. 518 homogeneity,
  519. 519 energy,
  520. 520 correlation,
  521. 521 entropy,
  522. 522 variance,
  523. 523 dissimilarity,
  524. 524 }
  525. 525}
  526. 526
  527. 527///|
  528. 528/// 计算光谱特征
  529. 529pub fn calculate_spectral_signature(
  530. 530 image : RemoteSensingImage,
  531. 531 x : Int32,
  532. 532 y : Int32,
  533. 533) -> SpectralSignature {
  534. 534● let reflectance : Array[Double] = []
  535. 535 let wavelengths : Array[Double] = []
  536. 536 let mut sum = 0.0
  537. 537 let mut sum_sq = 0.0
  538. 538
  539. 539 for b in 0..<image.bands {
  540. 540● let idx = (y * image.width + x) * image.bands + b
  541. 541● if idx < image.data.length() {
  542. 542● let value = image.data[idx]
  543. 543● reflectance.push(value)
  544. 544● wavelengths.push(image.wavelength[b])
  545. 545 sum += value
  546. 546 sum_sq += value * value
  547. 547 }
  548. 548 }
  549. 549
  550. 550◐ let mean = if image.bands > 0 { sum / image.bands.to_double() } else { 0.0 }
  551. 551 let variance = if image.bands > 0 {
  552. 552● sum_sq / image.bands.to_double() - mean * mean
  553. 553 } else {
  554. 554○ 0.0
  555. 555 }
  556. 556● let std = if variance > 0.0 { variance.sqrt() } else { 0.0 }
  557. 557
  558. 558 // 简化的吸收特征检测
  559. 559 let absorption_features : Array[(Double, Double)] = []
  560. 560 for b in 1..<(image.bands - 1) {
  561. 561● if b < reflectance.length() {
  562. 562● let prev = reflectance[b - 1]
  563. 563 let curr = reflectance[b]
  564. 564 let next = reflectance[b + 1]
  565. 565 if curr < prev && curr < next {
  566. 566○ let depth = (prev + next) / 2.0 - curr
  567. 567 if depth > 0.01 {
  568. 568○ absorption_features.push((wavelengths[b], depth))
  569. 569 }
  570. 570 }
  571. 571 }
  572. 572 }
  573. 573
  574. 574 SpectralSignature::{
  575. 575 wavelengths,
  576. 576 reflectance,
  577. 577 num_bands: image.bands,
  578. 578 mean_reflectance: mean,
  579. 579 std_reflectance: std,
  580. 580 absorption_features,
  581. 581 }
  582. 582}
  583. 583
  584. 584///|
  585. 585/// 计算遥感图像质量
  586. 586pub fn calculate_remote_sensing_quality(
  587. 587 image : RemoteSensingImage,
  588. 588) -> RemoteSensingQuality {
  589. 589● let w = image.width
  590. 590 let h = image.height
  591. 591 let total = w * h
  592. 592 let mut sum = 0.0
  593. 593 let mut sum_sq = 0.0
  594. 594
  595. 595 for i in 0..<total {
  596. 596● if i < image.data.length() {
  597. 597● let pixel = image.data[i]
  598. 598 sum += pixel
  599. 599 sum_sq += pixel * pixel
  600. 600 }
  601. 601 }
  602. 602
  603. 603◐ let mean = if total > 0 { sum / total.to_double() } else { 0.0 }
  604. 604 let variance = if total > 0 {
  605. 605● sum_sq / total.to_double() - mean * mean
  606. 606 } else {
  607. 607○ 0.0
  608. 608 }
  609. 609● let std = if variance > 0.0 { variance.sqrt() } else { 1.0 }
  610. 610◐ let snr = if std > 0.0 { mean / std } else { 0.0 }
  611. 611
  612. 612 let overall_quality = if snr > 10.0 && image.cloud_cover < 10.0 {
  613. 613● 5.0
  614. 614● } else if snr > 5.0 && image.cloud_cover < 30.0 {
  615. 615● 3.0
  616. 616 } else {
  617. 617● 2.0
  618. 618 }
  619. 619
  620. 620 RemoteSensingQuality::{
  621. 621 snr,
  622. 622 cloud_cover: image.cloud_cover,
  623. 623 geometric_accuracy: 0.8,
  624. 624 radiometric_accuracy: 0.85,
  625. 625 overall_quality,
  626. 626 }
  627. 627}
  628. 628
  629. 629///|
  630. 630/// 生成遥感图像分析报告
  631. 631pub fn remote_sensing_report_to_string(
  632. 632 image : RemoteSensingImage,
  633. 633 classification : ClassificationResult,
  634. 634 changes : ChangeDetectionResult,
  635. 635 quality : RemoteSensingQuality,
  636. 636) -> String {
  637. 637● let mut report = "## 遥感图像分析报告\n\n"
  638. 638 report = report + "### 图像信息\n\n"
  639. 639 report = report + "| 指标 | 值 |\n|------|------|\n"
  640. 640 let type_str = if image.image_type == RemoteSensingImageType::Optical {
  641. 641● "光学"
  642. 642● } else if image.image_type == RemoteSensingImageType::Multispectral {
  643. 643● "多光谱"
  644. 644○ } else if image.image_type == RemoteSensingImageType::Hyperspectral {
  645. 645○ "高光谱"
  646. 646○ } else if image.image_type == RemoteSensingImageType::SAR {
  647. 647○ "SAR"
  648. 648○ } else if image.image_type == RemoteSensingImageType::Thermal {
  649. 649○ "热红外"
  650. 650○ } else if image.image_type == RemoteSensingImageType::LiDAR {
  651. 651○ "激光雷达"
  652. 652 } else {
  653. 653○ "未知"
  654. 654 }
  655. 655 report = report + "| 类型 | " + type_str + " |\n"
  656. 656 report = report +
  657. 657 "| 尺寸 | " +
  658. 658● image.width.to_string() +
  659. 659 "x" +
  660. 660● image.height.to_string() +
  661. 661 " |\n"
  662. 662● report = report + "| 波段数 | " + image.bands.to_string() + " |\n"
  663. 663 report = report +
  664. 664 "| 空间分辨率 | " +
  665. 665● image.resolution.to_string() +
  666. 666 "m |\n"
  667. 667 report = report + "| 获取日期 | " + image.acquisition_date + " |\n"
  668. 668● report = report + "| 云量 | " + image.cloud_cover.to_string() + "% |\n\n"
  669. 669
  670. 670 report = report + "### 图像质量\n\n"
  671. 671 report = report + "| 指标 | 值 |\n|------|------|\n"
  672. 672● report = report + "| SNR | " + quality.snr.to_string() + " dB |\n"
  673. 673● report = report + "| 云量 | " + quality.cloud_cover.to_string() + "% |\n"
  674. 674 report = report +
  675. 675 "| 几何精度 | " +
  676. 676● (quality.geometric_accuracy * 100.0).to_string() +
  677. 677 "% |\n"
  678. 678 report = report +
  679. 679 "| 辐射精度 | " +
  680. 680● (quality.radiometric_accuracy * 100.0).to_string() +
  681. 681 "% |\n"
  682. 682 report = report +
  683. 683 "| 综合质量 | " +
  684. 684● quality.overall_quality.to_string() +
  685. 685 "/5.0 |\n\n"
  686. 686
  687. 687 report = report + "### 地物分类统计\n\n"
  688. 688 report = report + "| 类别 | 颜色(RGB) |\n|------|-----------|\n"
  689. 689 for i in 0..<classification.num_classes {
  690. 690● if i < classification.class_names.length() &&
  691. 691● i < classification.class_colors.length() {
  692. 692● let color = classification.class_colors[i]
  693. 693 report = report +
  694. 694 "| " +
  695. 695 classification.class_names[i] +
  696. 696 " | " +
  697. 697● color.0.to_string() +
  698. 698 "," +
  699. 699● color.1.to_string() +
  700. 700 "," +
  701. 701● color.2.to_string() +
  702. 702 " |\n"
  703. 703 }
  704. 704 }
  705. 705
  706. 706 report = report + "\n### 变化检测\n\n"
  707. 707 report = report + "| 指标 | 值 |\n|------|------|\n"
  708. 708 report = report +
  709. 709 "| 变化像素数 | " +
  710. 710● changes.num_changed_pixels.to_string() +
  711. 711 " |\n"
  712. 712 report = report +
  713. 713 "| 变化百分比 | " +
  714. 714● changes.change_percentage.to_string() +
  715. 715 "% |\n"
  716. 716● report = report + "| 变化阈值 | " + changes.threshold.to_string() + " |\n"
  717. 717
  718. 718 report
  719. 719}