-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ CogReader ndarray method to decode TIFF into an ndarray Array #10
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Making the decoder.read_image() code an impl method under the CogReader struct. Reworded the previous panic message into an unimplemented error with a more helpful message that dtypes other than float32 are not yet supported.
Move the previous tiff-decoder -> Vec -> ndarray code to an impl method under CogReader. Was going to separate the as_vec and ndarray code, but got caught up with move semantics when trying to use the methods in pyo3, so just having an all-in-one ndarray method now. Added a unit test to check that an ndarray is properly returned.
weiji14
changed the title
♻️ Turn TIFF to ndarray decoding code into CogReader methods
❇️ CogReader ndarray method to decode TIFF into an ndarray Array
Mar 14, 2024
weiji14
changed the title
❇️ CogReader ndarray method to decode TIFF into an ndarray Array
✨ CogReader ndarray method to decode TIFF into an ndarray Array
Mar 14, 2024
weiji14
commented
Mar 15, 2024
Comment on lines
+24
to
+41
/// Decode GeoTIFF image to an [`ndarray::Array`] | ||
fn ndarray(&mut self) -> TiffResult<Array2<f32>> { | ||
// Get image dimensions | ||
let (width, height): (u32, u32) = self.decoder.dimensions()?; | ||
|
||
// Get image pixel data | ||
let decode_result = self.decoder.read_image()?; | ||
let image_data: Vec<f32> = match decode_result { | ||
DecodingResult::F32(img_data) => img_data, | ||
_ => unimplemented!("Data types other than float32 are not yet supported."), | ||
}; | ||
|
||
// Put image pixel data into an ndarray | ||
let vec_data = Array2::from_shape_vec((height as usize, width as usize), image_data) | ||
.map_err(|_| TiffFormatError::InvalidDimensions(height, width))?; | ||
|
||
Ok(vec_data) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was playing around with wrapping parts of this in a TryFrom
trait, but got caught up fighting the borrow checker when trying to use it in another part of the crate, so will leave things here for now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Moving more of the TIFF decoding functionality from the
read_geotiff
function to impl methods under theCogReader
struct that was made in #7. Nothing new actually, same-ish code from #3.TODO:
Create(merged into oneas_vec
method for decoding TIFF toVec
ndarray
function below)ndarray
method for decoding TIFF toVec
and then converting to an ndarrayArray