image.photography\advanced_imaging\advanced_imaging.mbt
89.4% · 202 / 226 points · 846 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 高级成像 advanced_imaging/advanced_imaging - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 高级成像技术(v40.0.0) - 7
// 量子成像、太赫兹成像、红外成像、高光谱成像、偏振成像、热成像、X射线成像、超声成像、MRI成像、PET成像 - 8
- 9
///| - 10
/// 成像模态类型 - 11
/// `#non_exhaustive` 表示未来可能添加新构造器 - 12
#derive(Eq, @debug.Debug) - 13
#non_exhaustive - 14
pub(all) enum ImagingModality { - 15
Quantum - 16
Terahertz - 17
Infrared - 18
Hyperspectral - 19
Polarization - 20
Thermal - 21
XRay - 22
Ultrasound - 23
MRI - 24
PET - 25
CT - 26
Unknown - 27
} - 28
- 29
///| - 30
pub extend ImagingModality with @debug.Debug::{to_repr} - 31
- 32
///| - 33
pub extend ImagingModality with Eq::{not_equal, equal} - 34
- 35
///| - 36
/// 量子成像算法类型 - 37
/// `#non_exhaustive` 表示未来可能添加新构造器 - 38
#derive(Eq, @debug.Debug) - 39
#non_exhaustive - 40
pub(all) enum QuantumImagingAlgorithm { - 41
GhostImaging - 42
SinglePixel - 43
QuantumIllumination - 44
EntangledPhoton - 45
CompressiveSensing - 46
Unknown - 47
} - 48
- 49
///| - 50
pub extend QuantumImagingAlgorithm with @debug.Debug::{to_repr} - 51
- 52
///| - 53
pub extend QuantumImagingAlgorithm with Eq::{not_equal, equal} - 54
- 55
///| - 56
/// 红外成像类型 - 57
/// `#non_exhaustive` 表示未来可能添加新构造器 - 58
#derive(Eq, @debug.Debug) - 59
#non_exhaustive - 60
pub(all) enum InfraredImagingType { - 61
MWIR - 62
LWIR - 63
SWIR - 64
NIR - 65
ThermalIR - 66
Unknown - 67
} - 68
- 69
///| - 70
pub extend InfraredImagingType with @debug.Debug::{to_repr} - 71
- 72
///| - 73
pub extend InfraredImagingType with Eq::{not_equal, equal} - 74
- 75
///| - 76
/// 高光谱数据 - 77
#derive(Eq, @debug.Debug) - 78
pub(all) struct HyperspectralData { - 79
image_cube : Array[@types.Image] - 80
num_bands : Int32 - 81
wavelengths : Array[Double] - 82
spectral_resolution : Double - 83
spatial_width : Int32 - 84
spatial_height : Int32 - 85
} - 86
- 87
///| - 88
pub extend HyperspectralData with Eq::{not_equal, equal} - 89
- 90
///| - 91
pub extend HyperspectralData with @debug.Debug::{to_repr} - 92
- 93
///| - 94
/// 偏振数据 - 95
#derive(Eq, @debug.Debug) - 96
pub(all) struct PolarizationData { - 97
intensity : @types.Image - 98
degree_of_polarization : @types.Image - 99
angle_of_polarization : @types.Image - 100
stokes_parameters : Array[@types.Image] - 101
num_stokes : Int32 - 102
} - 103
- 104
///| - 105
pub extend PolarizationData with Eq::{not_equal, equal} - 106
- 107
///| - 108
pub extend PolarizationData with @debug.Debug::{to_repr} - 109
- 110
///| - 111
/// 热成像数据 - 112
#derive(Eq, @debug.Debug) - 113
pub(all) struct ThermalData { - 114
temperature_map : @types.Image - 115
min_temperature : Double - 116
max_temperature : Double - 117
average_temperature : Double - 118
emissivity : Double - 119
units : String - 120
} - 121
- 122
///| - 123
pub extend ThermalData with Eq::{not_equal, equal} - 124
- 125
///| - 126
pub extend ThermalData with @debug.Debug::{to_repr} - 127
- 128
///| - 129
/// X射线数据 - 130
#derive(Eq, @debug.Debug) - 131
pub(all) struct XRayData { - 132
projection : @types.Image - 133
energy_kev : Double - 134
dose : Double - 135
contrast : Double - 136
noise_level : Double - 137
} - 138
- 139
///| - 140
pub extend XRayData with Eq::{not_equal, equal} - 141
- 142
///| - 143
pub extend XRayData with @debug.Debug::{to_repr} - 144
- 145
///| - 146
/// 超声数据 - 147
#derive(Eq, @debug.Debug) - 148
pub(all) struct UltrasoundData { - 149
b_mode : @types.Image - 150
doppler : @types.Image - 151
frequency_mhz : Double - 152
depth_cm : Double - 153
gain : Double - 154
frame_rate : Double - 155
} - 156
- 157
///| - 158
pub extend UltrasoundData with Eq::{not_equal, equal} - 159
- 160
///| - 161
pub extend UltrasoundData with @debug.Debug::{to_repr} - 162
- 163
///| - 164
/// MRI数据 - 165
#derive(Eq, @debug.Debug) - 166
pub(all) struct MRIData { - 167
t1_weighted : @types.Image - 168
t2_weighted : @types.Image - 169
flair : @types.Image - 170
tr_ms : Double - 171
te_ms : Double - 172
slice_thickness_mm : Double - 173
field_strength_t : Double - 174
} - 175
- 176
///| - 177
pub extend MRIData with Eq::{not_equal, equal} - 178
- 179
///| - 180
pub extend MRIData with @debug.Debug::{to_repr} - 181
- 182
///| - 183
/// PET数据 - 184
#derive(Eq, @debug.Debug) - 185
pub(all) struct PETData { - 186
activity_map : @types.Image - 187
radiotracer : String - 188
injected_dose_mbq : Double - 189
uptake_time_min : Double - 190
reconstruction_algorithm : String - 191
suv_scale : Double - 192
} - 193
- 194
///| - 195
pub extend PETData with Eq::{not_equal, equal} - 196
- 197
///| - 198
pub extend PETData with @debug.Debug::{to_repr} - 199
- 200
///| - 201
/// 成像配置 - 202
#derive(Eq, @debug.Debug) - 203
pub(all) struct AdvancedImagingConfig { - 204
modality : ImagingModality - 205
image_width : Int32 - 206
image_height : Int32 - 207
num_slices : Int32 - 208
use_noise_reduction : Bool - 209
use_enhancement : Bool - 210
calibration_factor : Double - 211
} - 212
- 213
///| - 214
pub extend AdvancedImagingConfig with Eq::{not_equal, equal} - 215
- 216
///| - 217
pub extend AdvancedImagingConfig with @debug.Debug::{to_repr} - 218
- 219
///| - 220
/// 创建默认高级成像配置 - 221
pub fn create_default_advanced_imaging_config( - 222
modality : ImagingModality, - 223
) -> AdvancedImagingConfig { - 224●
AdvancedImagingConfig::{ - 225
modality, - 226
image_width: 512, - 227
image_height: 512, - 228
num_slices: 1, - 229
use_noise_reduction: true, - 230
use_enhancement: true, - 231
calibration_factor: 1.0, - 232
} - 233
} - 234
- 235
///| - 236
/// 量子成像(鬼成像简化版) - 237
pub fn quantum_ghost_imaging( - 238
num_patterns : Int32, - 239
width : Int32, - 240
height : Int32, - 241
algorithm : QuantumImagingAlgorithm, - 242
) -> @types.Image { - 243●
ignore(algorithm) - 244
let total = width * height - 245
let out : Array[Byte] = [] - 246
let accumulator : Array[Double] = [] - 247
for _ in 0..<total { - 248●
accumulator.push(0.0) - 249
} - 250
- 251
// 简化的鬼成像:随机模式与桶信号的关联 - 252
let mut state = 42 - 253
for _ in 0..<num_patterns { - 254
// 生成随机照明模式 - 255●
let pattern : Array[Bool] = [] - 256
let mut bucket_signal = 0.0 - 257
for _ in 0..<total { - 258●
state = ((state * 11035 + 12345).reinterpret_as_uint() % 1000000).reinterpret_as_int() - 259
let is_on = state % 2 == 0 - 260●
pattern.push(is_on) - 261
if is_on { - 262●
bucket_signal += 1.0 - 263
} - 264
} - 265
- 266
// 关联计算 - 267
for i in 0..<total { - 268●
if pattern[i] { - 269●
accumulator[i] += bucket_signal - 270
} - 271
} - 272
} - 273
- 274
// 归一化 - 275
let mut max_val = 0.0 - 276
for i in 0..<total { - 277●
if accumulator[i] > max_val { - 278●
max_val = accumulator[i] - 279
} - 280
} - 281
- 282
for i in 0..<total { - 283●
let normalized = if max_val > 0.0 { - 284●
accumulator[i] / max_val * 255.0 - 285
} else { - 286●
0.0 - 287
} - 288●
out.push(normalized.to_int().to_byte()) - 289
} - 290
- 291●
@types.Image::{ width, height, channels: 1, data: Bytes::from_array(out), } - 292
} - 293
- 294
///| - 295
/// 红外成像伪彩色映射 - 296
pub fn infrared_pseudocolor( - 297
infrared_image : @types.Image, - 298
ir_type : InfraredImagingType, - 299
) -> @types.Image { - 300●
ignore(ir_type) - 301
let w = infrared_image.width - 302
let h = infrared_image.height - 303
let total = w * h - 304
let out : Array[Byte] = [] - 305
- 306
for i in 0..<total { - 307●
let gray = infrared_image.data[i].to_double() / 255.0 - 308
- 309
// 铁彩虹伪彩色映射 - 310
let mut r = 0.0 - 311
let mut g = 0.0 - 312
let mut b = 0.0 - 313
- 314
if gray < 0.25 { - 315●
r = 0.0 - 316
g = 0.0 - 317
b = gray * 4.0 * 255.0 - 318●
} else if gray < 0.5 { - 319●
let t = (gray - 0.25) * 4.0 - 320
r = 0.0 - 321
g = t * 255.0 - 322
b = 255.0 - t * 255.0 - 323●
} else if gray < 0.75 { - 324●
let t = (gray - 0.5) * 4.0 - 325
r = t * 255.0 - 326
g = 255.0 - 327
b = 0.0 - 328
} else { - 329●
let t = (gray - 0.75) * 4.0 - 330
r = 255.0 - 331
g = 255.0 - t * 255.0 - 332
b = t * 128.0 - 333
} - 334
- 335●
out.push(r.to_int().to_byte()) - 336●
out.push(g.to_int().to_byte()) - 337●
out.push(b.to_int().to_byte()) - 338
} - 339
- 340
@types.Image::{ - 341
width: w, - 342
height: h, - 343
channels: 3, - 344●
data: Bytes::from_array(out), - 345
} - 346
} - 347
- 348
///| - 349
/// 生成高光谱数据立方体(简化版) - 350
pub fn generate_hyperspectral_cube( - 351
base_image : @types.Image, - 352
num_bands : Int32, - 353
start_wavelength : Double, - 354
end_wavelength : Double, - 355
) -> HyperspectralData { - 356●
let image_cube : Array[@types.Image] = [] - 357
let wavelengths : Array[Double] = [] - 358
let spectral_resolution = (end_wavelength - start_wavelength) / - 359●
num_bands.to_double() - 360
- 361
for band in 0..<num_bands { - 362●
let wavelength = start_wavelength + band.to_double() * spectral_resolution - 363●
wavelengths.push(wavelength) - 364
- 365
// 简化的波段生成:基于波长的颜色调制 - 366
let w = base_image.width - 367
let h = base_image.height - 368
let total = w * h - 369
let out : Array[Byte] = [] - 370
- 371
for i in 0..<total { - 372●
let base = base_image.data[i].to_double() - 373
// 简化的光谱响应 - 374
let response = if wavelength < 500.0 { - 375●
base * 0.8 - 376●
} else if wavelength < 600.0 { - 377●
base * 1.0 - 378●
} else if wavelength < 700.0 { - 379●
base * 0.9 - 380
} else { - 381●
base * 0.7 - 382
} - 383◐
let clamped = if response > 255.0 { 255.0 } else { response } - 384●
out.push(clamped.to_int().to_byte()) - 385
} - 386
- 387●
image_cube.push(@types.Image::{ - 388
width: w, - 389
height: h, - 390
channels: 1, - 391●
data: Bytes::from_array(out), - 392
}) - 393
} - 394
- 395
HyperspectralData::{ - 396
image_cube, - 397
num_bands, - 398
wavelengths, - 399
spectral_resolution, - 400
spatial_width: base_image.width, - 401
spatial_height: base_image.height, - 402
} - 403
} - 404
- 405
///| - 406
/// 偏振成像分析(简化版) - 407
pub fn analyze_polarization( - 408
images_0deg : @types.Image, - 409
images_45deg : @types.Image, - 410
images_90deg : @types.Image, - 411
images_135deg : @types.Image, - 412
) -> PolarizationData { - 413●
let w = images_0deg.width - 414
let h = images_0deg.height - 415
let total = w * h - 416
let intensity_out : Array[Byte] = [] - 417
let dop_out : Array[Byte] = [] - 418
let aop_out : Array[Byte] = [] - 419
- 420
for i in 0..<total { - 421●
let i0 = images_0deg.data[i].to_double() - 422●
let i45 = images_45deg.data[i].to_double() - 423●
let i90 = images_90deg.data[i].to_double() - 424●
let i135 = images_135deg.data[i].to_double() - 425
- 426
// Stokes参数 - 427
let s0 = (i0 + i90) / 2.0 - 428
let s1 = i0 - i90 - 429
let s2 = i45 - i135 - 430
- 431
// 偏振度 - 432
let dop = if s0 > 0.0 { - 433●
(s1 * s1 + s2 * s2).sqrt() / s0 * 255.0 - 434
} else { - 435●
0.0 - 436
} - 437
- 438
// 偏振角 - 439
let aop = if s1 != 0.0 { - 440●
(0.5 * atan_approx(s2 / s1) + 3.14159 / 2.0) / 3.14159 * 255.0 - 441
} else { - 442●
0.0 - 443
} - 444
- 445◐
let intensity_clamped = if s0 > 255.0 { 255.0 } else { s0 } - 446◐
let dop_clamped = if dop > 255.0 { 255.0 } else { dop } - 447◐
let aop_clamped = if aop > 255.0 { 255.0 } else { aop } - 448
- 449●
intensity_out.push(intensity_clamped.to_int().to_byte()) - 450●
dop_out.push(dop_clamped.to_int().to_byte()) - 451●
aop_out.push(aop_clamped.to_int().to_byte()) - 452
} - 453
- 454
let stokes : Array[@types.Image] = [] - 455●
stokes.push(images_0deg) - 456●
stokes.push(images_45deg) - 457●
stokes.push(images_90deg) - 458●
stokes.push(images_135deg) - 459
- 460
PolarizationData::{ - 461
intensity: @types.Image::{ - 462
width: w, - 463
height: h, - 464
channels: 1, - 465●
data: Bytes::from_array(intensity_out), - 466
}, - 467
degree_of_polarization: @types.Image::{ - 468
width: w, - 469
height: h, - 470
channels: 1, - 471●
data: Bytes::from_array(dop_out), - 472
}, - 473
angle_of_polarization: @types.Image::{ - 474
width: w, - 475
height: h, - 476
channels: 1, - 477●
data: Bytes::from_array(aop_out), - 478
}, - 479
stokes_parameters: stokes, - 480
num_stokes: 4, - 481
} - 482
} - 483
- 484
///| - 485
/// 热成像温度转换(简化版) - 486
pub fn thermal_to_temperature( - 487
thermal_image : @types.Image, - 488
emissivity : Double, - 489
min_temp : Double, - 490
max_temp : Double, - 491
) -> ThermalData { - 492●
let w = thermal_image.width - 493
let h = thermal_image.height - 494
let total = w * h - 495
let temp_out : Array[Byte] = [] - 496
- 497
let mut min_t = 1000.0 - 498
let mut max_t = -1000.0 - 499
let mut sum_t = 0.0 - 500
- 501
for i in 0..<total { - 502●
let gray = thermal_image.data[i].to_double() / 255.0 - 503
let temp = min_temp + gray * (max_temp - min_temp) - 504
let corrected = temp / emissivity - 505
- 506
if corrected < min_t { - 507●
min_t = corrected - 508
} - 509
if corrected > max_t { - 510●
max_t = corrected - 511
} - 512
sum_t += corrected - 513
- 514
let normalized = (corrected - min_temp) / (max_temp - min_temp) * 255.0 - 515
let clamped = if normalized < 0.0 { - 516○
0.0 - 517●
} else if normalized > 255.0 { - 518●
255.0 - 519
} else { - 520●
normalized - 521
} - 522●
temp_out.push(clamped.to_int().to_byte()) - 523
} - 524
- 525
ThermalData::{ - 526
temperature_map: @types.Image::{ - 527
width: w, - 528
height: h, - 529
channels: 1, - 530●
data: Bytes::from_array(temp_out), - 531
}, - 532
min_temperature: min_t, - 533
max_temperature: max_t, - 534●
average_temperature: sum_t / total.to_double(), - 535
emissivity, - 536
units: "Celsius", - 537
} - 538
} - 539
- 540
///| - 541
/// X射线图像增强(简化版) - 542
pub fn xray_enhance(xray_image : @types.Image, energy_kev : Double) -> XRayData { - 543●
let w = xray_image.width - 544
let h = xray_image.height - 545
let total = w * h - 546
let out : Array[Byte] = [] - 547
- 548
// 简化的X射线增强:对比度增强+噪声抑制 - 549
let mut sum = 0.0 - 550
let mut sum_sq = 0.0 - 551
for i in 0..<total { - 552●
let v = xray_image.data[i].to_double() - 553
sum += v - 554
sum_sq += v * v - 555
} - 556●
let mean = sum / total.to_double() - 557●
let variance = sum_sq / total.to_double() - mean * mean - 558●
let std_dev = if variance > 0.0 { variance.sqrt() } else { 1.0 } - 559
- 560
for i in 0..<total { - 561●
let v = xray_image.data[i].to_double() - 562
// 标准化+对比度拉伸 - 563
let normalized = (v - mean) / std_dev - 564
let enhanced = normalized * 40.0 + 128.0 - 565
let clamped = if enhanced < 0.0 { - 566○
0.0 - 567●
} else if enhanced > 255.0 { - 568○
255.0 - 569
} else { - 570●
enhanced - 571
} - 572●
out.push(clamped.to_int().to_byte()) - 573
} - 574
- 575
XRayData::{ - 576
projection: @types.Image::{ - 577
width: w, - 578
height: h, - 579
channels: 1, - 580●
data: Bytes::from_array(out), - 581
}, - 582
energy_kev, - 583
dose: 0.1, - 584
contrast: std_dev / mean, - 585
noise_level: std_dev * 0.1, - 586
} - 587
} - 588
- 589
///| - 590
/// 超声图像合成(简化版) - 591
pub fn ultrasound_synthesize( - 592
width : Int32, - 593
height : Int32, - 594
frequency_mhz : Double, - 595
depth_cm : Double, - 596
) -> UltrasoundData { - 597●
let _ = width * height - 598
let b_out : Array[Byte] = [] - 599
let doppler_out : Array[Byte] = [] - 600
- 601
let mut state = 42 - 602
for y in 0..<height { - 603●
for x in 0..<width { - 604●
state = ((state * 11035 + 12345).reinterpret_as_uint() % 1000000).reinterpret_as_int() - 605●
let noise = (state % 1000).to_double() / 1000.0 - 606
- 607
// 简化的B模式:扇形扫描+斑点噪声 - 608●
let center_x = width.to_double() / 2.0 - 609●
let dx = (x.to_double() - center_x) / (width.to_double() / 2.0) - 610●
let dy = y.to_double() / height.to_double() - 611●
let distance = (dx * dx + dy * dy).sqrt() - 612
- 613
let attenuation = 1.0 - dy * 0.5 - 614
let speckle = noise * 0.3 - 615●
let structure = if distance < 0.3 { 150.0 } else { 50.0 } - 616
let b_value = (structure + speckle * 100.0) * attenuation - 617
let b_clamped = if b_value < 0.0 { - 618○
0.0 - 619●
} else if b_value > 255.0 { - 620○
255.0 - 621
} else { - 622●
b_value - 623
} - 624●
b_out.push(b_clamped.to_int().to_byte()) - 625
- 626
// 简化的多普勒:血流信号 - 627
let doppler_value = if distance < 0.2 && dy > 0.3 { - 628○
noise * 255.0 - 629
} else { - 630●
0.0 - 631
} - 632●
doppler_out.push(doppler_value.to_int().to_byte()) - 633
} - 634
} - 635
- 636
UltrasoundData::{ - 637
b_mode: @types.Image::{ - 638
width, - 639
height, - 640
channels: 1, - 641●
data: Bytes::from_array(b_out), - 642
}, - 643
doppler: @types.Image::{ - 644
width, - 645
height, - 646
channels: 1, - 647●
data: Bytes::from_array(doppler_out), - 648
}, - 649
frequency_mhz, - 650
depth_cm, - 651
gain: 50.0, - 652
frame_rate: 30.0, - 653
} - 654
} - 655
- 656
///| - 657
/// MRI图像合成(简化版) - 658
pub fn mri_synthesize( - 659
width : Int32, - 660
height : Int32, - 661
field_strength_t : Double, - 662
) -> MRIData { - 663●
let _ = width * height - 664
let t1_out : Array[Byte] = [] - 665
let t2_out : Array[Byte] = [] - 666
let flair_out : Array[Byte] = [] - 667
- 668●
let center_x = width.to_double() / 2.0 - 669●
let center_y = height.to_double() / 2.0 - 670●
let radius = width.to_double() * 0.35 - 671
- 672
for y in 0..<height { - 673●
for x in 0..<width { - 674●
let dx = x.to_double() - center_x - 675●
let dy = y.to_double() - center_y - 676●
let dist = (dx * dx + dy * dy).sqrt() - 677
- 678
// 简化的脑部MRI - 679
let mut t1_value = 0.0 - 680
let mut t2_value = 0.0 - 681
let mut flair_value = 0.0 - 682
- 683
if dist < radius * 0.3 { - 684
// 脑室 - 685●
t1_value = 30.0 - 686
t2_value = 200.0 - 687
flair_value = 30.0 - 688●
} else if dist < radius * 0.6 { - 689
// 灰质 - 690●
t1_value = 100.0 - 691
t2_value = 150.0 - 692
flair_value = 120.0 - 693●
} else if dist < radius { - 694
// 白质 - 695●
t1_value = 180.0 - 696
t2_value = 100.0 - 697
flair_value = 160.0 - 698
} else { - 699
// 背景 - 700●
t1_value = 10.0 - 701
t2_value = 10.0 - 702
flair_value = 10.0 - 703
} - 704
- 705●
t1_out.push(t1_value.to_int().to_byte()) - 706●
t2_out.push(t2_value.to_int().to_byte()) - 707●
flair_out.push(flair_value.to_int().to_byte()) - 708
} - 709
} - 710
- 711
MRIData::{ - 712
t1_weighted: @types.Image::{ - 713
width, - 714
height, - 715
channels: 1, - 716●
data: Bytes::from_array(t1_out), - 717
}, - 718
t2_weighted: @types.Image::{ - 719
width, - 720
height, - 721
channels: 1, - 722●
data: Bytes::from_array(t2_out), - 723
}, - 724
flair: @types.Image::{ - 725
width, - 726
height, - 727
channels: 1, - 728●
data: Bytes::from_array(flair_out), - 729
}, - 730
tr_ms: 500.0, - 731
te_ms: 14.0, - 732
slice_thickness_mm: 5.0, - 733
field_strength_t, - 734
} - 735
} - 736
- 737
///| - 738
/// PET图像合成(简化版) - 739
pub fn pet_synthesize( - 740
width : Int32, - 741
height : Int32, - 742
radiotracer : String, - 743
) -> PETData { - 744●
let _ = width * height - 745
let out : Array[Byte] = [] - 746
- 747●
let center_x = width.to_double() / 2.0 - 748●
let center_y = height.to_double() / 2.0 - 749
- 750
let mut state = 42 - 751
for y in 0..<height { - 752●
for x in 0..<width { - 753●
state = ((state * 11035 + 12345).reinterpret_as_uint() % 1000000).reinterpret_as_int() - 754●
let noise = (state % 1000).to_double() / 1000.0 - 755
- 756●
let dx = x.to_double() - center_x - 757●
let dy = y.to_double() - center_y - 758●
let dist = (dx * dx + dy * dy).sqrt() - 759
- 760
// 简化的PET:高摄取区域+泊松噪声 - 761
let uptake = if dist < 50.0 { - 762●
200.0 - 763○
} else if dist < 100.0 { - 764○
100.0 - 765
} else { - 766○
20.0 - 767
} - 768
- 769
let value = uptake * (0.8 + noise * 0.4) - 770◐
let clamped = if value > 255.0 { 255.0 } else { value } - 771●
out.push(clamped.to_int().to_byte()) - 772
} - 773
} - 774
- 775
PETData::{ - 776
activity_map: @types.Image::{ - 777
width, - 778
height, - 779
channels: 1, - 780●
data: Bytes::from_array(out), - 781
}, - 782
radiotracer, - 783
injected_dose_mbq: 370.0, - 784
uptake_time_min: 60.0, - 785
reconstruction_algorithm: "OSEM", - 786
suv_scale: 1.0, - 787
} - 788
} - 789
- 790
///| - 791
/// 生成高级成像报告 - 792
pub fn advanced_imaging_report_to_string( - 793
modality : ImagingModality, - 794
image : @types.Image, - 795
config : AdvancedImagingConfig, - 796
) -> String { - 797●
let modality_name = match modality { - 798○
ImagingModality::Quantum => "量子成像" - 799●
ImagingModality::Terahertz => "太赫兹成像" - 800○
ImagingModality::Infrared => "红外成像" - 801○
ImagingModality::Hyperspectral => "高光谱成像" - 802●
ImagingModality::Polarization => "偏振成像" - 803○
ImagingModality::Thermal => "热成像" - 804○
ImagingModality::XRay => "X射线成像" - 805○
ImagingModality::Ultrasound => "超声成像" - 806●
ImagingModality::MRI => "MRI成像" - 807○
ImagingModality::PET => "PET成像" - 808●
ImagingModality::CT => "CT成像" - 809○
_ => "未知" - 810
} - 811
- 812
let mut report = "## 高级成像报告\n\n" - 813
report = report + "### 成像信息\n\n" - 814
report = report + "| 指标 | 值 |\n|------|------|\n" - 815
report = report + "| 成像模态 | " + modality_name + " |\n" - 816
report = report + - 817
"| 图像尺寸 | " + - 818●
image.width.to_string() + - 819
"x" + - 820●
image.height.to_string() + - 821
" |\n" - 822●
report = report + "| 通道数 | " + image.channels.to_string() + " |\n" - 823●
report = report + "| 切片数 | " + config.num_slices.to_string() + " |\n" - 824
report = report + - 825
"| 校准因子 | " + - 826●
config.calibration_factor.to_string() + - 827
" |\n" - 828
report = report + - 829
"| 噪声抑制 | " + - 830◐
(if config.use_noise_reduction { "开启" } else { "关闭" }) + - 831
" |\n" - 832
report = report + - 833
"| 图像增强 | " + - 834◐
(if config.use_enhancement { "开启" } else { "关闭" }) + - 835
" |\n" - 836
- 837
report - 838
} - 839
- 840
// 辅助函数 - 841
- 842
///| - 843
fn atan_approx(x : Double) -> Double { - 844
// 简化的反正切近似 - 845●
x - x * x * x / 3.0 + x * x * x * x * x / 5.0 - 846
}