(bit)Wise Images

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!

MilkyWay90

Posted 2019-03-03T16:08:11.230

Reputation: 2 264

Question was closed 2019-03-04T01:29:14.603

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 by 1 image, then it's okay. Otherwise, it can't be a flast list – MilkyWay90 – 2019-03-03T16:25:12.467

2Does "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.333

1...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.947

Also, 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

Answers

4

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

Adám

Posted 2019-03-03T16:08:11.230

Reputation: 37 779

Ah, I thought the characters just weren't rendering for me – Jo King – 2019-03-03T23:45:39.853

@JoKing APL renders right on almost all systems. – Adám – 2019-03-04T00:12:54.873

If only my browser displayed this characters correctly – MilkyWay90 – 2019-03-04T00:45:27.207

1@MilkyWay90 As Adam said, the characters are rendering correctly; it's just that they are all the same box character – Jo King – 2019-03-05T01:40:43.337

@JoKing oh okay. I couldn't see the previous comments (maybe they were deleted) – MilkyWay90 – 2019-03-05T02:20:29.780

@MilkyWay90 It says so in the post itself: And yes, those are three identical boxes: I've made it italic now. – Adám – 2019-03-05T05:38:37.710

@Adám Oh, sorry – MilkyWay90 – 2019-03-06T03:47:20.060