forked from GottaYotta/GPUImage2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the histogram equalization filter.
- Loading branch information
1 parent
f26626b
commit 805bf5d
Showing
21 changed files
with
261 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
public class HistogramEqualization: OperationGroup { | ||
public var downsamplingFactor: UInt = 16 { didSet { histogram.downsamplingFactor = downsamplingFactor } } | ||
|
||
let histogram:Histogram | ||
let rawDataInput = RawDataInput() | ||
let rawDataOutput = RawDataOutput() | ||
let equalizationFilter:BasicOperation | ||
|
||
public init(type:HistogramType) { | ||
|
||
self.histogram = Histogram(type:type) | ||
switch type { | ||
case .Red: self.equalizationFilter = BasicOperation(fragmentShader:HistogramEqualizationRedFragmentShader, numberOfInputs:2) | ||
case .Blue: self.equalizationFilter = BasicOperation(fragmentShader:HistogramEqualizationBlueFragmentShader, numberOfInputs:2) | ||
case .Green: self.equalizationFilter = BasicOperation(fragmentShader:HistogramEqualizationGreenFragmentShader, numberOfInputs:2) | ||
case .Luminance: self.equalizationFilter = BasicOperation(fragmentShader:HistogramEqualizationLuminanceFragmentShader, numberOfInputs:2) | ||
case .RGB: self.equalizationFilter = BasicOperation(fragmentShader:HistogramEqualizationRGBFragmentShader, numberOfInputs:2) | ||
} | ||
|
||
super.init() | ||
|
||
({downsamplingFactor = 16})() | ||
|
||
self.configureGroup{input, output in | ||
self.rawDataOutput.dataAvailableCallback = {data in | ||
var redHistogramBin = [Int](count:256, repeatedValue:0) | ||
var greenHistogramBin = [Int](count:256, repeatedValue:0) | ||
var blueHistogramBin = [Int](count:256, repeatedValue:0) | ||
|
||
let rowWidth = 256 * 4 | ||
redHistogramBin[0] = Int(data[rowWidth]) | ||
greenHistogramBin[1] = Int(data[rowWidth + 1]) | ||
blueHistogramBin[2] = Int(data[rowWidth + 2]) | ||
|
||
for dataIndex in 1..<256 { | ||
redHistogramBin[dataIndex] = redHistogramBin[dataIndex - 1] + Int(data[rowWidth + (dataIndex * 4)]) | ||
greenHistogramBin[dataIndex] = greenHistogramBin[dataIndex - 1] + Int(data[rowWidth + (dataIndex * 4) + 1]) | ||
blueHistogramBin[dataIndex] = blueHistogramBin[dataIndex - 1] + Int(data[rowWidth + (dataIndex * 4) + 2]) | ||
} | ||
|
||
var equalizationLookupTable = [UInt8](count:256 * 4, repeatedValue:0) | ||
for binIndex in 0..<256 { | ||
equalizationLookupTable[binIndex * 4] = UInt8((((redHistogramBin[binIndex] - redHistogramBin[0]) * 255) / redHistogramBin[255])) | ||
equalizationLookupTable[(binIndex * 4) + 1] = UInt8((((greenHistogramBin[binIndex] - greenHistogramBin[0]) * 255) / greenHistogramBin[255])) | ||
equalizationLookupTable[(binIndex * 4) + 2] = UInt8((((blueHistogramBin[binIndex] - blueHistogramBin[0]) * 255) / blueHistogramBin[255])) | ||
equalizationLookupTable[(binIndex * 4) + 3] = 255 | ||
} | ||
|
||
self.rawDataInput.uploadBytes(equalizationLookupTable, size:Size(width:256, height:1), pixelFormat:.RGBA) | ||
} | ||
|
||
input --> self.histogram --> self.rawDataOutput | ||
input --> self.equalizationFilter --> output | ||
self.rawDataInput --> self.equalizationFilter | ||
} | ||
} | ||
} |
Oops, something went wrong.