1

so i am using loops to get each pixels in an image, but i am getting an error which i don't understand.I am using for in range loop to do this

height,width=img.shape

when i log these it gives the result alright. The dimensions are being logged, but then when i loop it gives error. I have seen a lot of code use this, but now it is giving some error. What is happening here?

for i in range(0, height):
TypeError: 'int' object is not callable

The code for the loop looks like:

p =[]
p.append(5000)
p.append(0)
p.append(5000)
p.append(0)
for i in range(0, height):
  for j in range(0, width):
    if mask[i][j]==0:
        if i<p[0]:
            p[0]=i
        if i>p[1] :
            p[1] = i
        if j<p[2]:
            p[2]=j
        if j>p[3] :
            p[3] = j
    else:
        img[i,j]=[255,255,255]
2
  • The code as it is works without any error, still something is missing from your code! Commented May 16, 2019 at 8:23
  • I cannot reproduce your problem. The code you posted works just fine. Please, make sure that you create a minimal reproducible example which accurately reproduces the problem in the most minimal way possible without requiring any external resources. Commented May 16, 2019 at 8:28

1 Answer 1

10

You have redefined the range name into an int, if you do type(range) it will return int instead of range

You can even get back to the old method using this lines of code :

range = 5  # Oh no ! I made a mistake !


import builtins
range = builtins.range  # Get back the original method

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.