User Tools

Site Tools


Sidebar

Multimedia

k23:k23.4:k23.4.2:k23.4.2.7:start

23.4.2.7 ImageHistogram class (gb.image.effect)

This class represents an image histogram. Histograms help to assess the colour distribution and special functions allow the colour distribution to be manipulated. The class is static and behaves like a read-only array.

How to determine a single histogram value from a histogram:

  Dim hImageHistogram As ImageHistogram
  Dim histInteger As Integer

  histInteger = hImageHistogram [ Channel As Integer, Value As Integer ]

The following applies:

  • Channel is the colour channel to be examined and can be Image.Red, Image.Green, Image.Blue or Image.Alpha.
  • Value is the colour value.

23.4.2.7.1 Project histogram

The source code is straightforward and is therefore shown in full:

' Gambas class file
 
Public Sub Form_Open()
 
    DisplayHistogram()
 
End
 
Public Sub DisplayHistogram()
 
    Dim hImage As Image
 
'-- Set the dimensions of the histograms
    PictureBoxOrig.W = 256
    PictureBoxOrig.H = 100
    PictureBoxEffect.W = 256
    PictureBoxEffect.H = 100
 
'-- Load the original old photo and show its histogramm
    PictureBox1.Picture = Picture["images/image_original.png"]
    hImage = PictureBox1.Picture.Image
    MakeHistogram(hImage, PictureBoxOrig)
 
'-- Treat the original photo with image.effects
    If RadioButton2.Value Then
       hImage.Normalize()
    Else If RadioButton3.Value Then
       hImage.Equalize()
    Else If RadioButton4.Value Then
       hImage.Fade(Color.Red, 0.263)
    Endif
 
'-- Display the photo treated with image.effects and its histogram
    PictureBox2.Picture = hImage.Picture
    MakeHistogram(hImage, PictureBoxEffect)
 
End
 
Public Sub Effect_Click()
 
    DisplayHistogram()
 
End
 
Public Sub MakeHistogram(img As Image, pBox As PictureBox)
 
    Dim hHistogram As ImageHistogram
    Dim i, iH As Integer
    Dim hPicture As Picture
 
    hHistogram = img.Histogram()
    iH = pBox.H
 
    hPicture = New Picture(256, 100, True)
 
    Paint.Begin(hPicture)
 
      Paint.Brush = Paint.Color(Color.Red)
      Paint.LineWidth = 1
 
      For i = 0 To 255
          Paint.MoveTo(i, iH)
          Paint.LineTo(i, iH - hHistogram[Image.Red, i] / 300)
          Paint.Stroke()
      Next
 
      Paint.Brush = Paint.Color(Color.Green)
      For i = 0 To 255
          Paint.MoveTo(i, iH)
          Paint.LineTo(i, iH - hHistogram[Image.Green, i] / 300)
          Paint.Stroke()
      Next
 
      Paint.Brush = Paint.Color(Color.Blue)
      For i = 0 To 255
          Paint.MoveTo(i, iH)
          Paint.LineTo(i, iH - hHistogram[Image.Blue, i] / 300)
          Paint.Stroke()
      Next
 
    Paint.End()
    pBox.Picture = hPicture
 
End

Notes:

  • You can see that the histograms are each drawn as a line histogram for the three colours red, green and blue in the MakeHistogram(…) procedure.
  • All 4 radio buttons have been combined in a group with the group name 'Effect'.
  • The most noticeable change in the project is the change in the histogram compared to the histogram of the original image with the Equalise effect. The red histogram is stretched to the left (darker area). This gives red contrast again and the image looks much more natural:

IMAGE Histograms

Figure 23.4.2.7.1: Display of the images and the associated histograms

The project is available in the download area as a project archive.

Download

Project

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.4/k23.4.2/k23.4.2.7/start.txt · Last modified: 26.01.2024 by emma

Page Tools