Your task is to write a program that takes an input image and run it through edge-detection to become an output image.
The edge-detection works as follows (if unclear, see sobel edge detection):
- The value for a pixel is the total brightness of a pixel, so if it is in color, you will need to convert it to grayscale first (to keep things simple and golf-able, you can take the average value for R, G and B).
- The formulae for Gx and Gy for pixel p(i,j) are:
- Gx = -1 * p(i-1, j-1) - 2 * p(i-1, j) - 1 * p(i-1, j+1) + 1 * p(i+1, j-1) + 2 * p(i+1, j) + 1 * p(i+1, j+1)
- Gy = -1 * p(i-1, j-1) - 2 * p(i, j-1) - 1 * p(i+1, j-1) + 1 * p(i-1, j+1) + 2 * p(i, j+1) + 1 * p(i+1, j+1)
- The value for the size of the edge at that pixel is then: √(Gx2 + Gy2)
The output image is for each pixel the size of the edge √(Gx2 + Gy2) as greyscale.
- Perform a gaussian blur to smooth out the image before edge-detection kicks in, to omit any smaller edges. This gives a bonus of -30% on the end result.
- Take the angle of the edge in account. You give the output pixel some color, by taking the same greyscale value and adding color from a color wheel using the angle obtained from the formula arctan(Gy/Gx). This gives another bonus of -30% on the end result.
- You may omit the value for the edgepixels, and set them to black, or you may use 0 for any pixel outside the image.
- Your ouput image must be in an image format that can be opened on most computers.
- Output must be written to disk or be pipeable to a file.
- Input is given as a commandline argument, in the form of a relative path to the image, or piped in from the commandline.
- This is code golf, so shortest code in bytes wins!