Have you tried the netpbm tools? This will work with R8G8B8 and other 8-bit RGB orders.
For a width 100 height 200 RGB order raw file:
rawtoppm -rgb 100 200 input.rgb > image.ppm
ppmtorgb3 image.ppm
You will now have 3 pgm format grey-map files, each suffixed .red .grn and .blu. These .pgm files are almost a raw binary format, except for the short header, so:
tail +4 image.red > image_r.raw
tail +4 image.grn > image_g.raw
tail +4 image.blu > image_b.raw
if you really want the raw channels like that. Or, for further processing:
pgmtoppm red image.red > image_red.ppm
pgmtoppm green image.grn > image_grn.ppm
pgmtoppm blue image.blu > image_blue.ppm
You now have three ppmformat files which are the separated RGB channels (see also rgb3toppm). These can be convert to other formats using ppmtoX, e.g. ppmtopng.
Use "white" instead of the colour in the 2nd parameter to leave each as a grey scale.
Imagemagick's convert may also be also useful, it will handle RGB, RGBA and 16-bit raw formats too, and it has a -separate option to split channels.
for ch in R G B; do
convert -set colorspace RGB -size 100x200 -depth 8 rgb:image.rgb \
-channel ${ch} -separate -depth 8 gray:image_${ch}.raw
done
Check that the -set colorspace option is appropriate for your input.
Newer versions let you do this in a single command, see http://www.imagemagick.org/Usage/color_basics
convert ... -channel RGB -separate gray:image_%d.raw
and R/G/B will be written to image_0.raw image_1.raw image_2.raw files
Note,
convert command was updated based on help and feedback from
Stephane Chazelas, there were several changes to colorspace behaviour from ImageMagic-6.7.7 which cause problems due to (I believe) sRGB being used instead of RGB.
# colorspace changes mean this works differently after ImageMagick-6.7.6
convert -size 100x200 -depth 8 rgb:image.rgb \
-channel ${ch} -separate -depth 8 gray:image_${ch}.raw
RGB RGB RGBorRRR GGG BBB? – LiuYan 刘研 Feb 22 at 10:21