Working in the sRGB colourspace, it is easy to implement a method that does this.
Consider the following method:
private static BufferedImage createColorFromGrayscale(BufferedImage red, BufferedImage green, BufferedImage blue){
BufferedImage base = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_ARGB);
for(int x = 0;x < red.getWidth();x++){
for(int y = 0; y < red.getHeight(); y++){
int rgb = (red.getRGB(x, y) & 0x00FF0000) | (green.getRGB(x, y) & 0x0000FF00) | (blue.getRGB(x, y) & 0x000000FF);
base.setRGB(x, y, (rgb | 0xFF000000));
}
}
return base;
}
Creating a new base image, we create a colour component by using bitwise ANDs and ORs to create a 4 byte integer color in format ARGB which is assigned to the base image. Iterating through the whole image by the means of the for loops we are able to set each pixel of the resultant base image to the colours of each channel respectively.
This method assumes that all three images are equal in size. If images are not equal in size, you must handle that separately (e.g by means of stretching images before input or by modifying the method to accept images of different size.)
P.S: It might be more efficient to directly use one of the bufferedimage instances as the base image to save memory when dealing with large images...