Graphics Reference
In-Depth Information
There's more…
By first applying blur to the source image, we are able to reduce the level of noise generated
by the Sobel filter as shown in the right-hand example of the previous example output. This is
where the Implementing a Gaussian blur filter recipe can be useful as this type of blur filter is
better at preserving edges while still reducing noise within the source image.
See also
F The Implementing box blur using separable convolution filters recipe will cover how
you can apply multiple filters one after another
Calculating an image's luminance histogram
In this recipe we will explore using a compute shader to gather characteristics from the source
image and output to a buffer. The characteristic that we will be determining is the image's
luminance histogram, that is, how many texels are there within the texture for each luminance
value (mapped from 0.0-1.0 to 0-255).
We will also cover how to retrieve the data from the GPU and load it into an array that is
accessible from the CPU.
How to do it…
We'll begin with the HLSL code necessary to calculate the histogram.
1.
The input continues to be a Texture2D SRV; however, this time our output UAV will
be RWByteAddressBuffer .
Texture2D<float4> input : register(t0);
RWByteAddressBuffer outputByteBuffer : register(u0);
#define THREADSX 32
#define THREADSY 32
// used for RGB/sRGB color models
#define LUMINANCE_RGB float3(0.2125, 0.7154, 0.0721)
#define LUMINANCE(_V) dot(_V.rgb, LUMINANCE_RGB)
2.
Our actual compute shader is quite simple:
// Calculate the luminance histogram of the input
// Output to outputByteBuffer
[numthreads(THREADSX, THREADSY, 1)]
void HistogramCS(uint groupIndex: SV_GroupIndex, uint3
 
Search WWH ::




Custom Search