k23:k23.4:k23.4.2:k23.4.2.7:start
Inhaltsverzeichnis
23.4.2.7 Klasse ImageHistogramm (gb.image.effect)
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:
- Channel ist der zu untersuchende Farbkanal und kann Image.Red, Image.Green, Image.Blue oder Image.Alpha sein.
- Value ist der Farbwert.
23.4.2.7.1 Projekt Histogramm
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:
- Sie können erkennen, dass die Histogramme jeweils als Linien-Histogramm für die drei Farben rot, grün und blau in der Prozedur MakeHistogram(…) gezeichnet werden.
- Alle 4 Radio-Buttons sind in einer Gruppe mit dem Gruppennamen 'Effect' zusammengefasst worden.
- Am auffälligsten im Projekt ist die Änderung des Histogramms gegenüber dem Histogramm des Originalbildes beim Equalize-Effekt. Das Rot-Histogramm wird nach links (dunklerer Bereich gestreckt). Damit hat Rot wieder Kontrast und das Bild sieht wesentlich natürlicher aus:
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.
Download
k23/k23.4/k23.4.2/k23.4.2.7/start.txt · Zuletzt geändert: von 127.0.0.1

