Advertisement
horshack

rawBayerToChannels.m

Apr 5th, 2021
3,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.80 KB | None | 0 0
  1. %%
  2. %% Splits an interleaved bayer image into individual RGGB channels
  3. %%
  4. %% Parameters:
  5. %% cfaPatternStr - CFA pattern. Must be RGGB or GBRG
  6. %% imgData - Interleaved bayer image
  7. %%
  8. %% Returns:
  9. %% Four separate color channels from bayer data: r, g1, g2, b
  10. %%
  11. function [r, g1, g2, b] = rawBayerToChannels(cfaPatternStr, imgData)
  12.  
  13.   switch (cfaPatternStr)
  14.     case "RGGB"
  15.       redGreen1_FirstRow = 1;
  16.       green2Blue_FirstRow = 2;
  17.     case "GBRG"
  18.       redGreen1_FirstRow = 2;
  19.       green2Blue_FirstRow = 1;
  20.     otherwise
  21.       assert(0, "Unsupported CFA pattern string");
  22.   end
  23.  
  24.   r  = imgData(redGreen1_FirstRow:2:end, 1:2:end);
  25.   g1 = imgData(redGreen1_FirstRow:2:end, 2:2:end);
  26.   g2 = imgData(green2Blue_FirstRow:2:end, 1:2:end);
  27.   b  = imgData(green2Blue_FirstRow:2:end, 2:2:end);
  28.  
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement