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.


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!

  • \$\begingroup\$ Could you explain how an example bigger than 1x1 would work? \$\endgroup\$ – xnor Mar 3 '19 at 16:19
  • 2
    \$\begingroup\$ Does "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"? \$\endgroup\$ – Kamil Drakari Mar 3 '19 at 17:54
  • 1
    \$\begingroup\$ ...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],...],...]. \$\endgroup\$ – Jonathan Allan Mar 3 '19 at 18:41
  • 1
    \$\begingroup\$ @Kamil Yes, any image format, whether it is made up or not as long as it satifies our cirteria \$\endgroup\$ – MilkyWay90 Mar 4 '19 at 0:41
  • 2
    \$\begingroup\$ I 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. \$\endgroup\$ – lirtosiast Mar 4 '19 at 5:02

APL (Dyalog Unicode), 3 bytesSBCS

Full program. Prompts for first image, then truth table, then second image, all from STDIN. Images must be given as bit arrays (for example, 8 × height × width × 3, but this doesn't actually matter). The truth table must be given as a Boolean APL function. And yes, those are three identical boxes:


Try it online!

 prompt for the first image

 prompt for the function, and apply it with the following left argument:

 prompt for the second image

  • \$\begingroup\$ Ah, I thought the characters just weren't rendering for me \$\endgroup\$ – Jo King Mar 3 '19 at 23:45
  • \$\begingroup\$ @JoKing APL renders right on almost all systems. \$\endgroup\$ – Adám Mar 4 '19 at 0:12
  • \$\begingroup\$ If only my browser displayed this characters correctly \$\endgroup\$ – MilkyWay90 Mar 4 '19 at 0:45
  • 1
    \$\begingroup\$ @MilkyWay90 As Adam said, the characters are rendering correctly; it's just that they are all the same box character \$\endgroup\$ – Jo King Mar 5 '19 at 1:40
  • \$\begingroup\$ @JoKing oh okay. I couldn't see the previous comments (maybe they were deleted) \$\endgroup\$ – MilkyWay90 Mar 5 '19 at 2:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.