Replies: 1 comment 2 replies
-
The most common brightness supposition is Luma . We have pixel formats specifically designed to represent an image luma as calculated in accordance with the ITU-R Recommendation BT.709 specification. Given an long luma = 0;
double averageLuma = 0;
using (var image = Image<Rgba32>.Load(...))
{
// Use memory pooling to allocate a buffer the length of one row
// to house our converted luma values.
Configuration configuration = image.GetConfiguration();
MemoryAllocator allocator = configuration.MemoryAllocator;
using (IMemoryOwner<L8> lumaBuffer = allocator.Allocate<L8>(image.Width))
{
// Convert one row at a time adding the sum of each row to our total.
Span<L8> lumaSpan = lumaBuffer.Memory.Span;
for (int y = 0; y < image.Height; y++)
{
Span<Rgba32> rowSpan = image.GetPixelRowSpan(y);
PixelOperations<Rgba32>.Instance.ToL8(configuration, rowSpan, lumaSpan);
// This loop could be vectorized for maximum performance.
for (int x = 0; x < lumaSpan.Length; x++)
{
luma += lumaSpan[x].PackedValue;
}
}
}
// Finally calculate the average luma.
averageLuma = luma / (double)(image.Width * image.Height);
} If you don't need the image for any other operation you can skip the conversion part and use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
what would be most efficient way to measure image brighness?
I need some kind classification number or even better if I can get sum of pixel color values in each color channel.
Beta Was this translation helpful? Give feedback.
All reactions