TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

Lipstick

I try to use Moravec detection. When I try to run this code I get some error:

     diff = diff - image.getpixel((x, y))
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

How can I fix it? Any help will be appreciated. The code is:

def moravec(image, threshold = 100):
    """Moravec's corner detection for each pixel of the image."""

    corners = []
    xy_shifts = [(1, 0), (1, 1), (0, 1), (-1, 1)]

    for y in range(1, image.size[1]-1):
        for x in range(1, image.size[0]-1):
            # Look for local maxima in min(E) above threshold:
            E = 100000
            for shift in xy_shifts:
                diff = image.getpixel((x + shift[0], y + shift[1]))
                diff = diff - image.getpixel((x, y))
                diff = diff * diff
                if diff < E:
                    E = diff
            if E > threshold:
                corners.append((x, y))

    return corners

if __name__ == "__main__":
        threshold = 100

        image = Image.open('all.jpg')
        corners = moravec(image, threshold)
        draw_corners(image, corners)
        image.save('low2.png')
aldanor

You're trying to substract two tuples (with RGB values), and arithmetic operations on tuples like * and - are not defined.

To find the distance, you could just do this:

c1 = image.getpixel((x + shift[0], y + shift[1]))
c2 = image.getpixel((x, y))
diff = (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2
if diff < E:
    E = diff

Hypothetically also could use numpy to get the dot products and arithmetic operations working out of the box if that's what you're used to, although it's a bit of an overkill:

import numpy as np

c1 = image.getpixel((x + shift[0], y + shift[1]))
c2 = image.getpixel((x, y))
diff = (np.diff([c1, c2]) ** 2).sum()
if diff < E:
    E = diff

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: unsupported operand type(s) for |: 'tuple' and 'bool'

From Dev

TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

From Dev

TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' with random generator?

From Dev

unsupported operand type(s) for +: 'int' and 'tuple'

From Dev

Python: unsupported operand type(s) for /: 'tuple' and 'float'

From Dev

CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

From Dev

CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

From Dev

TypeError: 'in <string>' requires string as left operand, not tuple

From Dev

Having issues with formatters: "unsupported operand type(s) for %: 'NoneType' and 'tuple'"

From Dev

python & Mysql: unsupported operand type(s) for -: 'int' and 'tuple'

From Dev

What does "unsupported operand type(s) for -: 'int' and 'tuple'" means?

From Dev

Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

From Dev

python & Mysql: unsupported operand type(s) for -: 'int' and 'tuple'

From Dev

Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

From Dev

Having issues with formatters: "unsupported operand type(s) for %: 'NoneType' and 'tuple'"

From Dev

Unsupported operand types 'NoneType'

From Dev

Django unsupported operand types

From Dev

groupby python TypeError: unorderable types: tuple() < str()

From Dev

Trying to average a list, but I don't know what is meant by the error: unsupported operand type(s) for +: 'int' and 'tuple'

From Dev

unsupported operand types for //: 'str', 'int'

From Dev

unsupported operand types for * : 'float' and 'decimal'

From Dev

TypeError: unsupported operand type in Python

From Dev

deducing a tuple's types

From Dev

A seq of tuple with adhoc types?

From Dev

How to determine tuple types?

From Dev

Defining Tuple types

From Dev

TypeError: tuple indices must be integers, not tuple

From Dev

TypeError: tuple indices must be integers, not tuple

Related Related

  1. 1

    TypeError: unsupported operand type(s) for |: 'tuple' and 'bool'

  2. 2

    TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

  3. 3

    TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

  4. 4

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' with random generator?

  5. 5

    unsupported operand type(s) for +: 'int' and 'tuple'

  6. 6

    Python: unsupported operand type(s) for /: 'tuple' and 'float'

  7. 7

    CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

  8. 8

    CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

  9. 9

    TypeError: 'in <string>' requires string as left operand, not tuple

  10. 10

    Having issues with formatters: "unsupported operand type(s) for %: 'NoneType' and 'tuple'"

  11. 11

    python & Mysql: unsupported operand type(s) for -: 'int' and 'tuple'

  12. 12

    What does "unsupported operand type(s) for -: 'int' and 'tuple'" means?

  13. 13

    Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

  14. 14

    python & Mysql: unsupported operand type(s) for -: 'int' and 'tuple'

  15. 15

    Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

  16. 16

    Having issues with formatters: "unsupported operand type(s) for %: 'NoneType' and 'tuple'"

  17. 17

    Unsupported operand types 'NoneType'

  18. 18

    Django unsupported operand types

  19. 19

    groupby python TypeError: unorderable types: tuple() < str()

  20. 20

    Trying to average a list, but I don't know what is meant by the error: unsupported operand type(s) for +: 'int' and 'tuple'

  21. 21

    unsupported operand types for //: 'str', 'int'

  22. 22

    unsupported operand types for * : 'float' and 'decimal'

  23. 23

    TypeError: unsupported operand type in Python

  24. 24

    deducing a tuple's types

  25. 25

    A seq of tuple with adhoc types?

  26. 26

    How to determine tuple types?

  27. 27

    Defining Tuple types

  28. 28

    TypeError: tuple indices must be integers, not tuple

  29. 29

    TypeError: tuple indices must be integers, not tuple

HotTag

Archive