Hallo,
ich habe zwei Methoden, welche viel zu lange rechnen, leider sehe ich nirgends Potenzial sie schneller zu gestalten, vielleicht seht ihr Ansätze. Die Methoden sollen ein 16 bit S/W Bild in ein 8 Bit Bild umwandeln.
Diezweite Methode ist folgende, diese benötigt gute 4sec.
ich habe zwei Methoden, welche viel zu lange rechnen, leider sehe ich nirgends Potenzial sie schneller zu gestalten, vielleicht seht ihr Ansätze. Die Methoden sollen ein 16 bit S/W Bild in ein 8 Bit Bild umwandeln.
VB.NET-Quellcode
- Private Function Fits2Byte(ByVal arImage As System.Array, _
- ByVal trackGammaValue As Integer, ByVal trackMinimumImageValue As Integer, _
- ByVal trackMaximumImageValue As Integer) As Byte(,)
- Trace.WriteLine("$ Fits2Byte")
- Trace.WriteLine("$ Fits2Byte Start:" & Now.ToString)
- 'black(level)
- Dim intBlackLevel As Integer = trackMinimumImageValue
- 'Scale, white - black
- Dim intScale As Integer = trackMaximumImageValue - intBlackLevel
- Dim intRowsImage As Integer = arImage.GetLength(1)
- Dim intColumnImage As Integer = arImage.GetLength(0)
- Dim bytearImage(,) As Byte
- 'Helligkeitswerte in 16Bit
- Dim intOriginalLumValue As Integer
- Dim j As Integer
- 'Gammastufen()
- Dim byteGamma As Byte() = New Byte(255) {}
- Dim dblGamma As Double = CDbl(trackGammaValue)
- ReDim bytearImage(intColumnImage, intRowsImage)
- 'Helligkeiten
- Dim byteLum(65535) As Int32
- For i As Integer = 0 To 255
- byteGamma(i) = CByte((Math.Pow(CDbl(i) / 256.0R, dblGamma) * 256.0R)) 'Gammakurve erstellen
- Next
- Trace.WriteLine("$ Lum16ToLum8")
- Trace.WriteLine("$ Lum16ToLum8 Start:" & Now.ToString)
- For i = 0 To 65535
- byteLum(i) = byteGamma(Lum16ToLum8(i, intBlackLevel, intScale)) 'Einteilung der Helligkeiten von 16 Bit in 8 Bit
- Next
- Trace.WriteLine("$ Lum16ToLum8 Ende:" & Now.ToString)
- ' Bis hierher gehts schnell!
- 'Ab hier bis zum Ende benötigt die Methode gute 2sec!
- For i = 0 To intRowsImage - 1
- For j = 0 To intColumnImage - 1
- intOriginalLumValue = Convert.ToInt32(arImage.GetValue(j, i))
- 'convert 16 bit signed to 16 bit unsigned
- If intOriginalLumValue < 0 Then
- intOriginalLumValue += 65535
- End If
- bytearImage(j, i) = byteLum(intOriginalLumValue)
- Next
- Next
- Trace.WriteLine("$ Fits2Byte Ende:" & Now.ToString)
- Return bytearImage
- End Function
Diezweite Methode ist folgende, diese benötigt gute 4sec.
VB.NET-Quellcode
- Try
- Dim imgPtr As IntPtr = bmpdata.Scan0 'Zeiger auf Bild
- Dim tmpImage As Byte
- Dim Pixel As Integer = 0
- Dim offs As Integer
- For intRows As Integer = 0 To bytearImage.GetUpperBound(1) - 1
- For intColumn As Integer = 0 To bytearImage.GetUpperBound(0) - 1
- Try
- offs = (intRows * bmpImage.Width + intColumn) * bytesPerPixel
- 'offs = (intRows + intColumn * bmpImage.Width) * bytesPerPixel
- tmpImage = bytearImage(intColumn, intRows)
- System.Runtime.InteropServices.Marshal.WriteByte(bmpdata.Scan0, offs, tmpImage)
- System.Runtime.InteropServices.Marshal.WriteByte(bmpdata.Scan0, offs + 1, tmpImage)
- System.Runtime.InteropServices.Marshal.WriteByte(bmpdata.Scan0, offs + 2, tmpImage)
- Catch ex As Exception
- MessageBox.Show("$ Byte2Image: Fehler in Reihe:" & intRows.ToString & " Spalte: " & intColumn.ToString & vbNewLine & _
- " tmpImagevalue: " & tmpImage.ToString & " Offset: " & offs.ToString & vbNewLine & _
- ex.Message)
- Trace.WriteLine("$ Byte2Image: Fehler in Reihe:" & intRows.ToString & " Spalte: " & intColumn.ToString & vbNewLine & _
- " tmpImagevalue: " & tmpImage.ToString & " Offset: " & offs.ToString & vbNewLine & _
- ex.Message)
- Exit For
- End Try
- Next
- Next
- bmpImage.UnlockBits(bmpdata) 'zurückschreiben des Bildes
- imgOriginalImage = bmpImage 'Rückgabe in globale Variable
- Catch ex As Exception
- Trace.WriteLine("$ Byte2Image: " & ex.Message)
- MessageBox.Show("$ Byte2Image: " & ex.Message)
- End Try