Skip to content

Commit

Permalink
⏪ Dimensions in TIFF decoder and writer is actually width height
Browse files Browse the repository at this point in the history
Getting confused with the `tiff` crate using (width, height), while `ndarray` uses (height, width)...
  • Loading branch information
weiji14 committed Mar 8, 2024
1 parent 147511f commit 5bf0bb0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/io/geotiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn read_geotiff<R: Read + Seek>(stream: R) -> Result<Array2<f32>, TiffError>
decoder = decoder.with_limits(Limits::unlimited());

// Get image dimensions
let (height, width): (u32, u32) = decoder.dimensions()?;
let (width, height): (u32, u32) = decoder.dimensions()?;

// Get image pixel data
let DecodingResult::F32(img_data) = decoder.read_image()? else {
Expand Down Expand Up @@ -49,16 +49,16 @@ mod tests {
let mut file = tempfile().unwrap();
let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap();
bigtiff
.write_image::<colortype::Gray32Float>(20, 10, &image_data)
.write_image::<colortype::Gray32Float>(10, 20, &image_data) // width, height, data
.unwrap();
file.seek(SeekFrom::Start(0)).unwrap();

// Read a BigTIFF file
let arr = read_geotiff(file).unwrap();
assert_eq!(arr.ndim(), 2);
assert_eq!(arr.dim(), (20, 10)); // (height, width)
assert_eq!(arr.nrows(), 20); // y-axis
assert_eq!(arr.ncols(), 10); // x-axis
assert_eq!(arr.dim(), (20, 10)); // (height, width)
assert_eq!(arr.nrows(), 20); // y-axis
assert_eq!(arr.ncols(), 10); // x-axis
assert_eq!(arr.mean(), Some(14.0));
}
}

0 comments on commit 5bf0bb0

Please sign in to comment.