Diese Klasse repräsentiert ein Bildhistogramm. Histogramme helfen dabei, die Farbverteilung zu beurteilen und spezielle Funktionen erlauben es, die Farbverteilung zu manipulieren. Die Klasse ist statisch und verhält sich wie ein schreibgeschütztes Array.
So ermitteln Sie einen einzelnen Histogramm-Wert aus einem Histogramm:
Dim hImageHistogram As ImageHistogram Dim histInteger As Integer histInteger = hImageHistogram [ Channel As Integer, Value As Integer ]
Dabei gilt:
Der Quelltext ist überschaubar und wird daher komplett angegeben:
' 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
Hinweise:
Abbildung 23.4.2.7.1: Anzeige der Bilder und der zugehörigen Histogramme
Das Projekt wird Ihnen im Download-Bereich als Projekt-Archiv zur Verfügung gestellt.