Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: autocontrast() got an unexpected keyword argument 'preserve_tone' #125

Open
NonaSuomy opened this issue Jun 23, 2023 · 1 comment

Comments

@NonaSuomy
Copy link

NonaSuomy commented Jun 23, 2023

Trying to use linedraw.py get this error. What modifications did you make to linedraw from the original git as I can't see this preserve_tone command in the original linedraw.py what would I need to do if I run the original from here https://github.com/LingDong-/linedraw to make it work with the brachiograph?

Thank you.

python
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from linedraw import *
>>> image_to_json("africa", draw_contours=2, draw_hatch=16)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/BrachioGraph/linedraw.py", line 40, in image_to_json
    lines = vectorise(
  File "/home/pi/BrachioGraph/linedraw.py", line 129, in vectorise
    image = ImageOps.autocontrast(image, 5, preserve_tone=True)
TypeError: autocontrast() got an unexpected keyword argument 'preserve_tone'

Edit: Looked at pillow project found this info

>>> Image.__version__
'8.1.2'
[ImageOps](https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#module-PIL.ImageOps) Module
The [ImageOps](https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#module-PIL.ImageOps) module contains a number of ‘ready-made’ image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images.

New in version 1.1.3.

PIL.ImageOps.autocontrast(image, cutoff=0, ignore=None, mask=None, preserve_tone=False)[[source]](https://pillow.readthedocs.io/en/stable/_modules/PIL/ImageOps.html#autocontrast)
Maximize (normalize) image contrast. This function calculates a histogram of the input image (or mask region), removes cutoff percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255).

PARAMETERS:
image – The image to process.

cutoff – The percent to cut off from the histogram on the low and high ends. Either a tuple of (low, high), or a single number for both.

ignore – The background pixel value (use None for no background).

mask – Histogram used in contrast operation is computed using pixels within the mask. If no mask is given the entire image is used for histogram computation.

preserve_tone –

Preserve image tone in Photoshop-like style autocontrast.

New in version 8.2.0.

So I guess maybe it's missing from the default version installed.

@NonaSuomy
Copy link
Author

NonaSuomy commented Jun 23, 2023

python3 -m pip install --upgrade pip
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pip in /usr/lib/python3/dist-packages (20.3.4)
Collecting pip
  Downloading https://www.piwheels.org/simple/pip/pip-23.1.2-py3-none-any.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 330 kB/s
Installing collected packages: pip
  WARNING: The scripts pip, pip3 and pip3.9 are installed in '/home/pi/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.1.2
python3 -m pip install --upgrade Pillow
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (8.1.2)
Collecting Pillow
  Downloading Pillow-9.5.0-cp39-cp39-manylinux_2_28_aarch64.whl (3.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 4.0 MB/s eta 0:00:00
Installing collected packages: Pillow
Successfully installed Pillow-9.5.0
python
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> Image.__version__
'9.5.0'
>>> from linedraw import *
>>> image_to_json("africa", draw_contours=2, draw_hatch=16)
Generating contours...
Finding edges...
Getting contour points...
Connecting contour points...
Getting contour points...
Connecting contour points...
Optimising line sequence...
Reduced 34 lines to 31 lines.
Optimising line sequence...
Reduced 437 lines to 189 lines.
220 lines, 997 segments.
Generating svg file...

Now it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant