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

Refactor ImageConvertor and add Convert and Grayscale preprocessors #256

Merged
merged 15 commits into from
Oct 11, 2021

Conversation

juliabeliaeva
Copy link
Contributor

@juliabeliaeva juliabeliaeva commented Oct 4, 2021

This PR has the following changes:

  1. Refactored ImageConvertor to support more image types (TYPE_3BYTE_BGR, TYPE_INT_BGR, TYPE_INT_RGB, TYPE_BYTE_GRAY are tested, but the code should work for other types).
  2. Replaced Loading#colorMode with a separate preprocessor Convert to convert the image to the desired type. colorMode was used only for transforming BufferredImage into FloatArray and does not seem to belong to Loading operation. After this refactoring image is transformed to floats "as is" and conversions are performed during image preprocessing stage. This change will also simplify Loading operation refactoring necessary for [Preprocessing] Split the Load preprocessing stage into two parts: LoadFile and LoadDir #227.
  3. ImageShape#channels is made nullable. This will allow to define image shape when the number of channels is not known and to keep the same number of channels as in the original image in preprocessors such as resize.
  4. ColorOrder is renamed to ColorMode and now represents a more generic "image type".
  5. grayscale preprocessor is added as a Convert operation with ColorMode.GRAYSCALE target. Fixes Add Grayscale image preprocessor #202.

@zaleslaw
Copy link
Collaborator

zaleslaw commented Oct 7, 2021

@juliabeliaeva On first review it looks well, could you please merge the master into this branch and I'll start the final review and play with the new DSL in the sandbox, I want to test on different images

@zaleslaw zaleslaw added the Review This PR is under review label Oct 7, 2021
@zaleslaw zaleslaw added this to the 0.4 milestone Oct 7, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
When image data is not stored in bytes, use method getPixels to retrieve floats. Since this method always returns channels in the rgb order, swap channels when bgr order is required.
Null value will mean that the number of channels is not known.
@juliabeliaeva
Copy link
Contributor Author

@zaleslaw rebased on master to avoid extra merge commits.

@zaleslaw
Copy link
Collaborator

No objection from my side regarding this PR, very highly qualified work

@zaleslaw zaleslaw added LGTM PR reviewed and is ready to merge and removed Review This PR is under review labels Oct 11, 2021
@zaleslaw zaleslaw merged commit b6dd921 into Kotlin:master Oct 11, 2021
michalharakal pushed a commit to michalharakal/KotlinDL that referenced this pull request Nov 30, 2021
…otlin#256)

* Convert ImageConverter from class to object

* Remove unused parameter

* Reorganize methods in ImageConverter

* Cleanup imageToByteArray

* Support more image types in ImageConverter

When image data is not stored in bytes, use method getPixels to retrieve floats. Since this method always returns channels in the rgb order, swap channels when bgr order is required.

* Add tests for ImageConverter

* Add Convert preprocessor

* Remove unused function

* Replace colorMode field from Loading operation with Convert preprocessor

* Rename ColorOrder to ColorMode

* Support grayscale images

* Add Grayscale image preprocessor

* Allow for ImageShape#channels to be nullable

Null value will mean that the number of channels is not known.

* Keep original image type in image preprocessors

* Remove outdated comments
@juliabeliaeva juliabeliaeva deleted the convert-preprocessor branch January 23, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM PR reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Grayscale image preprocessor
2 participants