Extract an RGB channel of an image Given an image, either as input (possibly in RGB triplets) or with the filename as input (you may assume the image has a specific filename, possibly without an extension), output an image representing a single color channel of the image.

You will also take another input, representing which channel to output. The input can be one of any 3 distinct symbols.  However, the symbols must be either a string or a number. You cannot take a matrice to apply to the array as input however. (such as {1, 0, 0}, or {0, 1, 0}).

You will output the &lt;input&gt; channel of the input image.  You may either save it to a file or output a set of RGB pairs.

Your program should have no limits on the size of the image (in px), and must support either .png, .jpg/.jpeg/.JPG, or RGB triplets as image formats. (it can support as many as you want however)

Test case:



Red channel:



Green channel:



Blue channel:



And another test case, entirely of red.  Original photo, red, green, and blue.  (warning: the plain and red channel hurt to look at for too long)

2 more test cases:

Original, red, green, blue.

Original, red, green, blue.

The latter two test cases are from Images with all colors.
JavaScript (ES6), 29 bytes

a=&gt;n=&gt;a.map(b=&gt;b.map(c=&gt;c&amp;n))


Input is a 2D array of 24-bit integers (e.g. [[0x0000ff,0x00ff00],[0xff0000,0xffffff]]) and 16711680 for red, 65280 for green, 255 for blue. If this isn't valid, try this instead:

JavaScript (ES6), 48 bytes

a=&gt;n=&gt;a.map(b=&gt;b.map(c=&gt;c.map((d,i)=&gt;i==n?d:0)))


Input is a 3D array of color values and 0 for red, 1 for green, 2 for blue.