Advertisement
horshack

rawToRGB_BooleanMatrixSelection.m

Mar 31st, 2021
2,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.94 KB | None | 0 0
  1.  
  2. function [redPixels, greenPixels, bluePixels] = rawToRGB_BooleanMatrixSelection(cfaPatternDimensions, cfaPatternExif, imgData)
  3.  
  4.   timeStart = time();
  5.  
  6.   %%
  7.   %% Returns boolean matrix with values set to one corresponding to pixels in
  8.   %% imgData that correspond to pixels of the specified cfaColor  
  9.   %%
  10.   function pixelColorBooleanTable = genPixelColorBooleanTable(cfaColor)
  11.    
  12.     %% generate boolean table of M x N with values equal to 1 for pixels of color we want
  13.     table = logical(cfaPatternAsMatrix == cfaColor);
  14.    
  15.     %% scale (repeat) table so its large enough to cover the entire image data. this
  16.     %% requires rounding up the repeat count to an even multiple of the CFA dimensions
  17.     pixelColorBooleanTable  = repmat(table,  floor ((imgHeight+cfaPatternRows-1)/cfaPatternRows),
  18.      floor ((imgWidth+cfaPatternCols-1)/cfaPatternCols));
  19.      
  20.     %% round size of table down if necessary to exactly fit the size of the image data
  21.     pixelColorBooleanTable = pixelColorBooleanTable(1:imgHeight, 1:imgWidth);    
  22.   end
  23.  
  24.   CFA_RED = 0;
  25.   CFA_GREEN = 1;
  26.   CFA_BLUE = 2;
  27.  
  28.   imgHeight = size(imgData, 1);
  29.   imgWidth = size(imgData, 2);  
  30.  
  31.   %%
  32.   %% build three boolean matricies, one per color, that will be used to select
  33.   %% values out of the image data corresponding to the CFA location of those
  34.   %% colors
  35.   %%
  36.   cfaPatternRows = cfaPatternDimensions(1);
  37.   cfaPatternCols = cfaPatternDimensions(2);
  38.   cfaPatternAsMatrix = reshape(cfaPatternExif, [cfaPatternRows cfaPatternCols])';
  39.   redBooleanTable = genPixelColorBooleanTable(CFA_RED);
  40.   greenBooleanTable = genPixelColorBooleanTable(CFA_GREEN);
  41.   blueBooleanTable = genPixelColorBooleanTable(CFA_BLUE);
  42.  
  43.   %% extract pixel data for each of the colors we want    
  44.   redPixels   = imgData(redBooleanTable);
  45.   greenPixels = imgData(greenBooleanTable);
  46.   bluePixels  = imgData(blueBooleanTable);
  47.  
  48.   printf("Execution time: %.4f\n", time() - timeStart);
  49. end
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement