Create pixel art!
Sledgehammer, 22 17 bytes
I noticed I'm no longer winning for some reason and made a minor IO golf
⢟⢡⡂⠴⠒⢂⢜⠧⣘⡨⡏⣻⢈⠯⣧⠼⡫
Corresponding Mathematica code: Export[".bmp",ImageAdjust[Import[#]~Downsample~2, 9!]]&
. Takes input from the file with name specified in the program's arguments (for some reason these are put in a file, too), outputs to the file .bmp
. There are literally built-ins for everything!
- built-in for reading arbitrary image format
- built-in for downsampling
- built-in for adjusting the contrast by \$9!\$
- built-in for writing all that into a file
At least it's not PixelArtify[Input[]]
.
Mathematica, 61 31 bytes
ImageAdjust[#~Downsample~2,9!]&
Adjusts the contrast of the downsampled image by the factorial of nine.
MATL, 18 bytes
Yi2Lt3:K$)127>o2YG
The input is a string with the file name. The output is an image displayed in a window.
Input image:
Output image:
Explanation
Yi % Implicit input: filename. Read image. Gives an N×M×3 uint8 array
2L % Push [2 2 j] (predefined literal). When interpreted as an index,
% this means 2:2:end
t % Duplicate
3: % Push [1 2 3]
K$) % 4-input indexing. Downsamples the image by a factor of 2 in each
% dimension of the first two dimensions (vertical and horizontal),
% while keeping the three colour components
127> % Greater than 127? Gives true (1) or false (0)
o % Convert to double
2YG % Display image. For double data type this assumes range from 0 to 1
Python 3 + imageio, 68 67 bytes
Takes the filename as input, overwrites the original file.
from imageio import*
lambda f:imwrite(f,(~imread(f)[::2,::2]>>7)-1)
imageio.imread
returns a numpy 3d array of unsigned 8-bit integers corresponding to the RGB value of each pixel. array[::2, ::2]
takes every other row and every other column of the array.
Because of the 8-bit data type (~array>>7)-1
is equivalent to ((255-array)//128-1)%256
.
image source