Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [redPixels, greenPixels, bluePixels] = rawToRGB_BooleanMatrixSelection(cfaPatternDimensions, cfaPatternExif, imgData)
- timeStart = time();
- %%
- %% Returns boolean matrix with values set to one corresponding to pixels in
- %% imgData that correspond to pixels of the specified cfaColor
- %%
- function pixelColorBooleanTable = genPixelColorBooleanTable(cfaColor)
- %% generate boolean table of M x N with values equal to 1 for pixels of color we want
- table = logical(cfaPatternAsMatrix == cfaColor);
- %% scale (repeat) table so its large enough to cover the entire image data. this
- %% requires rounding up the repeat count to an even multiple of the CFA dimensions
- pixelColorBooleanTable = repmat(table, floor ((imgHeight+cfaPatternRows-1)/cfaPatternRows),
- floor ((imgWidth+cfaPatternCols-1)/cfaPatternCols));
- %% round size of table down if necessary to exactly fit the size of the image data
- pixelColorBooleanTable = pixelColorBooleanTable(1:imgHeight, 1:imgWidth);
- end
- CFA_RED = 0;
- CFA_GREEN = 1;
- CFA_BLUE = 2;
- imgHeight = size(imgData, 1);
- imgWidth = size(imgData, 2);
- %%
- %% build three boolean matricies, one per color, that will be used to select
- %% values out of the image data corresponding to the CFA location of those
- %% colors
- %%
- cfaPatternRows = cfaPatternDimensions(1);
- cfaPatternCols = cfaPatternDimensions(2);
- cfaPatternAsMatrix = reshape(cfaPatternExif, [cfaPatternRows cfaPatternCols])';
- redBooleanTable = genPixelColorBooleanTable(CFA_RED);
- greenBooleanTable = genPixelColorBooleanTable(CFA_GREEN);
- blueBooleanTable = genPixelColorBooleanTable(CFA_BLUE);
- %% extract pixel data for each of the colors we want
- redPixels = imgData(redBooleanTable);
- greenPixels = imgData(greenBooleanTable);
- bluePixels = imgData(blueBooleanTable);
- printf("Execution time: %.4f\n", time() - timeStart);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement