9
\$\begingroup\$

Your task is to take a 24 BPP sRGB image and output the same image upscaled 3x into red, green, and blue subpixels. The resulting image will be made entirely of pure black, red, green, and blue pixels.

Each pixel from the source image, when zoomed, produces an arrangement of 9 sub-pixels that can be either on or off (i.e. their respective color or black). The specific arrangement uses three columns of red, green, and blue, in that order, like so:

RGB subpixels

(Note that the borders on these "pixels" are for demonstration only.)

Since each of the nine subpixels can only be on or off, you will have to quantize the input image and use different subpixel patterns to achieve 3 levels of brightness.

For each subpixel in the image:

  • For color levels 0-74, all subpixels should be black.
  • For color levels 75-134, the middle subpixel should be the respective color and the other two should be black.
  • For color levels 135-179, the middle subpixel should be black and the other two should be the respective color
  • For color levels 180-255, all three subpixels should be their respective color

I chose these level ranges because those are what happened to look good

Apply this transformation to every pixel in the image and output the subpixel-upscaled image.

Single-pixel examples

rgb(40, 130, 175) will produce this pattern:

00B/0G0/00B

rgb(160, 240, 100) will produce this pattern:

RG0/0GB/RG0

Full Image Examples

Mona Lisa Mona Lisa Subpixels

Starry Night Starry Night Subpixels

Parrot Parrot Subpixels

Images sourced from Wikipedia

Rules and notes

  • Input and output may be in any convenient format, whether that's actual image files or (possibly nested) lists of RGB values.
  • You may assume the pixels are in the sRGB colorspace with 24BPP.

Happy golfing!

\$\endgroup\$
  • 2
    \$\begingroup\$ The initial description sounds like un-Bayering. It turns out that it isn't, partly because of the unconventional 3x3 mask but mainly because of the quantisation, but IMO it's still closer to un-Bayering than to subpixel zooming (which would be upscaling with some kind of edge detection to anti-alias). \$\endgroup\$ – Peter Taylor Mar 23 at 17:00
  • \$\begingroup\$ thanks for an interesting challenege.... is this actually used for anything in the real life? \$\endgroup\$ – don bright Mar 24 at 0:47
4
\$\begingroup\$

JavaScript (Node, Chrome, Firefox), 111 bytes

I/O format: matrix of [R,G,B] values.

a=>[...a,...a,...a].map((r,y)=>r.flat().map((_,x)=>a[y/3|0][x/3|0].map(v=>x--%3|511+y%3%2*3104>>v/15&1?0:255)))

Try it online! (just a single pixel)

How?

All threshold values are multiples of 15. Instead of doing explicit comparison tests, it's a bit shorter to test a bitmask where each bit represents an interval of 15 values (except the most significant bit which is mapped to a single value).

 bit | range   | top/bottom | middle
-----+---------+------------+--------
  0  |   0- 14 |     off    |   off
  1  |  15- 29 |     off    |   off
  2  |  30- 44 |     off    |   off
  3  |  45- 59 |     off    |   off
  4  |  60- 74 |     off    |   off
  5  |  75- 89 |     off    |    on
  6  |  90-104 |     off    |    on
  7  | 105-119 |     off    |    on
  8  | 120-134 |     off    |    on
  9  | 135-149 |      on    |   off
 10  | 150-164 |      on    |   off
 11  | 165-179 |      on    |   off
 12  | 180-194 |      on    |    on
 13  | 195-209 |      on    |    on
 14  | 210-224 |      on    |    on
 15  | 225-239 |      on    |    on
 16  | 240-254 |      on    |    on
 17  |   255   |      on    |    on

We encode off as \$1\$ and on as \$0\$ in order to maximize the number of leading zeros.

We get:

  • 000000000111111111 for top and bottom pixels (\$511\$ in decimal)
  • 000000111000011111 for the middle pixel (\$3615\$ in decimal)

Commented

a =>                      // a[] = input matrix
  [...a, ...a, ...a]      // create a new matrix with 3 times more rows
  .map((r, y) =>          // for each row r[] at position y:
    r.flat()              //   turn [[R,G,B],[R,G,B],...] into [R,G,B,R,G,B,...]
                          //   i.e. create a new list with 3 times more columns
    .map((_, x) =>        //   for each value at position x:
      a[y / 3 | 0]        //     get [R,G,B] from the original matrix
       [x / 3 | 0]        //     for the pixel at position (floor(x/3), floor(y/3))
      .map(v =>           //     for each component v:
        x-- % 3 |         //       1) yield a non-zero value if this is not the component
                          //          that we're interested in at this position
        511 +             //       2) use either 511 for top and bottom pixels
        y % 3 % 2 * 3104  //          or 3615 for the middle pixel (y mod 3 = 1)
        >> v / 15         //          divide v by 15
        & 1               //          and test the corresponding bit
        ?                 //       if either of the above tests is truthy:
          0               //         yield 0
        :                 //       else:
          255             //         yield 255
      )                   //     end of map() over RGB components
    )                     //   end of map() over columns
  )                       // end of map() over rows

Example

The following code snippet processes the head of Mona Lisa (64x64). Doesn't work on Edge.

f=
a=>[...a,...a,...a].map((r,y)=>r.flat().map((_,x)=>a[y/3|0][x/3|0].map(v=>x--%3|511+y%3%2*3104>>v/15&1?0:255)))

var img;

(img = new Image).onload = function(){
  var ctx = document.getElementById('c').getContext('2d');
  ctx.drawImage(img, 0, 0);
  var data = ctx.getImageData(0, 0, 192, 192), x, y, ptr, a = [];
  for(ptr = y = 0; y < 64; y++) {
    for(a[y] = [], x = 0; x < 64; x++) {
      a[y][x] = [data.data[ptr++], data.data[ptr++], data.data[ptr++]];
      ptr++;
    }
    ptr += 512;
  }
  a = f(a);
  for(ptr = y = 0; y < 192; y++) {
    for(x = 0; x < 192; x++) {
      data.data[ptr++] = a[y][x][0];
      data.data[ptr++] = a[y][x][1];
      data.data[ptr++] = a[y][x][2];
      data.data[ptr++] = 255;
    }
  }
  ctx.putImageData(data, 0, 0);
};

document.getElementById('img').src = img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAgAElEQVR4nD2713fcx5W2i4tzzowlJoROv9S5G42c0QiNnFMDDXQjg0gEM0iAQUwAkUMjZwIEcxZzEEUry5Y1I2ssWcGSLFmyZjxJ33z/w3Mu6DUXe9XNvnr2u6veqlo7oG+0grPjbs6OV9E3WkXfqIfTo1WcGfNwasRN/3g1/eNVDE97GZj0MOj30D9ewcCEm6GxCvqGijh1Np+B0TLODJZwZqCcoTEfI+N1DIz4ODNcy5nRBvommugfb6BvxMvgUA2DA9WMTzQzMt7M8GQLQ/6dDPqbGZxoZmiimYHxOvrGPPRPeDg17ObMSDWnR3ycHPFxeqyOU2N1nJ5ooH+qmbPTLQzMtdE/18YpfzOnJus5OV7L4FQDZ8ZqODlUSd9kHadHPJwccnNqyM3ZcS/9Ez4CBscr6B8pYWC8gmF/NcP+GgbGK+kbLad/rIKzY24GJ6oYnalhZLqasZkaBifcDPvdjE1UMDRSTN9gAcMT5QyMlnN22M3QuJfRcR8j4z6GJ+sZnm5iYKqBoblG+qe8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GYwNLhFCa7ojndGMPxugT2l0fSmW+nIc1AbbJMU5qRplQD7ZkmuvIs7Ck001Pp4HClnZ6qULryJVozRWridOSa1Dh1ahJ0OhIlBXugDuNWDaGal57AGChiVok4ZD0mjYRFa8Ss1hIZaiE7L5mMvFgKypLJKUkkoOuwl10HKth7qIau/RXs7S5j78ESdu0pobk5H19pOokmmRTJQJZswu2IIEcx4BJkCowGnGodkTtUJEgKCXqJeFnEqTeSbJJxmhVyHRJ7SixcOpPJhZNO5rqdTHQlcaYhgt5KK91/nyPaV2jiYLGVvfkK+wsVjlRaOFlrp78pnL7GMI55TBws1dOUoqPIEkiGoiJeHUSCKBAerMOyQ4spUIc5WMIYqMOuFQmXZSxqAavagEklYJIFsnKScKaFUVKRQkllKgFdPU3sOexj/2Ef7V0F7OsuYtfubDo6Cmiuy6OhMpMks0iWyUq6RiJDJ5GlGEkX9bg0mpduUDISL8qkWk0kKgLJej1JRhGn2UC2zUhLpombw8Xcm8jjUn8O546lM707krG2MIaawumrC+U1j4XjHgsnvTZOea301dsYaQ1nvDOSic5IzjZaOValpzVVRW28QJ4phBQxmBhVIBEhaiK1egyBAuZgGatKxq7RESXL2NUvJ03ErTKq7WoiIx0kO0Op8qTia8wkoOtwI+17PbR3uWndVcjeA8Xs3ltAfV0GzfUFVBcmk2wSybM5yDFYSRf0FNnDcYl6sgWZNI1IolYiWqMjXpFwmvQk62VcNiO54aHkO0zUORUunirmyUwZ98ZzuTmUwdX+dM6/5mRmdwQT7eH4OyOY7AhnrM3BaGsoE51hzO2LZuFgNMs9CUztCWOi3cGxMokmp5Z8SxB5Ji0pumDCAwMJDRYwbldjDRGwqgzE6g2km2TidCI2rQlDkBXddhm9qJCSHE1ebhwFhbH8/yAZ7ktBxllRAAAAAElFTkSuQmCC";
<img id="img" />
<canvas id="c" width=192 height=192></canvas>

\$\endgroup\$
3
\$\begingroup\$

Jelly, 27 bytes

<“⁷KṆ‘‘Ḅœ?Ɗo⁹’)×€"3⁼þ¤)ẎZ)Ẏ

A monadic Link accepting a list (picture) of lists (rows) of lists (pixels). Each pixel being three integers in \$[0,255]\$, [r, g, b], which yields the result in the same format.

Try it online! This example is taking a two by two image where the top-left pixel is the first example pixel, the top-right pixel is the second example pixel, the bottom-left pixel is a black pixel and the bottom-right pixel is a white pixel.

How?

<“⁷KṆ‘‘Ḅœ?Ɗo⁹’)×€"3⁼þ¤)ẎZ)Ẏ - Link: list of lists of lists of integers, I
                         )  - for each row, R, in I:
                      )     -   for each pixel, P, in R:
              )             -     for each integer, C, in P:
 “⁷KṆ‘                      -       list of code-page indices = [135,75,180]
<                           -       less than -> [C<135,C<75,C<180] 
          Ɗ                 -       last three links as a monad:
      ‘                     -         increment -> [1+(C<135),1+(C<75),1+(C<180)]
       Ḅ                    -         from binary -> 4*(1+(C<135))+2*(1+(C<75))+1+(C<180)
        œ?                  -         permutation at that index of [C<135,C<75,C<180]
                            -         when all permutations sorted lexicographically
                            -       ... a no-op for all but [0,0,1]->[0,1,0]
            ⁹               -       256
           o                -       logical OR  e.g. [0,1,0]->[256,1,256]
             ’              -       decrement               ->[255,0,255]
                     ¤      -     nilad followed by link(s) as a nilad:
                  3         -       three
                    þ       -       table with: (i.e. [1,2,3] . [1,2,3])
                   ⁼        -         equal?    -> [[1,0,0],[0,1,0],[0,0,1]]
                 "          -     zip with:
                €           -       for each:
               ×            -         multiply
                       Ẏ    -   tighten (reduce with concatenation)
                        Z   -   transpose
                          Ẏ - tighten
\$\endgroup\$
  • \$\begingroup\$ im trying to figure out where it encodes [[1,0,0].[0,1,0],[0,0,1]] and i am baffled. \$\endgroup\$ – don bright Mar 24 at 0:46
  • \$\begingroup\$ @donbright 3⁼þ¤ performs an outer product of [1,2,3]=[1,2,3] yielding [[1=1,2=1,3=1],[2=1,2=2,2=3],[3=1,3=2,3=3]] which is [[1,0,0],[0,1,0],[0,0,1]]. \$\endgroup\$ – Jonathan Allan Mar 24 at 1:17
2
\$\begingroup\$

Wolfram Language (Mathematica), 186 bytes

Input and Output are lists of RGB values

(g=#;Flatten[(T=Transpose)@Flatten[T/@{{#,v={0,0,0},v},{v,#2,v},{v,v,#3}}&@@(If[(l=Max@#)<75,v,If[74<l<135,{0,l,0},If[134<l<179,{l,0,l},{l,l,l}]]]&/@#)&/@g[[#]],1]&/@Range[Length@g],1])&

Try it online!


Wolfram Language (Mathematica), 243 bytes

this second code is a function that takes as input an image and outputs an image
(I don't know why people were confused in the comments)

So, if you feed this img

enter image description here

into this function

(i=#;Image[Flatten[(T=Transpose)@Flatten[T/@{{#,v={0,0,0},v},{v,#2,v},{v,v,#3}}&@@(If[(l=Max@#)<75,v,If[74<l<135,{0,l,0},If[134<l<179,{l,0,l},{l,l,l}]]]&/@#)&/@ImageData[i,"Byte"][[#]],1]&/@Range[Last@ImageDimensions@i],1],ColorSpace->"RGB"])&


you will get this output

enter image description here

\$\endgroup\$
  • 2
    \$\begingroup\$ Wouldn't this count as a hardcoded input? \$\endgroup\$ – attinat Mar 24 at 6:53
  • \$\begingroup\$ "Input and output may be in any convenient format, whether that's actual image files ...". No, i is an image. \$\endgroup\$ – J42161217 Mar 24 at 8:28
  • \$\begingroup\$ I would agree with @attinat, this looks like hardcoding. \$\endgroup\$ – Jonathan Frech Mar 24 at 9:36
  • \$\begingroup\$ I made some changes and I hope that everything is clear now. \$\endgroup\$ – J42161217 Mar 24 at 20:05
1
\$\begingroup\$

C# (Visual C# Interactive Compiler), 157 bytes

n=>{int i=0,j=n[0].Length;for(;;Write(z(0)+",0,0|0,"+z(1)+",0|0,0,"+z(2)+"\n|"[++i%j&1]));int z(int k)=>(((511^i/j%3%2*4064)>>n[i/j/3][i%j][k]/15)&1^1)*255;}

Prints the RGB of the output. The output is newline separated and not aligned. Originally, I used a bit-mask with 1 being on and 0 being off, but then I saw Arnauld's answer, and I realized using 0 as on and 1 as off could save bytes in the number. The TIO link contains a 4 by 2 pixel sample "image".

Try it online!

\$\endgroup\$
0
\$\begingroup\$

APL+WIN, 102 bytes

Prompts for a 2d matrix of pixels as 24 bit integers as they would appear in the image

((⍴a)⍴,3 3⍴255*⍳3)×a←(3 1×⍴m)⍴∊⍉((1↓⍴m)/⍳↑⍴m)⊂n←(-+⌿n)⊖n←1 0↓0 75 135 180∘.≤,m←(1 3×⍴m)⍴,⍉(3⍴256)⊤,m←⎕

Try it online! Courtesy of Dyalog Classic

Outputs a 2d matrix of 24 bit integers of the transformed image. Most of the code is handling the formatting of the input and output.

Example: Take a 2 x 2 image made up of the sample pixels

Input:

2654895 10547300
2654895 10547300

Output:.

0     0 16581375 255 65025        0
0 65025        0   0 65025 16581375
0     0 16581375 255 65025        0
0     0 16581375 255 65025        0
0 65025        0   0 65025 16581375
0     0 16581375 255 65025        0
\$\endgroup\$
0
\$\begingroup\$

Rust - 281 bytes

fn z(p:Vec<u8>,wh:[usize;2])->Vec<u8>{let mut o=vec![0;wh[0]*wh[1]*27];for m in 0..wh[0]{for n in 0..wh[1]{for i in 1..=3{for j in 0..3{o[m*9+n*wh[0]*27+j*wh[0]*9+i*2]=match p[18+m*3+n*wh[0]*3+3-i]{75..=134=>[0,1,0],135..=179=>[1,0,1],180..=255=>[1,1,1],_=>[0,0,0],}[j]*255;}}}}o}

This line is a function that meets the challenge, however it's input is actually data in the TGA file format as described at paulbourke.net, along with pre-parsed width and height, in pixels, of the image. It returns pixel data for the output, as bytes, in a vector 9 times the size of the input pixel data.

use std::fs::File;use std::io::{Read,Write};fn main(){let mut p=vec![];let mut o=vec![0u8;18];File::open("i.tga").unwrap().read_to_end(&mut p).unwrap();let mut wh=[0;2];let h=|x|p[x] as usize;let g=|x|(3*x/256) as u8;for i in 0..2{wh[i]=h(12+i*2)+256*h(13+i*2);o[12+i*2]=g(wh[i]*256);o[13+i*2]=g(wh[i]);}let mut f=File::create("o.tga").unwrap();o[2]=2;o[16]=24;o.extend(z(p,wh));f.write(&o).unwrap();}

This second line is a main() function that can transform an input file named i.tga into an output file named o.tga, by calling the function z from the first line, without using any external libraries. It handles parsing of width/height, creating a header for the output file, and file reading + writing. It would add 402 bytes if the challenge required File I/O, for a total of 683. It is useful for testing.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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