28
6
Challenge:
Take input of two black and white (monochrome) images and xor each pixel of the first, with each pixel of the second, add them to a new image and output the new image.
Some clarifications:
Size of pictures does not matter. Extension/Image format doesn't matter. You can make it take input any extension and output any extension, as long as the extension is used to store digital images. You can also use graphics to draw the output in eg: a picturebox if you wish. Otherwise, save the output as a file. Input can be taken as a path to the image, or url.
One thing you can't do however, is I/O arrays, eg. of triplets(R,G,B).
Do NOT tamper with alpha. It should not be xored, it should be 255 (max value) for every pixel.
What do you mean xor each pixel?
You don't have to do it this way, but one way to xor two pixels is to take their RGB values and xor R1 with R2, G1 with G2, B1 with B2, and take the result, which is your new color
Since we have only two colors, obviously when the colors are the same the result would be (0,0,0) and when they are different (white is 255,255,255 and black is 0,0,0) in this case, the result would be 255,255,255.
Thus when two pixels are different, the result is a white pixel, else a black pixel
Example I/O:
Input 1: Input 2:
Output:
This is code-golf so shortest code wins.
Can we take the input image as a URL? – user41805 – 2017-01-15T17:11:05.940
@KritixiLithos yup, I edited it in the challenge for any further viewers. – P. Ktinos – 2017-01-15T17:14:17.633
5
Bonus challenge: http://i.imgur.com/a0M6o9e.png and http://i.imgur.com/bP1TsjQ.png.
– orlp – 2017-01-15T17:26:07.387May we read/write matrices of (R, G, B) triplets?
– Lynn – 2017-01-15T17:28:46.363@orlp I got up to the qr code – user41805 – 2017-01-15T17:29:55.717
@Lynn No, simply because it is tagged "image-processing" and graphical-output. You need to output an image, and take an image. Otherwise the challenge would be xor two arrays. – P. Ktinos – 2017-01-15T17:30:38.223
@P.Ktinos Then you need to explicitly state this in the challenge, as arrays of (R,G,B) triplets are an accepted I/O format by default for these challenges. – orlp – 2017-01-15T17:36:11.550
Is it okay if we output nothing instead of white? – user41805 – 2017-01-15T17:44:04.913
Nothing as in a pixel with 0 alpha @KritixiLithos ? What would Nothing look like in the image? – P. Ktinos – 2017-01-15T17:45:50.603
@P.Ktinos http://i.stack.imgur.com/ShkoX.png
– user41805 – 2017-01-15T17:47:03.910Not really @KritixiLithos . I guess it's kind of my fault for not specifying to not tamper with the alpha value. The alpha value should be at maximum for every pixel, and should not be xored, ill add to the question – P. Ktinos – 2017-01-15T17:49:06.020
Just to clarify, do we need to handle for all image sizes, or can we handle only specific image sizes? I was thinking it would be easier if I would handle images upto 400x400px – user41805 – 2017-01-15T17:54:05.090
@KritixiLithos Since "Size of the images doesn't matter", do whatever you think will help you achieve shorter code. If only handling specific image sizes makes your code shorter (or vice versa with all image sizes), then go ahead. – P. Ktinos – 2017-01-15T17:56:05.303
I would replace the word "extension" with "image format". (The "extension" is just a part of the file name.) – Paŭlo Ebermann – 2017-01-15T19:10:23.827
@PaŭloEbermann Done – P. Ktinos – 2017-01-15T19:15:19.910
@orlp Your QR links to http://codegolf.stackexchange.com/
– NoOneIsHere – 2017-01-16T22:27:38.663