Repository: mlcommons/GaNDLF

Issue:
Vips installation is a pain and should be made optional, or use something else entirely
**Is your feature request related to a problem? Please describe.**
VIPS (libvips/pyvips) is a major pain to install and use, since it does not install all dependencies from pypi.

**Describe the solution you'd like**
Currently, we are only using VIPS for a resize operation in the unit tests, and this should be either made optional or changed to use another library.

**Describe alternatives you've considered**
Nothing else, since VIPS is just a pain.

**Additional context**
N.A.



Discussion:

Resolving patch:
diff --git a/GANDLF/utils/__init__.py b/GANDLF/utils/__init__.py
--- a/GANDLF/utils/__init__.py
+++ b/GANDLF/utils/__init__.py
@@ -34,7 +34,6 @@
 )
 
 from .generic import (
-    fix_paths,
     get_date_time,
     get_unique_timestamp,
     get_filename_extension_sanitized,
diff --git a/GANDLF/utils/generic.py b/GANDLF/utils/generic.py
--- a/GANDLF/utils/generic.py
+++ b/GANDLF/utils/generic.py
@@ -34,18 +34,6 @@ def checkPatchDivisibility(patch_size, number=16):
     return True
 
 
-def fix_paths(cwd):
-    """
-    This function takes the current working directory of the script (which is required for VIPS) and sets up all the paths correctly
-
-    Args:
-        cwd (str): The current working directory.
-    """
-    if os.name == "nt":  # proceed for windows
-        vipshome = os.path.join(cwd, "vips/vips-dev-8.10/bin")
-        os.environ["PATH"] = vipshome + ";" + os.environ["PATH"]
-
-
 def get_date_time():
     """
     Get a well-parsed date string
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -67,7 +67,6 @@ def run(self):
     "tiffslide",
     "matplotlib",
     "requests>=2.25.0",
-    "pyvips==2.2.1",
     "pytest",
     "coverage",
     "pytest-cov",
@@ -131,20 +130,3 @@ def run(self):
     keywords="semantic, segmentation, regression, classification, data-augmentation, medical-imaging",
     zip_safe=False,
 )
-
-## windows vips installation
-if os.name == "nt":  # proceed for windows
-    from pathlib import Path
-
-    # download and extract if main dll is absent
-    if not Path("./vips/vips-dev-8.10/bin/libvips-42.dll").exists():
-        print("Downloading and extracting VIPS for Windows")
-        url = "https://github.com/libvips/libvips/releases/download/v8.10.2/vips-dev-w64-all-8.10.2.zip"
-        zip_to_extract = "./vips.zip"
-        import urllib.request, zipfile
-
-        urllib.request.urlretrieve(url, zip_to_extract)
-        z = zipfile.ZipFile(zip_to_extract)
-        z.extractall("./vips")
-        z.close()
-        os.remove(zip_to_extract)


Test patch:
diff --git a/testing/test_full.py b/testing/test_full.py
--- a/testing/test_full.py
+++ b/testing/test_full.py
@@ -5,7 +5,7 @@
 import pandas as pd
 
 from pydicom.data import get_testdata_file
-import pyvips as pv
+import cv2
 
 from GANDLF.data.ImagesFromDataFrame import ImagesFromDataFrame
 from GANDLF.utils import *
@@ -1768,11 +1768,12 @@ def test_train_inference_classification_histology_large_2d(device):
     # resize the image
     input_df = pd.read_csv(inputDir + "/train_2d_histo_classification.csv")
     for _, row in input_df.iterrows():
-        img = pv.Image.new_from_file(row["Channel_0"])
-        img_resize = img.resize(10)
+        img = cv2.imread(row["Channel_0"])
+        dims = img.shape
+        img_resize = cv2.resize(img, (dims[1] * 10, dims[0] * 10))
         new_filename = row["Channel_0"].replace(".tiff", "_resize.tiff")
         row["Channel_0"] = new_filename
-        img_resize.tiffsave(new_filename)
+        cv2.imwrite(new_filename, img_resize)
 
     input_df.to_csv(inputDir + "/train_2d_histo_classification_resize.csv", index=False)