Reverse Bayer Filter of an image

Matlab, 104 92 bytes

This makes use of the 3d-array/matrix representation of RGB images in Matlab, as well as the Kronecker product which is exactly what we need creating this new 2x2 "metapixel" form each source pixel. The output is then displayed in a popup window.

a=double(imread(input('')));for n=1:3;b(:,:,n)=kron(a(:,:,n),[1:2;2:3]==n)/255;end;imshow(b)

Resized screencapture:


Pyth, 26 bytes

[email protected],U2tU3'

Expects the input filename with quotation marks on stdin, and writes to o.png. Example output:


Python 3, 259 254 bytes

from PIL.Image import*
o=open(input())
w,h=o.size
n=new('RGB',(2*w,2*h))
P=Image.putpixel
for b in range(w*h):x=b//h;y=b%h;r,g,b=o.getpixel((x,y));c=2*x;d=2*y;G=0,g,0;P(n,(c,d),(0,0,b));P(n,(c+1,d),G);P(n,(c,d+1),G);P(n,(c+1,d+1),(r,0,0))
n.save('o.png')

The input filename is given in standard input. Outputs to o.png.

Example usage:

$ echo mona-lisa.jpg | python bayer.py

Mona Lisa with reverse Bayer filter applied