1
1
Given a truth table and two images, use the truth table as a bitwise operation to the two images.
For example with the truth table:
1 0
1 0 0
0 1 0
(Note that the top is the first image and the left is the second)
and the two images (0, 2, 4)
(a 1x1
image, with the numbers being RGB values) and (30, 20, 10)
:
You would apply the above truth table to the numbers 0
and 30
, of which's binary representations are 00000
and 11110
.
Using the truth table as a bitwise operation would get us 00000
, or in decimal form 0
.
This means that the red value of the first pixel would be 0
.
Continuing this with the other RGB values would get us 2
and 4
for green and blue respectively.
So the output for this would be a 1x1
image with the only pixel having an RGB value of 0, 2, 4
.
For images greater than 1x1
, you apply the truth table for both corresponding pixels on both images and output it to the output image.
For example, if we had a pixel which is located at (x, y) in the image, you would apply the truth table to the R, G, and B values for the (x, y) position in the first image and the (x, y) position in the second. Once you have done this, the (x, y) position in the output image is the output of the truth table applied to the R, G, and B values.
NOTES:
You can use any default input or output method.
You can assume that the two input images are the same dimensions.
You can use any Standard Image I/O that supports RGB.
The truth table can be in any format you want.
As always, since this is code golf, lowest byte-count wins!
Could you explain how an example bigger than 1x1 would work? – xnor – 2019-03-03T16:19:19.510
@xnor You would apply the operation to every pixel – MilkyWay90 – 2019-03-03T16:19:53.523
Can we take the pixels as a flat list, or does it have to be 2D? – xnor – 2019-03-03T16:22:09.053
@xnor If the image is an
n
by1
image, then it's okay. Otherwise, it can't be a flast list – MilkyWay90 – 2019-03-03T16:25:12.4672Does "any image format" include a raw 2D array of RGB tuples? e.g.
[[[12,34,26],[227,162,201]],[[54,231,43],[1,2,3]]]
as a 2x2 "image"? – Kamil Drakari – 2019-03-03T17:54:02.3331...and does it include a raw 2D array of RGB bytes? i.e.
[[[[0,0,0,0,1,1,0,0],[0,0,1,0,0,0,1,0],[0,0,0,1,1,0,1,0]],...],...]
being Kamil's[[[12,34,26],...],...]
. – Jonathan Allan – 2019-03-03T18:41:29.947Also, can we take the truth table as four 0/1 variables? As a single 4-bit number? – xnor – 2019-03-03T21:30:43.440
1@Kamil Yes, any image format, whether it is made up or not as long as it satifies our cirteria – MilkyWay90 – 2019-03-04T00:41:44.527
@JonathanAllan See above – MilkyWay90 – 2019-03-04T00:41:59.053
Wait, why did this get voted as unclear? – MilkyWay90 – 2019-03-04T03:09:26.413
2I downvoted this question because it is trivial in its current form (see Adám's answer). I'm guessing it was closed as unclear for the same reason. – lirtosiast – 2019-03-04T05:02:11.630
@lirtosiast Okay, thanks for explaining! – MilkyWay90 – 2019-03-04T12:08:22.943