Imports System.Collections.Generic Imports System.Linq Public Class ExempleRoro Public Sub New(ByVal Col0 As Integer, ByVal Col1 As Integer, ByVal Col2 As Integer) Me.New(Col0, Col1, Col2, 0) End Sub Public Sub New(ByVal Col0 As Integer, ByVal Col1 As Integer, ByVal Col2 As Integer, ByVal Count As Integer) Colonne0 = Col0 Colonne1 = Col1 Colonne2 = Col2 Compte = Count End Sub Public Property Colonne0() As Integer Public Property Colonne1() As Integer Public Property Colonne2() As Integer Private privateCompte As Integer Public Property Compte() As Integer Get Return privateCompte End Get Private Set(ByVal value As Integer) privateCompte = value End Set End Property Public Overrides Function ToString() As String Return String.Format("{0} {1} {2} {3}", Colonne0, Colonne1, Colonne2, Compte) End Function Public Shared Function Compter(ByVal Liste As List(Of ExempleRoro)) As List(Of ExempleRoro) Return ( From item In Liste Let c = Liste.Select(Function(tt) tt.Colonne0).Count(Function(ttt) ttt = item.Colonne0) Select New ExempleRoro(item.Colonne0, item.Colonne1, item.Colonne2, c)).ToList() End Function Public Shared Function SansDoublonsCol0(ByVal Liste As List(Of ExempleRoro)) As List(Of ExempleRoro) Return ( From item In Liste.OrderBy(Function(x) x.Colonne0).ThenByDescending(Function(xx) xx.Colonne1).GroupBy(Function(xxx) xxx.Colonne0) Select New ExempleRoro(item.Key, item.ElementAt(0).Colonne1, item.ElementAt(0).Colonne2, item.ElementAt(0).Compte)).ToList() End Function End Class
Dim maListe As New List(Of ExempleRoro)() maListe.Add(New ExempleRoro(4, 188, 193)) 'compte 1 affiche la ligne attendue à la fin maListe.Add(New ExempleRoro(7, 101, 116)) maListe.Add(New ExempleRoro(5, 188, 193)) 'compte 1 maListe.Add(New ExempleRoro(7, 186, 193)) 'compte 2 maListe.Add(New ExempleRoro(8, 93, 124)) maListe.Add(New ExempleRoro(9, 90, 127)) maListe.Add(New ExempleRoro(8, 185, 193)) 'compte 2 maListe.Add(New ExempleRoro(9, 184, 193)) 'comte 3 maListe.Add(New ExempleRoro(11, 83, 133)) maListe.Add(New ExempleRoro(9, 85, 13)) maListe.Add(New ExempleRoro(10, 184, 19)) 'compte 1 maListe.Add(New ExempleRoro(11, 183, 19)) 'compte 2 Dim maListeAvecCompte As List(Of ExempleRoro) = ExempleRoro.Compter(maListe) Dim maListeApureeEtTrieeParColonne0 As List(Of ExempleRoro) = ExempleRoro.SansDoublonsCol0(maListeAvecCompte)
Dim pc As New System.IO.StreamWriter("C:/count/pixelcompter.txt", False)
pc.WriteLine("Begin Count:")
pc.WriteLine()
pc.Close()
Dim img As Bitmap = New Bitmap(PictureBox1.Image)
Dim c As Color
Dim maListe As New List(Of ExempleRoro)()
For i = 0 To img.Width - 1
Dim toppix As Integer = 0
Dim pixlength As Integer = 0
Dim j As Integer
For j = 0 To img.Height - 1
c = img.GetPixel(i, j)
Dim r As Integer = 0
r = Convert.ToInt16(c.R)
Dim g As Integer = 0
g = Convert.ToInt16(c.G)
Dim b As Integer = 0
b = Convert.ToInt16(c.B)
Dim ans As Integer = ((r + (g + b)) / 3)
If (ans > 128) Then
r = 255
g = 255
b = 255
Else
r = 0
g = 0
b = 0
End If
Dim total As Integer = r + g + b
If toppix = 0 Then
If total < 765 Then
toppix = j
pixlength = 1
End If
Else
If total < 765 Then
pixlength += 1
Else
maListe.Add(New ExempleRoro(i, toppix - 1, toppix + pixlength))
toppix = 0
pixlength = 0
End If
End If
Next
Next
Dim maListeAvecCompte As List(Of ExempleRoro) = ExempleRoro.Compter(maListe)
Dim maListeApureeEtTrieeParColonne0 As List(Of ExempleRoro) = ExempleRoro.SansDoublonsCol0(maListeAvecCompte)
For Each element In maListeApureeEtTrieeParColonne0
Dim pce As New System.IO.StreamWriter("C:/count/pixelcompter.txt", True)
pce.WriteLine(element)
pce.Close()
Next
Public Shared Function SansDoublonsCol0(ByVal Liste As List(Of ExempleRoro)) As List(Of ExempleRoro) Dim groupeTrieeParCol0PuisCol1 = Liste.OrderBy(Function(x) x.Colonne0).ThenByDescending(Function(xx) xx.Colonne1).GroupBy(Function(xxx) xxx.Colonne0).ToList() 'la collection est triée par colO dans l'ordre et col1 en ordre inverse, ainsi le premier enregistrement contient le col1 le plus grand 'le groupBy génère une collection du type 'Clé1 'enregistrement 1 de la clé1 'enregistrement 2 de la clé1 '... 'Clé2 'enregistrement 1 de la clé2 'enregistrement 2 de la clé2 '... Dim PlusGrand As Boolean = True Dim retour As New List(Of ExempleRoro)() For Each item In groupeTrieeParCol0PuisCol1 If item.Count() = 1 Then retour.Add(New ExempleRoro(item.Key, item.First().Colonne1, item.First().Colonne2, item.First().Compte)) Else If PlusGrand Then retour.Add(New ExempleRoro(item.Key, item.First().Colonne1, item.First().Colonne2, item.First().Compte)) Else retour.Add(New ExempleRoro(item.Key, item.Last().Colonne1, item.Last().Colonne2, item.Last().Compte)) End If PlusGrand = Not PlusGrand End If Next item Return retour End Function
'reprise dans la colonne 4 des répétitions For i = LBound(Tablo, 2) To UBound(Tablo, 2) MonDico(Tablo(0, i)) = MonDico(Tablo(0, i)) + 1 Next For i = LBound(Tablo, 2) To UBound(Tablo, 2) Tablo(3, i) = MonDico(Tablo(0, i)) Next 'Création Tableau final Rep = 0 Ind = 0 x = 0 While Ind < UBound(Tablo, 2) If Tablo(3, Ind) = Rep Then For i = 0 To 2 ReDim Preserve tabfin(0 To 2, 0 To x) tabfin(i, x) = Tablo(i, Ind + Rep1 - 1) ' et non Ind+Rep1 Next i If Rep1 = 1 Then Rep1 = Rep Else Rep1 = Rep1 - 1 Ind = Ind + Rep x = x + 1 Else Rep = Tablo(3, Ind) Rep1 = Rep End If Wend
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Dim pc As New System.IO.StreamWriter("C:/Compter/pixelcompter.txt", False)
pc.WriteLine("Begin Count:")
pc.WriteLine()
pc.Close()
Dim img As Bitmap = New Bitmap(PictureBox1.Image)
Dim c As Color
For i = 0 To img.Width - 1
Dim toppix As Integer = 0
Dim pixlength As Integer = 0
Dim j As Integer
For j = 0 To img.Height - 1
c = img.GetPixel(i, j)
Dim r As Integer = 0
r = Convert.ToInt16(c.R)
Dim g As Integer = 0
g = Convert.ToInt16(c.G)
Dim b As Integer = 0
b = Convert.ToInt16(c.B)
Dim ans As Integer = ((r + (g + b)) / 3)
If (ans > 128) Then
r = 255
g = 255
b = 255
Else
r = 0
g = 0
b = 0
End If
Dim total As Integer = r + g + b
If toppix = 0 Then
If total < 765 Then
toppix = j
pixlength = 1
End If
Else
If total < 765 Then
pixlength += 1
Else
Dim pcr As New System.IO.StreamWriter("C:/Compter/pixelcompter.txt", True)
pcr.WriteLine(" " & i & " " & toppix - 1 & " " & toppix + pixlength)
pcr.WriteLine()
pcr.Close()
toppix = 0
pixlength = 0
End If
End If
Next
Next
Dim pcr As New System.IO.StreamWriter("C:/Compter/pixelcompter.txt", True)
pcr.WriteLine(" " & i & " " & toppix - 1 & " " & toppix + pixlength)
pcr.WriteLine()
pcr.Close()
Public Class Form1
Private Structure Structcolonne
Dim col0 As Integer
Dim col1 As Integer
Dim col2 As Integer
End Structure
Private listecols As New List(Of Structcolonne)
Private listecol As Structcolonne
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim img As Bitmap = New Bitmap(PictureBox1.Image)
Dim c As Color, r As Integer, g As Integer, b As Integer
Dim toppix As Integer, pixlength As Integer, total As Integer, ans As Integer
For i = 0 To img.Width - 1
toppix = 0
pixlength = 0
For j = 0 To img.Height - 1
c = img.GetPixel(i, j)
r = Convert.ToInt32(c.R)
g = Convert.ToInt32(c.G)
b = Convert.ToInt32(c.B)
ans = (r + g + b) \ 3
If (ans > 127) Then
r = 255 : g = 255 : b = 255
Else
r = 0 : g = 0 : b = 0
End If
total = r + g + b
If toppix = 0 Then
If total < 765 Then
toppix = j
pixlength = 1
End If
Else
If total < 765 Then
pixlength += 1
Else
With listecol
.col0 = i
.col1 = toppix - 1
.col2 = toppix + pixlength
End With
listecols.Add(listecol)
toppix = 0
pixlength = 0
End If
End If
Next
Next
For i = 0 To listecols.Count - 1
With listecols(i)
ListBox1.Items.Add(.col0.ToString)
ListBox2.Items.Add(.col1.ToString)
ListBox3.Items.Add(.col2.ToString)
End With
Next
End Sub
End Class
2) Je récupère les départ et arrivée (d'une couleur) de chaque colonne de toute l'image
Private listnum As New List(Of List(Of Int32))
'la liste des résultats
Private listresult As New List(Of List(Of Int32))
Private list1 As New List(Of String)
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
'on lit ton fichier pixelcompter.txt et on le décompose
GetList()
DataProcess()
End Sub
Private Sub GetList()
list1 = IO.File.ReadAllLines("C:/Compter/pixelcompter.txt").ToList
Dim numbers As List(Of Int32)
Dim vect() As String
For Each item In list1
vect = item.Split(New Char() {}, StringSplitOptions.RemoveEmptyEntries)
numbers = New List(Of Int32)
For Each num In vect
numbers.Add(Convert.ToInt32(num))
Next
listnum.Add(numbers)
Next
End Sub
Private Sub DataProcess()
' selon ton algo
' En colonne 0 : un numéro unique ou répété
'Donc en partant du départ du tableau colonne "0":
'Si le numéro est unique alors je récupère la ligne
'autrement Si le numéro est répété alors
'je récupères qu'une seule ligne des numéro répété avec comme 'condition:
'à la première ligne de la colonne "0" si le numéro est répété 'alors
'je prends la valeur la plus haute de la colonne "1" et je conserve 'donc cette ligne.
'Ensuite je continu et dans la série d'après quelque soit le 'nombre de répetition je prend la valeur inférieur à celle d'avant .
'Lorsque j'arrive à la valeur la plus petite ; je redémarre avec une 'valeur la plus haute
'jusqu'à arrivé à un numéro unique
Dim flaghighest As Boolean = True
Dim data As New List(Of Int32)
Dim lastindex As Int32
lastindex = listnum(0)(0)
listresult.Add(listnum(0))
For iter = 1 To listnum.Count - 1
If listnum(iter)(0) <> lastindex Then
'index unique
listresult.Add(listnum(iter))
lastindex = listnum(iter)(0)
ElseIf flaghighest Then
'get highest value
If listnum(iter)(1) > listnum(iter - 1)(1) Then
listresult.RemoveAt(listresult.Count - 1)
listresult.Add(listnum(iter))
End If
lastindex = listnum(iter)(0)
flaghighest = False
Else
'get lowest value
If listnum(iter)(1) < listnum(iter - 1)(1) Then
listresult.RemoveAt(listresult.Count - 1)
listresult.Add(listnum(iter))
End If
lastindex = listnum(iter)(0)
flaghighest = True
End If
Next
End Sub
End Class