diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8d231b7b..50d11cbfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: - name: Run PyTest run: pytest --cov . --cov-report=xml -- name: Upload coverage reports to Codecov + - name: Upload coverage reports to Codecov if: matrix.operating-system == 'ubuntu-latest' && matrix.python-version == '3.12' uses: codecov/codecov-action@v4.3.0 with: diff --git a/albumentations/augmentations/transforms.py b/albumentations/augmentations/transforms.py index 3bc65ab73..369a74532 100644 --- a/albumentations/augmentations/transforms.py +++ b/albumentations/augmentations/transforms.py @@ -138,7 +138,6 @@ ] NUM_BITS_ARRAY_LENGTH = 3 -MAX_JPEG_QUALITY = 100 TWENTY = 20 @@ -342,53 +341,10 @@ class InitSchema(BaseTransformInitSchema): AfterValidator(nondecreasing), ] - quality_lower: int | None = Field( - ge=1, - le=100, - ) - quality_upper: int | None = Field( - ge=1, - le=100, - ) compression_type: Literal["jpeg", "webp"] - @model_validator(mode="after") - def validate_ranges(self) -> Self: - # Update the quality_range based on the non-None values of quality_lower and quality_upper - if self.quality_lower is not None or self.quality_upper is not None: - if self.quality_lower is not None: - warn( - "`quality_lower` is deprecated. Use `quality_range` as tuple" - " (quality_lower, quality_upper) instead.", - DeprecationWarning, - stacklevel=2, - ) - if self.quality_upper is not None: - warn( - "`quality_upper` is deprecated. Use `quality_range` as tuple" - " (quality_lower, quality_upper) instead.", - DeprecationWarning, - stacklevel=2, - ) - lower = self.quality_lower if self.quality_lower is not None else self.quality_range[0] - upper = self.quality_upper if self.quality_upper is not None else self.quality_range[1] - self.quality_range = (lower, upper) - # Clear the deprecated individual quality settings - self.quality_lower = None - self.quality_upper = None - - # Validate the quality_range - if not (1 <= self.quality_range[0] <= MAX_JPEG_QUALITY and 1 <= self.quality_range[1] <= MAX_JPEG_QUALITY): - raise ValueError( - f"Quality range values should be within [1, {MAX_JPEG_QUALITY}] range.", - ) - - return self - def __init__( self, - quality_lower: int | None = None, - quality_upper: int | None = None, compression_type: Literal["jpeg", "webp"] = "jpeg", quality_range: tuple[int, int] = (99, 100), p: float = 0.5, @@ -407,12 +363,7 @@ def apply( return fmain.image_compression(img, quality, image_type) def get_params(self) -> dict[str, int | str]: - if self.compression_type == "jpeg": - image_type = ".jpg" - elif self.compression_type == "webp": - image_type = ".webp" - else: - raise ValueError(f"Unknown image compression type: {self.compression_type}") + image_type = ".jpg" if self.compression_type == "jpeg" else ".webp" return { "quality": self.py_random.randint(*self.quality_range), diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 56f7d5b61..17fcf7581 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -1200,26 +1200,6 @@ def test_random_crop_from_borders( assert aug(image=image, mask=image, bboxes=bboxes, keypoints=keypoints) -@pytest.mark.parametrize( - "params, expected", - [ - # Test default initialization values - ({}, {"quality_range": (99, 100), "compression_type": "jpeg"}), - # Test custom quality range and compression type - ( - {"quality_range": (10, 90), "compression_type": "webp"}, - {"quality_range": (10, 90), "compression_type": "webp"}, - ), - # Deprecated quality values handling - ({"quality_lower": 75}, {"quality_range": (75, 100)}), - ], -) -def test_image_compression_initialization(params, expected): - img_comp = A.ImageCompression(**params) - for key, value in expected.items(): - assert getattr(img_comp, key) == value, f"Failed on {key} with value {value}" - - @pytest.mark.parametrize( "params", [