2021-05-10 07:08:09 +02:00
|
|
|
# python-FloatImg
|
|
|
|
|
2021-05-11 13:53:41 +02:00
|
|
|
A pythonesque binding to FloatImg library available at https://git.tetalab.org/tTh/FloatImg
|
|
|
|
|
2021-05-12 13:57:49 +02:00
|
|
|
python-FloatImg requires a Python 3 implementation (tested with 3.6.9).
|
|
|
|
|
|
|
|
Most function are wrapped into a similar api, sometime with a more consistent naming and an object-oriented approach.
|
|
|
|
|
|
|
|
Color values are specified using triplets of float values, like (128.5, 34.234, 242.23).
|
2021-05-11 13:53:41 +02:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
python-FloatImg requires a shared object file (.so) that is not yet officialy available from FloatImg.
|
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
The file `floatimg/settings.py` contains the path to the .so file and the encoding of path characters.
|
2021-05-11 13:53:41 +02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```python
|
2021-05-12 08:28:06 +02:00
|
|
|
import floatimg
|
2021-05-11 13:53:41 +02:00
|
|
|
```
|
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
The FloatImg class encapsulate core and file functionnalities of FloatImg library. Instances are created with functions from the module.
|
|
|
|
|
|
|
|
Colors are tuple of three elements `(r, g, b)`.
|
|
|
|
|
2021-05-11 13:53:41 +02:00
|
|
|
### Image creation
|
|
|
|
|
|
|
|
`FloatImg` has two class methods to create an image.
|
|
|
|
|
|
|
|
```python
|
2021-05-12 08:28:06 +02:00
|
|
|
img = floatimg.create(640, 480, floatimg.RGB)
|
2021-05-11 13:53:41 +02:00
|
|
|
```
|
|
|
|
Or use the `create_rgb` shortcut:
|
|
|
|
|
|
|
|
```python
|
2021-05-12 08:28:06 +02:00
|
|
|
img = floatimg.create_rgb(640, 480)
|
2021-05-11 13:53:41 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Note that calling the `destroy` method of the instance is not necessary as it will be called automatically at instance destruction.
|
|
|
|
|
|
|
|
Or completely duplicate an existing image:
|
|
|
|
|
|
|
|
```python
|
2021-05-12 08:28:06 +02:00
|
|
|
# without copying data
|
2021-05-11 13:53:41 +02:00
|
|
|
new_img = img.clone()
|
2021-05-12 08:28:06 +02:00
|
|
|
|
|
|
|
# with copying data
|
2021-05-12 13:57:49 +02:00
|
|
|
new_img = img.clone(True)
|
2021-05-11 13:53:41 +02:00
|
|
|
```
|
|
|
|
|
2021-05-16 11:45:00 +02:00
|
|
|
### Basic pixel operations
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
```python
|
|
|
|
# Get pixel value
|
|
|
|
color = (r, g, b) = img.get(x, y)
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# Set pixel value
|
|
|
|
img.put(x, y, (r, g, b))
|
2021-05-12 13:57:49 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# Reset all pixels to zero.
|
2021-05-11 13:53:41 +02:00
|
|
|
img.clear()
|
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# Copy pixels to another image of the same format
|
2021-05-11 13:53:41 +02:00
|
|
|
img.copy_data(another_img)
|
|
|
|
```
|
|
|
|
|
2021-05-16 11:45:00 +02:00
|
|
|
### File operations
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
#### Raw dump files
|
2021-05-11 13:53:41 +02:00
|
|
|
|
|
|
|
```python
|
2021-05-14 09:11:35 +02:00
|
|
|
# Dump image to file
|
|
|
|
img.dump(path)
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# Restore image data from a dump file
|
|
|
|
img.load(path)
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# Create a new image from a dump file
|
|
|
|
img = floatimg.create_from_dump(path)
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# Get dump metadata (TODO create a FileInfo named tuple)
|
|
|
|
witdh, height, img_type = floatimg.fileinfos(path)
|
2021-05-11 13:53:41 +02:00
|
|
|
```
|
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
#### External formats
|
2021-05-11 13:53:41 +02:00
|
|
|
|
|
|
|
```python
|
2021-05-14 09:11:35 +02:00
|
|
|
# export supports the following extentions : .fimg, .png, .tiff, .pnm, .fits
|
|
|
|
# save as png
|
|
|
|
img.export("test.png")
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# create an image instance from png file
|
|
|
|
img = floatimg.create_from_png("test.png")
|
2021-05-11 13:53:41 +02:00
|
|
|
|
2021-05-14 09:11:35 +02:00
|
|
|
# load pixel data from png file in an existing instance. size and type have to be compatible
|
|
|
|
img.load_png("test.png")
|
2021-05-11 13:53:41 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2021-05-14 06:40:38 +02:00
|
|
|
## Operators
|
|
|
|
|
|
|
|
```python
|
|
|
|
# addition
|
|
|
|
res_img = img + img2
|
|
|
|
|
|
|
|
# substraction
|
|
|
|
res_img = img - img2
|
|
|
|
|
|
|
|
# multiplication
|
|
|
|
res_img = img * img2
|
|
|
|
|
|
|
|
# min value per color channel
|
|
|
|
res_img = img.min(img2)
|
|
|
|
|
|
|
|
# max value per color channel
|
|
|
|
res_img = img.max(img2)
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2021-05-20 08:34:10 +02:00
|
|
|
## Contrast operations
|
|
|
|
|
|
|
|
Contrast types are defined in the Contrast enumeration:
|
|
|
|
|
|
|
|
```
|
|
|
|
floatimg.Contrast.SQRT
|
|
|
|
floatimg.Contrast.POW2
|
|
|
|
floatimg.Contrast.COS01
|
|
|
|
floatimg.Contrast.COS010
|
|
|
|
```
|
|
|
|
|
|
|
|
To apply contrast:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Return a new image
|
|
|
|
res = img.contrast(value, floatimg.Contrast.SQRT)
|
|
|
|
|
|
|
|
# set contrast in-place
|
|
|
|
img.contrast(value, floatimg.Contrast.SQRT, True)
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2021-05-11 13:53:41 +02:00
|
|
|
|
|
|
|
## Development
|
|
|
|
|
|
|
|
### Run tests
|
|
|
|
|
|
|
|
Install development requirements (you may add --user if not in a virtual environment or not in system-wide install):
|
|
|
|
|
|
|
|
```
|
|
|
|
pip install -r requirements-devel.txt
|
|
|
|
```
|
|
|
|
|
|
|
|
Ensure `floatimg` containing path is in the `PYTHONPATH`, this will run the tests and show a coverage report:
|
|
|
|
|
|
|
|
```
|
|
|
|
pytest --cov=floatimg tests/*
|
|
|
|
```
|
|
|
|
|
2021-05-16 11:45:00 +02:00
|
|
|
### Status
|
|
|
|
|
|
|
|
The goal is not to bind all the functions but essential ones too build a front-end with python-tkinter.
|
|
|
|
|
|
|
|
#### Done
|
|
|
|
|
|
|
|
- lib/fimg-core.c
|
|
|
|
- lib/fimg-file.c
|
|
|
|
- lib/operator.c
|
|
|
|
- funcs/exporter.c
|
|
|
|
- funcs/fimg-png.c
|
|
|
|
|
|
|
|
#### Partial
|
|
|
|
|
|
|
|
- lib/fimg-math.c
|