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:
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:
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.
Project