Skip to main content

Nd2File

Struct Nd2File 

Source
pub struct Nd2File { /* private fields */ }
Expand description

Main reader for ND2 files

Implementations§

Source§

impl Nd2File

Source

pub fn open_reader<R>(reader: R) -> Result<Self>
where R: Read + Seek + 'static,

Open an ND2 file from any Read + Seek source (e.g. in-memory buffer).

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open an ND2 file for reading from a local path.

Examples found in repository?
examples/read_summary.rs (line 12)
3fn main() -> Result<()> {
4    let args: Vec<String> = std::env::args().collect();
5
6    if args.len() < 2 {
7        eprintln!("Usage: {} <path-to-nd2-file>", args[0]);
8        std::process::exit(1);
9    }
10
11    let path = &args[1];
12    let mut nd2 = Nd2File::open(path)?;
13
14    println!("=== ND2 File Information ===");
15    println!("Version: {:?}", nd2.version());
16
17    let summary = nd2.summary()?;
18    println!("Logical frames: {}", summary.logical_frame_count);
19    println!("Sizes: {:?}", summary.sizes);
20    println!("Channels: {:?}", summary.channels);
21
22    let first_plane = nd2.read_frame_2d(0, 0, 0, 0)?;
23    println!("First plane pixels: {}", first_plane.len());
24
25    Ok(())
26}
Source

pub fn version(&self) -> (u32, u32)

Get the file format version (major, minor)

Examples found in repository?
examples/read_summary.rs (line 15)
3fn main() -> Result<()> {
4    let args: Vec<String> = std::env::args().collect();
5
6    if args.len() < 2 {
7        eprintln!("Usage: {} <path-to-nd2-file>", args[0]);
8        std::process::exit(1);
9    }
10
11    let path = &args[1];
12    let mut nd2 = Nd2File::open(path)?;
13
14    println!("=== ND2 File Information ===");
15    println!("Version: {:?}", nd2.version());
16
17    let summary = nd2.summary()?;
18    println!("Logical frames: {}", summary.logical_frame_count);
19    println!("Sizes: {:?}", summary.sizes);
20    println!("Channels: {:?}", summary.channels);
21
22    let first_plane = nd2.read_frame_2d(0, 0, 0, 0)?;
23    println!("First plane pixels: {}", first_plane.len());
24
25    Ok(())
26}
Source

pub fn summary(&mut self) -> Result<DatasetSummary>

Return a lightweight dataset overview aligned with other reader crates.

Examples found in repository?
examples/read_summary.rs (line 17)
3fn main() -> Result<()> {
4    let args: Vec<String> = std::env::args().collect();
5
6    if args.len() < 2 {
7        eprintln!("Usage: {} <path-to-nd2-file>", args[0]);
8        std::process::exit(1);
9    }
10
11    let path = &args[1];
12    let mut nd2 = Nd2File::open(path)?;
13
14    println!("=== ND2 File Information ===");
15    println!("Version: {:?}", nd2.version());
16
17    let summary = nd2.summary()?;
18    println!("Logical frames: {}", summary.logical_frame_count);
19    println!("Sizes: {:?}", summary.sizes);
20    println!("Channels: {:?}", summary.channels);
21
22    let first_plane = nd2.read_frame_2d(0, 0, 0, 0)?;
23    println!("First plane pixels: {}", first_plane.len());
24
25    Ok(())
26}
Source

pub fn read_frame(&mut self, index: usize) -> Result<Vec<u16>>

Read one frame by sequence index. Returns pixels as (C, Y, X) u16 data.

Source

pub fn read_frame_2d( &mut self, p: usize, t: usize, c: usize, z: usize, ) -> Result<Vec<u16>>

Read 2D Y×X frame at (p,t,c,z). Returns the Y×X pixels for the requested channel.

Examples found in repository?
examples/read_summary.rs (line 22)
3fn main() -> Result<()> {
4    let args: Vec<String> = std::env::args().collect();
5
6    if args.len() < 2 {
7        eprintln!("Usage: {} <path-to-nd2-file>", args[0]);
8        std::process::exit(1);
9    }
10
11    let path = &args[1];
12    let mut nd2 = Nd2File::open(path)?;
13
14    println!("=== ND2 File Information ===");
15    println!("Version: {:?}", nd2.version());
16
17    let summary = nd2.summary()?;
18    println!("Logical frames: {}", summary.logical_frame_count);
19    println!("Sizes: {:?}", summary.sizes);
20    println!("Channels: {:?}", summary.channels);
21
22    let first_plane = nd2.read_frame_2d(0, 0, 0, 0)?;
23    println!("First plane pixels: {}", first_plane.len());
24
25    Ok(())
26}

Trait Implementations§

Source§

impl Drop for Nd2File

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.