Skip to content

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

@NonaSuomy

Description

@NonaSuomy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions