Perimeter of Binary image

  • 0


    Given an Image grid with pixels of values 1 and 0 and a starting pixel, 1 being black and 0 being white, find all the connected black pixel's perimeter(bold 1's in image grid)

    Def findperimeter(image, num_rows ,num_cols, start_row, start_col):
    return perimeter

    image =

    start_row = image[1][1]
    How's perimeter calculated? for every blackpixel- check for pixels other than black in surrounding and add all non-black pixels
    In this question,
    For start black pixel: check for top, bottom and left and right for non black pixel:
    value : 3 (all striked out pixels)
    calculate as such for every connected black pixel and return cumulative perimeter = 3+2+2+2+3 = 12

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.