Skip to main content

This library change black pixels to invisible.

Project description

Black Pixel Convertor

This library change black pixels to invisible.
For example, you can use it to convert satellite images.

It will act by following sequence.

  1. Load image by pillow
  2. Convert it to numpy array.
  3. patch images
  4. Traverse patches and check should change.
  5. Convert alpha value in pixel. - RGBA
  6. Unpatch and change array to image.
  7. Compress and save.

Install

pip install black-pixel-convertor

requirements

  • numpy == 1.26.4
  • patchify == 0.2.3
  • pillow == 10.2.0

How to use

from bpc import Config, Convertor

config = Config()

convertor = Convertor(path="file_located_path", out_path="image_will_save_in_this_path")

convertor.multiple_convert()
convertor.single_convert(name="original_name.png", out_name="output_name.png")

Parameters

- config

"""
Config.__init__

cpu_amount
- type: int
- default: 2 / 3 of your cpu core amount
- notice: Do not set upper than core amount.

max_range
- type: int
- default: 10
- describe: max of black pixel amount you can permit in patch.

common_param
- type: int
- default: 100
- describe: height, width, step of each patch
- notice: 
    - if `common_param` is too small, time to spend will be increase
    - furthermore `common_param`is too big, image can't convert black pixels.
    - You have to find compromise point well.

compress_level
- type: int
- default: 4
- describe: 
    - compress level for saving image after convert.
    - you can get more details in pillow document. 
    - https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html
- notice:
    - It is same kind of common_param. 
    - Get compromise point of you image size.
    - else is same as pillow.


black_pixel_level
- type: int
- default: 0
- describe: 
    - standard of black pixel.
    - pixel where each R, G, B value is smaller than black_pixel_level separate as black.

max_image_pixels
- type: int
- default: 933120000
- describe: max pixel amount of your images to convert.
- notice: Be careful about Image ddos attack.

"""

- convertor

""" 
Convertor.__init__

~ `path` and `out_path` can be same

path
- type: str
- notice

out_path
- type: str
- notice


Convertor.single_convert

name
- type: str
- describe: name of the file to convert. 
- notice:
    - It can't be None!
    - You have to write extension(.png, .jpg) together!

out_name
- type: str
- default: `name` + `_Pad_out.png`
- describe:
    - File name of output after convert.
    - if `out_name` is None, `_Pad_out.png` will appended to name.


Convertor.multiple_convert

~ Convert all images(png, jpg) in `path` and return to `out_path`.
~ Name of output will be `filename` + `_Pad_out.png`  

"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

black-pixel-convertor-0.0.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

black_pixel_convertor-0.0.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file black-pixel-convertor-0.0.2.tar.gz.

File metadata

  • Download URL: black-pixel-convertor-0.0.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.0

File hashes

Hashes for black-pixel-convertor-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fd789d71f735ba2b17629d7f497d871e431322e290d77ec1a3c50b5e97d80c08
MD5 1f68c0178211acfc64d30bf8ce833326
BLAKE2b-256 dd61091ad2ebe69b628d9857b56a2ac59942e07d1fdad8c5f5f6aac0c3da2208

See more details on using hashes here.

File details

Details for the file black_pixel_convertor-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for black_pixel_convertor-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bf49952a1fa6be882ff9fb59cba31488f96ef0ed984eb0ddc0b46d456f2a813a
MD5 79d478e2b733f3aa4902f674aa15bd1c
BLAKE2b-256 e763b5136cafc1f21edee691e2cc266b78280f8afe220a3d472f32ab4f5df131

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page