svdcompressionimage


Namesvdcompressionimage JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryA Python package for image compression using Singular Value Decomposition (SVD), applying an efficient block-based method to reduce storage while retaining visual quality.
upload_time2024-08-13 01:43:34
maintainerNone
docs_urlNone
authorKatie Wen-Ling Kuo
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Image Compression
It is an image compression Python package based on Singular Value Decomposition (SVD) technology. This tool offers an efficient block-based image compression method, reducing the storage requirements of images by dividing them into blocks and applying SVD, while retaining as much visual information as possible.

## Update Description

### 1. Extended Input Support
**Improvement**: In the new version, the `compress_image_with_svd` function now directly accepts PIL Image objects as input, rather than being limited to file paths. This enhancement simplifies the image processing workflow, avoiding additional image loading steps and making it more suitable for scenarios where images need to be processed multiple times.

### 2. Region Merging and Color Quantization
**New Features**: Added the `region_growing` and `quantize_image` functions. The `region_growing` function reduces the complexity of the image by identifying and merging regions with similar colors, thereby achieving more efficient compression. The `quantize_image` function uses color quantization techniques to reduce the number of colors in the image to a specified number, further optimizing the compression ratio.

**Optimization Effect**: By combining region merging and color quantization, the efficiency of image compression can be significantly improved while maintaining high visual quality. This is particularly suitable for images with large areas of the same or similar colors.


## Installation

```bash
pip install .
```

## Usage

```Python
#%% package
from svdcompressionimage import compress_image_with_svd, quantize_image, region_growing
import os
from PIL import Image, ImageFilter

#%% path
image_path = 'YOUR_IMAGE_PATH.jpg'
image = Image.open(image_path)

#%% mkdir --> exist?
output_dir = 'THE_FOLDER_YOU_WANT_TO_PLACE'
os.makedirs(output_dir, exist_ok = True)

#%% region --> color
merged_image = region_growing(image, tolerance = 10)
quantized_image = quantize_image(merged_image, n_colors)

#%% block & rank
block_size = # YOU CAN USE 16, 32, 64, 128...
rank = # YOU CAN SET `RANK = NONE` TO AUTOMATICALLY SELECT THE NUMBER OF SINGULAR VALUES. YOU CAN ALSO SET IT MANUALLY; THE SMALLER THE VALUE OF `RANK`, THE STRONGER THE COMPRESSION BUT LESS INFORMATION IS RETAINED. THE LARGER THE VALUE, THE WEAKER THE COMPRESSION BUT MORE INFORMATION IS PRESERVED.

#%% compression & sharp
compressed_image = compress_image_with_svd(quantized_image, 
                                           block_size = block_size, 
                                           rank = rank)
compressed_image = compressed_image.filter(ImageFilter.SHARPEN)

#%% save
compressed_image.save(os.path.join(output_dir, 'THE_IMAGE_NAME_YOU_WANT_TO_ACCESS.jpg')) # SUPPORTS INPUT AND OUTPUT IN MULTIPLE IMAGE FORMATS, SUCH AS JPEG, PNG, BMP, SUITABLE FOR DIFFERENT APPLICATION SCENARIOS.

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "svdcompressionimage",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Katie Wen-Ling Kuo",
    "author_email": "katie20030705@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/11/48/81fd550284927e685ac7501576ba656ac509c7258f96bc6d8fba87766d29/svdcompressionimage-0.1.2.tar.gz",
    "platform": null,
    "description": "# Image Compression\r\nIt is an image compression Python package based on Singular Value Decomposition (SVD) technology. This tool offers an efficient block-based image compression method, reducing the storage requirements of images by dividing them into blocks and applying SVD, while retaining as much visual information as possible.\r\n\r\n## Update Description\r\n\r\n### 1. Extended Input Support\r\n**Improvement**: In the new version, the `compress_image_with_svd` function now directly accepts PIL Image objects as input, rather than being limited to file paths. This enhancement simplifies the image processing workflow, avoiding additional image loading steps and making it more suitable for scenarios where images need to be processed multiple times.\r\n\r\n### 2. Region Merging and Color Quantization\r\n**New Features**: Added the `region_growing` and `quantize_image` functions. The `region_growing` function reduces the complexity of the image by identifying and merging regions with similar colors, thereby achieving more efficient compression. The `quantize_image` function uses color quantization techniques to reduce the number of colors in the image to a specified number, further optimizing the compression ratio.\r\n\r\n**Optimization Effect**: By combining region merging and color quantization, the efficiency of image compression can be significantly improved while maintaining high visual quality. This is particularly suitable for images with large areas of the same or similar colors.\r\n\r\n\r\n## Installation\r\n\r\n```bash\r\npip install .\r\n```\r\n\r\n## Usage\r\n\r\n```Python\r\n#%% package\r\nfrom svdcompressionimage import compress_image_with_svd, quantize_image, region_growing\r\nimport os\r\nfrom PIL import Image, ImageFilter\r\n\r\n#%% path\r\nimage_path = 'YOUR_IMAGE_PATH.jpg'\r\nimage = Image.open(image_path)\r\n\r\n#%% mkdir --> exist?\r\noutput_dir = 'THE_FOLDER_YOU_WANT_TO_PLACE'\r\nos.makedirs(output_dir, exist_ok = True)\r\n\r\n#%% region --> color\r\nmerged_image = region_growing(image, tolerance = 10)\r\nquantized_image = quantize_image(merged_image, n_colors)\r\n\r\n#%% block & rank\r\nblock_size = # YOU CAN USE 16, 32, 64, 128...\r\nrank = # YOU CAN SET `RANK = NONE` TO AUTOMATICALLY SELECT THE NUMBER OF SINGULAR VALUES. YOU CAN ALSO SET IT MANUALLY; THE SMALLER THE VALUE OF `RANK`, THE STRONGER THE COMPRESSION BUT LESS INFORMATION IS RETAINED. THE LARGER THE VALUE, THE WEAKER THE COMPRESSION BUT MORE INFORMATION IS PRESERVED.\r\n\r\n#%% compression & sharp\r\ncompressed_image = compress_image_with_svd(quantized_image, \r\n                                           block_size = block_size, \r\n                                           rank = rank)\r\ncompressed_image = compressed_image.filter(ImageFilter.SHARPEN)\r\n\r\n#%% save\r\ncompressed_image.save(os.path.join(output_dir, 'THE_IMAGE_NAME_YOU_WANT_TO_ACCESS.jpg')) # SUPPORTS INPUT AND OUTPUT IN MULTIPLE IMAGE FORMATS, SUCH AS JPEG, PNG, BMP, SUITABLE FOR DIFFERENT APPLICATION SCENARIOS.\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python package for image compression using Singular Value Decomposition (SVD), applying an efficient block-based method to reduce storage while retaining visual quality.",
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95f3bbdd3ff14fe9a3d5dfbc1830653588b286aefcfda3f02e9d4b391c7128b4",
                "md5": "dfe1aa3e9f1612651069c8bbc884690a",
                "sha256": "fa66fead478e310c1df303be80ea4deb68e9e3283d02e9133fefcadd5fc6a026"
            },
            "downloads": -1,
            "filename": "svdcompressionimage-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dfe1aa3e9f1612651069c8bbc884690a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6157,
            "upload_time": "2024-08-13T01:43:33",
            "upload_time_iso_8601": "2024-08-13T01:43:33.356220Z",
            "url": "https://files.pythonhosted.org/packages/95/f3/bbdd3ff14fe9a3d5dfbc1830653588b286aefcfda3f02e9d4b391c7128b4/svdcompressionimage-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "114881fd550284927e685ac7501576ba656ac509c7258f96bc6d8fba87766d29",
                "md5": "415e54cf1ed1f5a09f7b892c20e54fc8",
                "sha256": "bbd97a20435699fecfa2baa8616de7c3f19d56df90f7577bf0f4d66dc5d1cf1d"
            },
            "downloads": -1,
            "filename": "svdcompressionimage-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "415e54cf1ed1f5a09f7b892c20e54fc8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5673,
            "upload_time": "2024-08-13T01:43:34",
            "upload_time_iso_8601": "2024-08-13T01:43:34.759176Z",
            "url": "https://files.pythonhosted.org/packages/11/48/81fd550284927e685ac7501576ba656ac509c7258f96bc6d8fba87766d29/svdcompressionimage-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-13 01:43:34",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "svdcompressionimage"
}
        
Elapsed time: 0.62133s