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
//! Image I/O utilities module
//!
//! This module provides clean delegation functions for image I/O operations,
//! forwarding calls to the unified I/O system in `crate::io::global`.
use crateResult;
use DynamicImage;
use Path;
use Tensor;
/// Save a tensor as an image using the unified I/O system
///
/// This function delegates to the global I/O system to save a tensor as an image file.
/// The tensor is expected to be in (C, H, W) format where C is channels (1 or 3),
/// H is height, and W is width.
///
/// # Arguments
/// * `tensor` - The tensor to save as an image (C, H, W format)
/// * `path` - Output file path
/// * `normalize` - Whether to normalize the tensor values to [0, 1] range
///
/// # Returns
/// * `Ok(())` if the image was saved successfully
/// * `Err(VisionError)` if there was an error during saving
///
/// # Example
/// ```rust
/// use torsh_vision::utils::image_io::save_tensor_as_image;
/// use torsh_tensor::creation;
///
/// let tensor = creation::rand(&[3, 224, 224]).unwrap();
/// save_tensor_as_image(&tensor, "output.png", true)?;
/// ```
/// Load multiple images from a directory using the unified I/O system
///
/// This function delegates to the global I/O system to load all images from a directory.
/// Returns a vector of tuples containing the loaded image and its filename.
///
/// # Arguments
/// * `dir_path` - Path to the directory containing images
///
/// # Returns
/// * `Ok(Vec<(DynamicImage, String)>)` - Vector of (image, filename) pairs
/// * `Err(VisionError)` if there was an error during loading
///
/// # Example
/// ```rust
/// use torsh_vision::utils::image_io::load_images_from_dir;
///
/// let images = load_images_from_dir("./images")?;
/// println!("Loaded {} images", images.len());
/// ```