Pages

Sunday 9 June 2024

Understanding the Difference Between Luminance and Lightness

 When working with digital images, color theory, or even photography, terms like "luminance" and "lightness" frequently arise. Although they might sound similar and are related to the perception of brightness, they refer to different concepts. Understanding the difference between luminance and lightness is essential for anyone involved in fields that require color manipulation or analysis. This blog post will explore these two terms, their definitions, how they are calculated in Delphi, and their applications.

What is Luminance?

Luminance refers to the intensity of light emitted from a surface per unit area in a given direction. It is a photometric measure that represents how bright a color appears to the human eye, considering the varying sensitivity of our eyes to different wavelengths of light. Luminance is denoted by the symbol YY and is measured in candelas per square meter (cd/m²).

Calculation of Luminance

Luminance is calculated using a weighted sum of the red, green, and blue (RGB) components of a color. The formula used for this calculation is derived from the ITU-R BT.601 standard, which approximates the human eye's sensitivity to these colors:

 Y = 0.299 X R + 0.587 × G + 0.114 × B


Here, R, G, and B are the red, green, and blue color components, respectively.


Application of Luminance

Luminance is crucial in various applications, including:

  1. Television and Video: Ensuring the brightness of images is consistent across different devices.
  2. Photography: Adjusting exposure and understanding the brightness of different parts of an image.
  3. Computer Graphics: Simulating realistic lighting and shading effects.

What is Lightness?

Lightness is a perceptual measure that describes how light or dark a color appears relative to a white or black reference. It is part of color spaces designed to be more aligned with human vision, such as HSL (Hue, Saturation, Lightness) and LAB (Lightness, A, B).

Calculation of Lightness

In the HSL color model, lightness is calculated as the average of the maximum and minimum values of the RGB components:

In the LAB color space, lightness (L) is derived through more complex transformations of the RGB values to approximate human vision more closely.

Application of Lightness

Lightness is used in contexts where an intuitive understanding of color is necessary:

  1. Graphic Design: Adjusting colors to achieve the desired visual effect.
  2. Image Editing: Modifying the lightness of colors to enhance or alter images.
  3. Color Theory: Teaching and understanding how colors relate to perceived brightness.

Key Differences Between Luminance and Lightness

Basis of Measurement

  • Luminance: Based on the physical intensity of light, considering the human eye's varying sensitivity to different wavelengths.
  • Lightness: A perceptual measure based on how light or dark a color appears compared to white or black.

Calculation Method

  • Luminance: Calculated using a weighted sum of RGB components with specific coefficients.
  • Lightness: In HSL, calculated as the average of the maximum and minimum RGB values; in LAB, through complex transformations.

Applications

  • Luminance: Used in technical fields such as television, photography, and computer graphics.
  • Lightness: Used in design, image editing, and color theory for more intuitive color adjustments.

Conclusion

While luminance and lightness are related to the perception of brightness, they serve different purposes and are calculated differently. Luminance is a more technical measure aligned with the physical properties of light and human vision sensitivity, whereas lightness is a perceptual measure useful in design and editing contexts. Understanding these differences allows for more precise and effective manipulation of color in various applications. Whether you're adjusting the exposure in a photograph, designing a visually appealing graphic, or simulating realistic lighting in a video game, knowing when to consider luminance versus lightness is key to achieving your desired outcome.

Practical Demonstration


Here is a Delphi demo application project containing the source code and a signed executable (download) using the popular ImageEn library that demonstrates these concepts in practice:



Here is the main Procedure that shows the LUMINANCE and LIGHTNESS of the clicked color:


procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

var

  BitmapX, BitmapY: Integer;

  ClickedColor: TColor;

  ClickedRGB: TRGB;

  R, G, B: Byte;

  Luminance, Lightness: Double;

begin

  // Convert view coordinates to bitmap coordinates:

  BitmapX := ImageEnView1.XScr2Bmp(X);

  BitmapY := ImageEnView1.YScr2Bmp(Y);


  // Check if the coordinates are within the bitmap bounds:

  if (BitmapX >= 0) and (BitmapX < ImageEnView1.IEBitmap.Width) and

     (BitmapY >= 0) and (BitmapY < ImageEnView1.IEBitmap.Height) then

  begin

    // Get the pixel color at the clicked coordinates:

    ClickedRGB := ImageEnView1.IEBitmap.Pixels[BitmapX, BitmapY];

    R := ClickedRGB.R;

    G := ClickedRGB.G;

    B := ClickedRGB.B;


    // Convert to TColor

    ClickedColor := RGB(R, G, B);


    // Calculate LUMINANCE:

    Luminance := 0.299 * R + 0.587 * G + 0.114 * B;


    // Calculate LIGHTNESS:

    Lightness := (MaxValue(R, G, B) + MinValue(R, G, B)) / 2;


    // Update the StringGrid with the new values:

    UpdateStringGrid(ClickedColor, R, G, B, Luminance, Lightness);


    // Set the Panel1 color to the clicked color:

    Panel1.Color := ClickedColor;

  end;

end;







No comments:

Post a Comment

Sierpinski Triangle Fractal version 2.0

 This is a substantial update from yesterday's article Creating a Fractal Art Application: Drawing the Sierpinski Triangle . What's ...