Sort by

recency

|

8 Discussions

|

  • + 0 comments

    Could have used Plain Text instead as an easier option. Psst, the answer is 59 in the Plain Text.

  • + 0 comments

    DON'T UNDERSTAND WHY RUNTIME ERROR, MY PROGRAM IS IN PYTHON3

                    
    import cv2
    import numpy as np
    
    im = np.array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  ],
                    [ 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,  ],
                    [ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,  ],
                    [ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,  ],
                    [ 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,  ],
                    [ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,  ],
                    [ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,  ],
                    [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  ],
                    [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  ]], dtype = np.uint8)
    
    kernel = np.ones((3,3), dtype = np.uint8)
    
    
    img_dilation = cv2.dilate(im, kernel, iterations=1) 
    
    print(int(np.sum((img_dilation == 1))))
    
  • + 0 comments

    import numpy as np

    img = np.array([ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ])

    def dilation(image): count = 0

    for i in range(image.shape[0] - 1): 
        for j in range(image.shape[1] - 1): 
            if image[i][j] == 1: 
                count += 1
            elif (
                image[i-1][j] == 1 or 
                image[i+1][j] == 1 or 
                image[i][j-1] == 1 or 
                image[i][j+1] == 1 or 
                image[i-1][j-1] == 1 or 
                image[i-1][j+1] == 1 or 
                image[i+1][j-1] == 1 or 
                image[i+1][j+1] == 1
            ): 
                count += 1
    
    return count 
    

    result = dilation(img) print(int(result))

  • + 0 comments
    import numpy as np
    import matplotlib.pyplot as plt
    from skimage.io import imread, imshow
    from skimage.draw import disk
    from skimage.morphology import (erosion, dilation, closing, opening,
                                    area_closing, area_opening)
    from skimage.color import rgb2gray
    
    a = np.array([
        [0,0,0,0,0,0,0,0,0,0],
        [0,1,1,1,1,1,1,1,0,0],
        [0,0,0,0,1,1,1,1,0,0],
        [0,0,0,0,1,1,1,1,0,0],
        [0,0,0,1,1,1,1,1,0,0],
        [0,0,0,0,1,1,1,1,0,0],
        [0,0,0,1,1,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]
    ])
    
    s = np.array([
            [1,1,1],
            [1,1,1],
            [1,1,1]])
    
    unique, freq = np.unique(dilation(a,s), return_counts=True)
    print(freq[1])
    
  • + 0 comments

    There is no any information about input, can you post instructions?