Re: image .. reduction des couleurs
Publié : dim. 13/mars/2016 14:14
Ajout de pathimage$ pour retrouver la photo sauvée au même endroit que l'originale
et évidement dns la sauvegarde
J'ai fait des essais en 512, le resultat est vraiment pas très beau. Il faudrait trouver un bon algo de conversion.
J'ai fait ça mais j'ai du me piner quelque part. ^^
Code : Tout sélectionner
If NomFichier$<>""
Resultat = LoadImage(#Image, NomFichier$ ) ; on charge une image
pathImage$ = GetPathPart(NomFichier$) ; Ici
Global format$=GetExtensionPart(NomFichier$)
EndIf
Code : Tout sélectionner
SaveImage(#image,pathimage$+"resultat_en_"+str(couleur)+".bmp",#PB_ImagePlugin_BMP)
J'ai fait ça mais j'ai du me piner quelque part. ^^
Code : Tout sélectionner
Procedure FloydSteinberg(nb_image)
; by Ar-S // Pseudo code ici : https://fr.wikipedia.org/wiki/Algorithme_de_Floyd-Steinberg
largeur_image=ImageWidth(nb_image)
Hauteur_image=ImageHeight(nb_image)
; mise en tableau
Global Dim TAB(largeur_image,Hauteur_image)
StartDrawing(ImageOutput(nb_image))
For y=0 To Hauteur_image-1
For x=0 To largeur_image-1
TAB(x,y)=Point(x,y)
Next x
Next y
; PSEUDO CODE
; ancien_pixel := pixel[x][y]
; nouveau_pixel := couleur_la_plus_proche(ancien_pixel)
; pixel[x][y] := nouveau_pixel
; erreur_quantification := ancien_pixel - nouveau_pixel
; pixel[x+1][y ] := pixel[x+1][y ] + 7/16 * erreur_quantification
; pixel[x-1][y+1] := pixel[x-1][y+1] + 3/16 * erreur_quantification
; pixel[x ][y+1] := pixel[x ][y+1] + 5/16 * erreur_quantification
; pixel[x+1][y+1] := pixel[x+1][y+1] + 1/16 * erreur_quantification
;Traitement
For y=0 To Hauteur_image-1
For x=0 To largeur_image-1
If y>0 And X > 1
Debug "ok"
OldPix = TAB(x,y)
I1 = TAB(x+1,y+1)
I2 = TAB(x-1,y+2)
I3 = Tab(x,y+1)
I4 = Tab(x+1,y+2)
If OldPix+I1 < OldPix+I2 And OldPix+I1 < OldPix+I3 And OldPix+I1 < OldPix+I4
NewPix = I1
ElseIf OldPix+I2 < OldPix+I1 And OldPix+I2 < OldPix+I3 And OldPix+I2 < OldPix+I4
NewPix = I2
ElseIf OldPix+I3 < OldPix+I1 And OldPix+I3 < OldPix+I2 And OldPix+I3 < OldPix+I4
NewPix = I3
Else
NewPix = I4
EndIf
TAB(x,y) = NewPix
Err = OldPix-NewPix
TAB(x+1,y) = TAB(x+1,y) + 7/16 * Err
TAB(x-1,y+1) = TAB(x-1,y+1) + 3/16 * Err
TAB(x,y+1) = TAB(x,y+1) + 5/16 * Err
TAB(x+1,y+1) = TAB(x+1,y+1) + 1/16 * Err
EndIf
Next x
Next y
;Creation image tramée
For y=0 To Hauteur_image-1
For x=0 To largeur_image-1
Coul = Tab(x,y)
Plot(x,y,coul)
Next x
Next y
StopDrawing()
MessageRequester("terminé","Terminé",0)
EndProcedure