CFA separations can be done very easily with PixelMath. In the case of the X-Trans CFA, the expressions required are more complex, but perfectly manageable anyway:
Red:
dy = y() % 6;
dx = x() % 6;
$T * (dx == 4 && (dy == 0 || dy == 2) ||
dx == 1 && (dy == 3 || dy == 5) ||
dy == 1 && (dx == 0 || dx == 2) ||
dy == 4 && (dx == 3 || dx == 5))
Green:
dy = y() % 6;
dx = x() % 6;
$T * ((dy == 1 || dy == 4) == (dx == 1 || dx == 4 ))
Blue:
dy = y() % 6;
dx = x() % 6;
$T * (dx == 1 && (dy == 0 || dy == 2) ||
dx == 4 && (dy == 3 || dy == 5) ||
dy == 4 && (dx == 0 || dx == 2) ||
dy == 1 && (dx == 3 || dx == 5))
with symbols dx and dy declared. The above PixelMath expressions can be used to convert a monochrome CFA image to a RGB image with separate color planes. Do the following:
- With the NewImage tool, create a new grayscale image of 6x6 pixels filled with white (fill value = 1)
- Open the PixelMath tool, uncheck the use a single RGB/K expression option, and copy the above expressions to their corresponding channels (don't include the channel names in the expressions). Write dx, dy in the Symbols field.
- Open the Destination section of PixelMath, check the Create new image option, and select Color space = RGB Color.
- Apply the PixelMath tool to the 6x6 grayscale white image. You should get exactly the X-Trans CFA pattern as a new RGB color image.
I have attached a .xpsm file with a ready to use PixelMath icon. Of course this could also be done with JavaScript. The JS source code would be simpler, but its execution would be slower because PixelMath is a highly optimized pixel-oriented language interpreter and runs multithreaded.