Skip to content
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

[Images] [3/N] Add image decoding for uint8 images. #981

Merged
merged 4 commits into from
Jun 2, 2023

Conversation

clarkzinzow
Copy link
Contributor

This PR adds basic support for decoding uint8 images.

@clarkzinzow clarkzinzow requested a review from samster25 June 1, 2023 22:38
@@ -58,17 +58,7 @@ impl<'a> DaftImageBuffer<'a> {
with_method_on_image_buffer!(self, width)
}

pub fn channels(&self) -> u16 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have ImageMode::num_chanels(), trying to keep a single source of truth there.

@@ -136,6 +130,44 @@ where
ImageBuffer::from_raw(w, h, owned).unwrap()
}

impl<'a> From<DynamicImage> for DaftImageBuffer<'a> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you intending to take ownership of the buffer of DynamicImage or Borrow the buffer? Right now it's taking ownership.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ownership, since we should only be doing this conversion on ingest (decoding), right? I can change this to borrow the buffer if we think that will be needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine then, we can implement a From<&'a DynamicImage> down the road when/if we need to borrow.

@@ -227,7 +259,6 @@ impl ImageArray {

assert_eq!(result.height(), h);
assert_eq!(result.width(), w);
assert_eq!(result.channels(), c);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep this validation in

Copy link
Contributor Author

@clarkzinzow clarkzinzow Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This DaftImageBuffer::channels() method was duplicating the ImageMode::num_channels() logic, so I'd like to consolidate that to one place if possible. We're also no longer pulling the channels from the DaftImageBuffer in from_daft_image_buffer() (we're pulling from ImageMode::num_channels() instead), so I don't see motivation for continuing to have a DaftImageBuffer::channels() API.

src/series/ops/image.rs Outdated Show resolved Hide resolved
src/series/ops/image.rs Outdated Show resolved Hide resolved
@clarkzinzow clarkzinzow requested a review from samster25 June 2, 2023 00:31
@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #981 (cd47dac) into main (de6d9d3) will decrease coverage by 0.08%.
The diff coverage is 76.30%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #981      +/-   ##
==========================================
- Coverage   85.04%   84.96%   -0.08%     
==========================================
  Files         184      184              
  Lines       15835    15906      +71     
==========================================
+ Hits        13467    13515      +48     
- Misses       2368     2391      +23     
Impacted Files Coverage Δ
src/array/from.rs 77.33% <0.00%> (-4.36%) ⬇️
src/series/ops/image.rs 57.89% <33.33%> (+22.89%) ⬆️
src/datatypes/image_mode.rs 48.86% <56.52%> (+4.24%) ⬆️
src/array/ops/image.rs 88.01% <79.51%> (-7.45%) ⬇️
src/array/ops/cast.rs 89.57% <100.00%> (-0.58%) ⬇️

... and 6 files with indirect coverage changes

src/series/ops/image.rs Outdated Show resolved Hide resolved
pub modes: Vec<u8>,
pub offsets: Vec<i64>,
pub validity: Option<arrow2::bitmap::Bitmap>,
}
Copy link
Contributor Author

@clarkzinzow clarkzinzow Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to keep the ImageArray::from_vecs() function from having a lot of arguments.

@@ -179,6 +226,77 @@ impl ImageArray {
array.as_ref().as_any().downcast_ref().unwrap()
}

pub fn from_vecs<T: arrow2::types::NativeType>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samster25 I consolidated the kernels and casting vecs --> ImageArray construction to this single function, to make sure that those paths don't diverge.

@clarkzinzow clarkzinzow force-pushed the clark/full-image-decoding branch from d59dedf to cd47dac Compare June 2, 2023 15:03
Copy link
Member

@samster25 samster25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clarkzinzow clarkzinzow merged commit 0f5b4b7 into main Jun 2, 2023
@clarkzinzow clarkzinzow deleted the clark/full-image-decoding branch June 2, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants