1. A method for edge detection, the method comprises: obtaining an image of an area of a lithographic mask; wherein the image is generated by an optical system that is partially coherent; calculating a gradient of the image and a second derivative of the image in a direction of the gradient of the image; calculating a function that is proportional to the second derivative of the image in the direction of the gradient of the image and is inversely proportional to a ratio between a square of the gradient of the image and the image; and detecting at least one edge of at least one feature of the area in response to values of the function.