Describe how you would implement a debayering algorithm in software or on an FPGA to convert raw sensor data into an RGB frame.