It's winter, and the time of year has come for it to start getting cold (and for strange colorful headcloths to start appearing... soon). Let's write some code to make avatar pictures and other images frozen over, to fit the theme!
Input
The input to submissions to this challenge should be an image (the image to make frozen) and a number (the threshold, which will be explained later).
You may input the image in any way your language supports them (a file path or URL as an argument, taking it from the clipboard, dragging and dropping an image, etc.) and in any format listed here that expresses colors in RGB (you can support / require RGBA instead if you want, but this is not a requirement).
You can input the number in any way you would like as well (command line argument, STDIN, input dialog, etc.), with the exception of hardcoding it into your program (ex. n=10
). If you use a file path / URL for the image, it must be input in this manner as well.
Output
The program must process the image according to the description below and then output it in any way you would like (to a file, showing it on screen, putting it on the clipboard, etc.).
Description
Submissions should process the image with the following three steps. n
refers to the number that your program received as input along with the image.
Apply a blur of radius
n
to the input image by replacing each pixel's R, G, and B values with the average R, G, and B values of all pixels within a Manhattan distance ofn
pixels, ignoring all out-of-bounds coordinates. (I.e. all pixels where the sum of the difference in X and the difference in Y is less than or equal ton
.)(note: I used a Gaussian blur for the images above because there was a convenient built-in function for it, so your images might look a little different.)
Set each pixel to a random pixel within a distance of
n/2
pixels ("distance" is defined the same way as in the previous step).This should be done by looping through the image and setting each pixel to a random pixel in this range, so some pixels might disappear entirely and some might be duplicated.
All changes must apply at the same time. In other words, use the old values of the pixels (after step 1 but before this step), not the new values after setting them to a random pixel.
Multiply the "blue" RGB value of each pixel by 1.5, capping it at 255 (or whatever the maximum value for a band of pixels is) and rounding down.
Rules
You may use image libraries / image processing-related functions built into your language; however, you may not use any functions that perform one of the three major tasks mentioned in the description. For example, you can't use a
blur
function, but agetPixel
function is fine.This is code-golf, so the shortest code in bytes wins!
dx <= n && dy <= n
is an accurate representation of Manhattan distance, is it not? \$\endgroup\$