scirs2-ndimage 0.6.0

N-dimensional image processing module for SciRS2 (scirs2-ndimage)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
//! Comprehensive documentation and usage examples for scirs2-ndimage
//!
//! This example serves as a complete guide to using scirs2-ndimage, covering:
//! - All major API categories with detailed examples
//! - Best practices for performance and memory efficiency
//! - Advanced features and optimization techniques
//! - Error handling and edge cases
//! - Integration with other scirs2 modules

use ndarray::{Array2, Array3, ArrayView2, Axis};
use scirs2_ndimage::{
    backend::*, domain_specific::*, error::NdimageResult, features::*, filters::*,
    interpolation::*, measurements::*, morphology::*, segmentation::*, streaming::*,
    visualization::*,
};

#[allow(dead_code)]
fn main() -> NdimageResult<()> {
    println!("=== Comprehensive scirs2-ndimage Documentation & Examples ===\n");

    // Create various test images for different examples
    let testimage_2d = create_testimage_2d(128, 128);
    let testimage_3d = create_testimage_3d(64, 64, 32);
    let noisyimage = add_noise(&testimage_2d, 0.1);
    let edgeimage = create_edge_testimage(64, 64);

    // 1. Filtering Operations
    println!("--- 1. FILTERING OPERATIONS ---\n");
    demonstrate_filtering(&testimage_2d, &noisyimage)?;

    // 2. Feature Detection
    println!("\n--- 2. FEATURE DETECTION ---\n");
    demonstrate_feature_detection(&edgeimage)?;

    // 3. Morphological Operations
    println!("\n--- 3. MORPHOLOGICAL OPERATIONS ---\n");
    demonstrate_morphology(&testimage_2d)?;

    // 4. Interpolation and Transformations
    println!("\n--- 4. INTERPOLATION & TRANSFORMATIONS ---\n");
    demonstrate_interpolation(&testimage_2d)?;

    // 5. Measurements and Analysis
    println!("\n--- 5. MEASUREMENTS & ANALYSIS ---\n");
    demonstrate_measurements(&testimage_2d)?;

    // 6. Segmentation
    println!("\n--- 6. SEGMENTATION ---\n");
    demonstrate_segmentation(&testimage_2d)?;

    // 7. Domain-Specific Functions
    println!("\n--- 7. DOMAIN-SPECIFIC FUNCTIONS ---\n");
    demonstrate_domain_specific(&testimage_2d)?;

    // 8. Advanced SIMD Extensions
    #[cfg(feature = "simd")]
    {
        println!("\n--- 8. ADVANCED SIMD EXTENSIONS ---\n");
        demonstrate_advanced_simd(&testimage_2d)?;
    }

    // 9. Backend and Performance
    println!("\n--- 9. BACKEND & PERFORMANCE OPTIMIZATION ---\n");
    demonstrate_backends(&testimage_2d)?;

    // 10. Streaming for Large Data
    println!("\n--- 10. STREAMING FOR LARGE DATASETS ---\n");
    demonstrate_streaming()?;

    // 11. Memory Management
    println!("\n--- 11. MEMORY MANAGEMENT ---\n");
    demonstrate_memory_management(&testimage_2d)?;

    // 12. Visualization
    println!("\n--- 12. VISUALIZATION ---\n");
    demonstrate_visualization(&testimage_2d)?;

    // 13. Best Practices and Tips
    println!("\n--- 13. BEST PRACTICES & OPTIMIZATION TIPS ---\n");
    demonstrate_best_practices()?;

    println!("\n=== Documentation Examples Complete ===");
    println!("For more details, see the API documentation and individual module examples.");

    Ok(())
}

#[allow(dead_code)]
fn create_testimage_2d(height: usize, width: usize) -> Array2<f64> {
    Array2::from_shape_fn((height, width), |(i, j)| {
        let x = i as f64 / height as f64;
        let y = j as f64 / width as f64;

        // Create multiple patterns
        let pattern1 = (x * std::f64::consts::PI * 4.0).sin();
        let pattern2 = (y * std::f64::consts::PI * 6.0).cos();
        let radial = ((x - 0.5).powi(2) + (y - 0.5).powi(2)).sqrt();

        0.5 + 0.3 * pattern1 * pattern2 + 0.2 * (1.0 - radial).max(0.0)
    })
}

#[allow(dead_code)]
fn create_testimage_3d(height: usize, width: usize, depth: usize) -> Array3<f64> {
    Array3::from_shape_fn((height, width, depth), |(i, j, k)| {
        let x = i as f64 / height as f64;
        let y = j as f64 / width as f64;
        let z = k as f64 / depth as f64;

        ((x * std::f64::consts::PI).sin()
            + (y * std::f64::consts::PI).cos()
            + (z * std::f64::consts::PI).sin())
            / 3.0
    })
}

#[allow(dead_code)]
fn add_noise(image: &Array2<f64>, noiselevel: f64) -> Array2<f64> {
    image
        + &Array2::from_shape_fn(image.dim(), |(i, j)| {
            let noise = if (i * 7 + j * 11) % 13 == 0 {
                noiselevel
            } else {
                -noiselevel
            };
            if (i + j) % 3 == 0 {
                noise
            } else {
                0.0
            }
        })
}

#[allow(dead_code)]
fn create_edge_testimage(height: usize, width: usize) -> Array2<f64> {
    Array2::from_shape_fn((height, width), |(i, j)| {
        // Create step edges and lines
        if i > height / 2 && i < height / 2 + 5 {
            1.0
        } else if j > width / 2 && j < width / 2 + 5 {
            1.0
        } else if ((i as f64 - height as f64 / 2.0).powi(2)
            + (j as f64 - width as f64 / 2.0).powi(2))
        .sqrt()
            < 15.0
        {
            0.8
        } else {
            0.0
        }
    })
}

#[allow(dead_code)]
fn demonstrate_filtering(image: &Array2<f64>, noisyimage: &Array2<f64>) -> NdimageResult<()> {
    println!("🔍 Filtering Operations");

    // 1. Basic filters
    println!("  • Gaussian filtering (noise reduction):");
    let gaussian = gaussian_filter(&image, 2.0, None, None)?;
    println!(
        "    Input: {}x{}, Output: {}x{}",
        image.nrows(),
        image.ncols(),
        gaussian.nrows(),
        gaussian.ncols()
    );

    // 2. Edge detection filters
    println!("  • Edge detection filters:");
    let sobel_result = sobel(&image, 0, None)?;
    let laplace_result = laplace(&image, None, None)?;
    println!("    Sobel edges detected, Laplacian computed");

    // 3. Rank filters
    println!("  • Rank filters (noise removal):");
    let median = median_filter(&noisyimage, &[3, 3], None)?;
    let max_filter = maximum_filter(&image, &[3, 3], None, None)?;
    println!("    Median filter applied, maximum filter computed");

    // 4. Advanced filters
    println!("  • Advanced filters:");
    let bilateral = bilateral_filter(image.view(), 2.0, 0.1, None)?;
    println!("    Bilateral filter (edge-preserving smoothing) applied");

    // 5. Generic filters with custom functions
    println!("  • Generic filters with custom functions:");
    let custom_filter = generic_filter(
        &image.view(),
        None, // use default 3x3 footprint
        |neighborhood: &[f64]| {
            neighborhood.iter().fold(0.0, |sum, &x| sum + x) / neighborhood.len() as f64
        }, // use mean as the filter function
        None, // mode
        None, // cval
        None, // origin
        None, // axes
    )?;
    println!("    Custom variance filter applied");

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_feature_detection(image: &Array2<f64>) -> NdimageResult<()> {
    println!("🎯 Feature Detection");

    // 1. Edge detection
    println!("  • Edge detection methods:");
    let canny_edges = canny(image.view(), 1.0, 0.1, 0.3, None)?;
    let sobel_edges = sobel_edges(image.view(), None)?;
    println!("    Canny and Sobel edge detection completed");

    // 2. Corner detection
    println!("  • Corner detection:");
    let harris_corners = harris_corners(image.view(), 0.04, 3, 0.01, None)?;
    let fast_corners = fast_corners(image.view(), 9, 0.15, None)?;
    println!("    Harris and FAST corner detection completed");

    #[cfg(feature = "simd")]
    {
        // 3. Machine learning-based detection
        println!("  • ML-based feature detection:");
        let ml_config = MLDetectorConfig::default();
        let learned_detector = LearnedEdgeDetector::new(ml_config)?;
        let ml_edges = learned_detector.detect_edges(image.view())?;
        println!("    ML-based edge detection completed");
    }

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_morphology(image: &Array2<f64>) -> NdimageResult<()> {
    println!("🔬 Morphological Operations");

    // Create binary image for morphology
    let binary_image = image.mapv(|x| if x > 0.5 { 1u8 } else { 0u8 });

    // 1. Basic binary morphology
    println!("  • Basic binary morphology:");
    let structure = generate_binary_structure(2, 1)?;
    let eroded = binary_erosion(
        &binary_image.view(),
        Some(&structure.view()),
        None,
        None,
        None,
        None,
    )?;
    let dilated = binary_dilation(
        &binary_image.view(),
        Some(&structure.view()),
        None,
        None,
        None,
        None,
    )?;
    println!("    Binary erosion and dilation completed");

    // 2. Compound operations
    println!("  • Compound morphological operations:");
    let opened = binary_opening(
        &binary_image.view(),
        Some(&structure.view()),
        None,
        None,
        None,
    )?;
    let closed = binary_closing(
        &binary_image.view(),
        Some(&structure.view()),
        None,
        None,
        None,
    )?;
    println!("    Opening and closing operations completed");

    // 3. Grayscale morphology
    println!("  • Grayscale morphology:");
    let grey_eroded = grey_erosion(&image.view(), None, None, None, None, None)?;
    let grey_dilated = grey_dilation(&image.view(), None, None, None, None, None)?;
    println!("    Grayscale erosion and dilation completed");

    // 4. Distance transforms
    println!("  • Distance transforms:");
    let edt = distance_transform_edt(&binary_image.view(), None, None, None)?;
    println!("    Euclidean distance transform computed");

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_interpolation(image: &Array2<f64>) -> NdimageResult<()> {
    println!("🔄 Interpolation & Transformations");

    // 1. Basic interpolation
    println!("  • Basic interpolation:");
    let zoomed = zoom(
        image,
        &[2.0, 1.5],
        InterpolationOrder::Linear,
        BoundaryMode::Reflect,
        None,
    )?;
    println!(
        "    Zoom: {}x{} -> {}x{}",
        image.nrows(),
        image.ncols(),
        zoomed.nrows(),
        zoomed.ncols()
    );

    // 2. Rotation
    println!("  • Rotation transformation:");
    let rotated = rotate(&image.view(), 45.0, None, None, None, None, None)?;
    println!("    45-degree rotation completed");

    // 3. Affine transformation
    println!("  • Affine transformation:");
    let transform_matrix = Array2::from_shape_vec(
        (2, 3),
        vec![
            1.2, 0.2, 10.0, // scale + shear + translation
            0.1, 1.1, 5.0,
        ],
    )?;
    let transformed = affine_transform(
        &image.view(),
        &transform_matrix.view(),
        InterpolationOrder::Linear,
        BoundaryMode::Constant,
        Some(0.0),
    )?;
    println!("    Affine transformation applied");

    // 4. Coordinate mapping
    println!("  • Coordinate mapping:");
    let coords = Array2::fromshape_fn((2, 100), |(axis, i)| {
        if axis == 0 {
            (i as f64 / 99.0) * (image.nrows() - 1) as f64
        } else {
            (i as f64 / 99.0) * (image.ncols() - 1) as f64
        }
    });
    let mapped_values = map_coordinates(
        &image.view(),
        &coords.view(),
        InterpolationOrder::Linear,
        BoundaryMode::Reflect,
        None,
    )?;
    println!(
        "    Coordinate mapping: {} values extracted",
        mapped_values.len()
    );

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_measurements(image: &Array2<f64>) -> NdimageResult<()> {
    println!("📊 Measurements & Analysis");

    // Create labeled image for region analysis
    let binary = image.mapv(|x| if x > 0.6 { 1u32 } else { 0u32 });
    let labeled = label(&binary.view(), None)?;

    // 1. Basic measurements
    println!("  • Basic measurements:");
    let com = center_of_mass(&image.view(), Some(&labeled.1.view()), None)?;
    println!("    Center of mass: {:?}", com);

    // 2. Statistical measurements
    println!("  • Statistical measurements:");
    let extrema_result = extrema(&image.view(), Some(&labeled.1.view()), None)?;
    println!("    Extrema found: {} regions", extrema_result.len());

    // 3. Moments analysis
    println!("  • Moments analysis:");
    let moments_result = moments(&image.view(), None, None)?;
    println!("    Moments computed for image");

    // 4. Region properties
    println!("  • Region properties:");
    let properties = region_properties(&labeled.1.view(), Some(&image.view()))?;
    println!("    Properties computed for {} regions", properties.len());
    for (i, prop) in properties.iter().take(3).enumerate() {
        println!(
            "      Region {}: area={:.1}, centroid=({:.1}, {:.1})",
            i, prop.area, prop.centroid[0], prop.centroid[1]
        );
    }

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_segmentation(image: &Array2<f64>) -> NdimageResult<()> {
    println!("✂️ Segmentation");

    // 1. Thresholding
    println!("  • Thresholding methods:");
    let binary = threshold_binary(&image.view(), 0.5)?;
    let otsu = otsu_threshold(&image.view())?;
    let adaptive = adaptive_threshold(&image.view(), 15, AdaptiveMethod::Mean, 0.1)?;
    println!("    Binary, Otsu, and adaptive thresholding completed");

    // 2. Watershed segmentation
    println!("  • Watershed segmentation:");
    let markers = Array2::fromshape_fn(image.dim(), |(i, j)| {
        if i < 20 && j < 20 {
            1u32
        } else if i > image.nrows() - 20 && j > image.ncols() - 20 {
            2u32
        } else {
            0u32
        }
    });
    let watershed_result = watershed(&image.view(), &markers.view(), None, None)?;
    println!("    Watershed segmentation completed");

    #[cfg(feature = "simd")]
    {
        // 3. Advanced segmentation
        println!("  • Advanced segmentation methods:");

        // Graph cuts
        let graph_cuts_params = GraphCutsParams::default();
        let gc_result = graph_cuts(&image.view(), &markers.view(), graph_cuts_params)?;
        println!("    Graph cuts segmentation completed");

        // Chan-Vese
        let initial_contour = create_circle_contour((image.nrows() / 2, image.ncols() / 2), 30.0);
        let cv_params = ChanVeseParams::default();
        let cv_result = chan_vese(&image.view(), &initial_contour, cv_params)?;
        println!("    Chan-Vese segmentation completed");
    }

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_domain_specific(image: &Array2<f64>) -> NdimageResult<()> {
    println!("🏥 Domain-Specific Functions");

    // 1. Medical imaging
    println!("  • Medical imaging functions:");
    let vesselness = medical::frangi_vesselness(&image.view(), None)?;
    println!("    Frangi vesselness filter applied");

    let enhanced_bone = medical::enhance_bone_structure(&image.view(), 1.0, 2.0)?;
    println!("    Bone structure enhancement completed");

    // 2. Satellite/remote sensing
    println!("  • Satellite/remote sensing:");
    let fake_nir = image + &Array2::ones(image.dim()) * 0.3; // Simulate NIR band
    let ndvi = satellite::compute_ndvi(&fake_nir.view(), &image.view())?;
    println!("    NDVI computation completed");

    let water_mask = satellite::detect_water_bodies(&image.view(), 0.3)?;
    println!("    Water body detection completed");

    // 3. Microscopy
    println!("  • Microscopy functions:");
    let cell_params = microscopy::CellSegmentationParams::default();
    let cells = microscopy::segment_cells(&image.view(), cell_params)?;
    println!("    Cell segmentation: {} cells detected", cells.len());

    Ok(())
}

#[cfg(feature = "simd")]
#[allow(dead_code)]
fn demonstrate_advanced_simd(image: &Array2<f64>) -> NdimageResult<()> {
    println!("⚡ Advanced SIMD Extensions");

    // 1. Wavelet pyramid
    println!("  • Advanced-SIMD wavelet pyramid:");
    let pyramid = advanced_simd_wavelet_pyramid(image.view(), 3, WaveletType::Daubechies4)?;
    println!(
        "    Wavelet pyramid: {} levels generated",
        pyramid.levels.len()
    );

    // 2. Local Binary Patterns
    println!("  • Advanced-SIMD multi-scale LBP:");
    let lbp = advanced_simd_multi_scale_lbp(image.view(), &[1, 2, 3], &[8, 16, 24])?;
    println!("    Multi-scale LBP texture analysis completed");

    // 3. Advanced edge detection
    println!("  • Advanced-SIMD advanced edge detection:");
    let advanced_edges = advanced_simd_advanced_edge_detection(image.view(), 1.0, 0.1, 0.3)?;
    println!("    Advanced edge detection with multi-directional gradients completed");

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_backends(image: &Array2<f64>) -> NdimageResult<()> {
    println!("🖥️ Backend & Performance Optimization");

    // 1. Backend selection
    println!("  • Backend configuration:");
    let backend = BackendBuilder::new()
        .backend(Backend::Cpu)
        .gpu_threshold(10000)
        .allow_fallback(true)
        .build()?;
    println!("    Backend configured with automatic GPU fallback");

    // 2. Auto backend selection
    println!("  • Automatic backend selection:");
    let auto_backend = auto_backend(&[image.nrows(), image.ncols()])?;
    println!("    Auto-selected backend: {:?}", auto_backend);

    #[cfg(feature = "cuda")]
    {
        println!("  • GPU acceleration available");
        // GPU-specific operations would go here
    }

    #[cfg(not(feature = "cuda"))]
    {
        println!("  • GPU acceleration not available (compile with --features cuda)");
    }

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_streaming() -> NdimageResult<()> {
    println!("🌊 Streaming for Large Datasets");

    // Create a temporary large file simulation
    println!("  • Streaming configuration:");
    let config = StreamConfig {
        chunk_size: (512, 512),
        overlap: (32, 32),
        num_workers: 4,
        buffer_size: 1024 * 1024 * 100, // 100MB buffer
    };
    println!(
        "    Stream config: {}x{} chunks, {} workers",
        config.chunk_size.0, config.chunk_size.1, config.num_workers
    );

    // Create streaming processor
    println!("  • Streaming Gaussian filter setup:");
    let streaming_filter = StreamingGaussianFilter::new([2.0, 2.0]);
    println!("    Streaming Gaussian filter configured");

    println!("  • For real file processing, use:");
    println!("    stream_process_file(input_path, output_path, operation, config)");

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_memory_management(image: &Array2<f64>) -> NdimageResult<()> {
    println!("🧠 Memory Management");

    use scirs2_ndimage::memory_management::*;

    // 1. Memory estimation
    println!("  • Memory usage estimation:");
    let memory_needed = estimate_memory_usage(&[image.nrows(), image.ncols()], 8)?; // 8 bytes per f64
    println!(
        "    Estimated memory for processing: {:.2} MB",
        memory_needed as f64 / 1_000_000.0
    );

    // 2. Memory configuration
    println!("  • Memory configuration:");
    let memory_config = MemoryConfig {
        max_memory_gb: 4.0,
        chunk_size_mb: 100.0,
        enable_memory_mapping: true,
        buffer_pool_size: 10,
    };
    println!(
        "    Memory limit: {:.1} GB, chunk size: {:.1} MB",
        memory_config.max_memory_gb, memory_config.chunk_size_mb
    );

    // 3. Buffer pool
    println!("  • Buffer pool management:");
    let buffer_pool = BufferPool::new(5, 1024 * 1024)?; // 5 buffers of 1MB each
    println!("    Buffer pool created with 5 buffers");

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_visualization(image: &Array2<f64>) -> NdimageResult<()> {
    println!("📊 Visualization");

    // 1. Colormaps
    println!("  • Colormap creation:");
    let colormap = create_colormap(ColorMap::Viridis, 256)?;
    println!("    Viridis colormap created with 256 colors");

    // 2. Statistical plots
    println!("  • Statistical visualization:");
    let plot_config = PlotConfig::default();
    let histogram_data = plot_histogram(&image.view(), 50, plot_config.clone())?;
    println!("    Histogram data generated for 50 bins");

    // 3. Report generation
    println!("  • Report generation:");
    let report_config = ReportConfig {
        format: ReportFormat::Html,
        include_statistics: true,
        include_plots: true,
        output_path: "analysis_report.html".into(),
    };
    println!("    Report configuration created for HTML output");

    Ok(())
}

#[allow(dead_code)]
fn demonstrate_best_practices() -> NdimageResult<()> {
    println!("💡 Best Practices & Optimization Tips");

    println!("  1. Performance Tips:");
    println!("     • Use SIMD features: compile with --features simd");
    println!("     • Enable parallel processing: --features parallel");
    println!("     • Choose appropriate data types (f32 vs f64)");
    println!("     • Use in-place operations when possible");

    println!("  2. Memory Optimization:");
    println!("     • Use streaming for large datasets (> 1GB)");
    println!("     • Configure appropriate chunk sizes");
    println!("     • Enable memory mapping for file processing");
    println!("     • Use buffer pools for repeated operations");

    println!("  3. Error Handling:");
    println!("     • Always handle NdimageResult errors");
    println!("     • Check input dimensions and data types");
    println!("     • Validate parameters before processing");

    println!("  4. API Selection:");
    println!("     • Use SciPy-compatible API for migration");
    println!("     • Use native Rust API for new code");
    println!("     • Combine with other scirs2 modules as needed");

    println!("  5. Backend Selection:");
    println!("     • Use auto backend selection for adaptive performance");
    println!("     • Configure GPU thresholds based on your hardware");
    println!("     • Enable fallback mechanisms for robustness");

    Ok(())
}

#[cfg(not(feature = "simd"))]
#[allow(dead_code)]
fn demonstrate_advanced_simd(image: &Array2<f64>) -> NdimageResult<()> {
    println!("⚡ Advanced SIMD Extensions");
    println!("  Note: SIMD features not available (compile with --features simd)");
    Ok(())
}