I'm writing a program that does basic image processing.

Keep in mind that the images are in grayscale, not RGB, also, I'm fairly new to Python, so an explanation of what I'm doing wrong/right would be incredibly helpful.

I'm trying to write an outline algorithm that follows this set of rules:

All light pixels in the original must be white in the outline image. All dark pixels on the edges of the image must be black in the outline image. If a pixel that is not on an edge of the image is dark and all of the 8 surrounding pixels are dark, this pixel is on the inside of a shape and must be white in the outline image. All other dark pixels must be black in the outline image.

So far I have this:

def outlines(image): """ Finds the outlines of shapes in an image. The parameter must be a two-dimensional list of pixels. The return value is another two-dimensional list of pixels which describes an image showing outlines of the shapes in the original image. Each pixel in the return value will be either black (0) or white (255). """ height=len(image) width=len(image[0]) new_image=[] for r in range(height): new_row=[] index=0 for c in range(width): if image[r][c]>128: new_row.append(255) if image[r][c]<=128: new_row.append(0]) new_image.append(new_row)

Can someone show me how to implement the algorithm into my outlines function?

Thanks in advance. Edit: This is an assignment for my University Comp Sci class, I'm not asking for someone to do my homework, rather because I've virtually no idea what the next step is. Edit2: If someone could explain to me a simple edge detection function that is similar to the algorithm I need to create I would appreciate it.