mercredi 21 octobre 2020

End of line error appearing in the end of the conditional statement

I am trying out some conditional statements but I am getting indentation error at the end of the statement. I am trying to delete the last condition but the error appear again. How to resolve this.

import numpy as np
new_sobel = np.random.randint(100, size=(100,100))
theta= np.random.randint(10, size=(100,100))


MM, NN = new_sobel.shape
Z = np.zeros((MM,NN), dtype=np.int32)
angle = theta * 180. / np.pi
angle[angle < 0] += 180

for i in range(1,MM-1):
    for j in range(1,NN-1):
        try:
            q=255;
            r=255;
            if (0 <= angle[i,j] < 22.5) or (157.5 <= angle[i,j] <= 180):
                        q = new_sobel[i, j+1]
                        r = new_sobel[i, j-1]
                    
            elif (22.5 <= angle[i,j] < 67.5):
                        q = new_sobel[i+1, j-1]
                        r = new_sobel[i-1, j+1]
                    
            elif (67.5 <= angle[i,j] < 112.5):
                        q = new_sobel[i+1, j]
                        r = new_sobel[i-1, j]
                    
            elif (112.5 <= angle[i,j] < 157.5):
                        q = new_sobel[i-1, j-1]
                        r = new_sobel[i+1, j+1]
        
            if (new_sobel[i,j] >= q) and (new_sobel[i,j] >= r):
                        Z[i,j] = new_sobel[i,j]
            else:
                        Z[i,j] = 0

Aucun commentaire:

Enregistrer un commentaire