Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do I get "IndentationError: expected an indented block" in my code

I want to detect edges in an image. This is the code I used:

fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(15,8))
# Liste des valeurs
Val1 = [50, 100, 400]
Val2 = [50, 100, 400]
for i, val1 in enumerate(Val1):
for j, val2 in enumerate(Val2):
edge_image = cv2.Canny(image, val1 , val2)
axs[i][j].imshow(edge_image, cmap = 'Greys_r')
axs[i][j].set_title((val1,val2))
axs[i][j].set_axis_off()

When I run it I get the error:

File "<ipython-input-16-d6d5d4b1d7c6>", line 6
    for j, val2 in enumerate(Val2):
      ^
IndentationError: expected an indented block

How can I fix this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Python needs indentation to separate code blocks.just like braces does in other languages. try to indent your code with tab or 2 spaces(According to PEP-8).reply if the error still persists.
Your code must indent like this

fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(15,8))
# Liste des valeurs
Val1 = [50, 100, 400]
Val2 = [50, 100, 400]
for i, val1 in enumerate(Val1):
  for j, val2 in enumerate(Val2):
    edge_image = cv2.Canny(image, val1 , val2)
    axs[i][j].imshow(edge_image, cmap = 'Greys_r')
    axs[i][j].set_title((val1,val2))
    axs[i][j].set_axis_off()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading