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

added the imageio instead of opencv #59

Merged
merged 2 commits into from
Mar 25, 2024

Conversation

sushmanthreddy
Copy link
Contributor

close #56

Replace OpenCV with imageio for Image Reading and Normalization

This update modifies the CustomImageParam and MaskedImageParam class to remove its dependency on OpenCV for reading images and converting color spaces. Instead, we utilize imageio, which simplifies the process by natively reading images in the desired RGB format and allows for direct normalization without additional steps. The primary change is in the __init__ method, where we replaced OpenCV operations with imageio functionality.

Changes:

  • Removed import for cv2.
  • Added import for imageio.
  • Updated the __init__ method to use imageio.imread for reading the image, automatically handling RGB conversion and normalization.

Code Change:

# Before:
import cv2
...
if isinstance(image, str):
    image = cv2.cvtColor(cv2.imread(image), cv2.COLOR_BGR2RGB)/255.
    image = torch.tensor(image).permute(-1,0,1).unsqueeze(0)

# After:
import imageio
...
if isinstance(image, str):
    image = imageio.imread(image) / 255.0  # Reads in RGB and normalizes
    image = torch.tensor(image).permute(2, 0, 1).unsqueeze(0)

This modification significantly reduces the dependency footprint by eliminating the need for OpenCV, which is a larger library used minimally in this context. It simplifies the codebase and leverages imageio for efficient image processing, making the project lighter and more focused on its specific requirements.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.03%. Comparing base (df90177) to head (0876aa7).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #59   +/-   ##
=======================================
  Coverage   83.03%   83.03%           
=======================================
  Files          22       22           
  Lines         825      825           
=======================================
  Hits          685      685           
  Misses        140      140           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Mayukhdeb Mayukhdeb merged commit bfb1696 into Mayukhdeb:master Mar 25, 2024
3 checks passed
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.

get rid of opencv
3 participants