je met ce code en cas si il peut apporter à servir.
Code : Tout sélectionner
Enumeration
#image_0
#image
#image_1
#image_2
#window_0
#image_origine
#button_1
#button_2
#button_3
#button_0
#button_4
#button_5
EndEnumeration
Global Threshold = 5
Global Progress.i = 0
Procedure.d Min(a.d,b.d)
If a<b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
Procedure.d Max(a.d,b.d)
If a>b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
Structure VECTOR3
x.f : y.f : z.f
EndStructure
Macro SetVector3(V,_x,_y,_z)
V\x=_x
V\y=_y
V\z=_z
EndMacro
Macro VectorLength(V)
(V\x*V\x + V\y*V\y + V\z*V\z)
EndMacro
Macro Normalize(V)
l.f = VectorLength(V)
If (l <> 0)
l = Sqr(l)
V\x / l
V\y / l
V\z / l
EndIf
EndMacro
Procedure.f DotProduct(*A.VECTOR3,*B.VECTOR3)
ProcedureReturn *A\X * *B\X + *A\Y * *B\Y + *A\Z * *B\Z
EndProcedure
Macro CharToByte(Char)
Char/255.0
EndMacro
Macro ByteToChar(Byte)
Byte*255
EndMacro
Procedure GetGrayLevel(x,y)
Color = Point(x,y)
Red = Red(Color)
Green = Green(Color)
Blue = Blue(Color)
Gray = (Red+Green+Blue)/3
ProcedureReturn Gray
EndProcedure
Procedure Map0_to_255(*V.VECTOR3)
*V\x = max(-256,*V\x)
*V\y = max(-256,*V\y)
*V\z = max(-256,*V\z)
*V\x = min(256,*V\x)
*V\y = min(256,*V\y)
*V\z = min(256,*V\z)
*V\x =*V\x/2 + 127
*V\y =*V\y/2 + 127
*V\z =*V\z/2 + 127
EndProcedure
Procedure Conv3x3(ImageID, Array Gradient.f(2) , Array Sobel(2))
StartDrawing(ImageOutput(ImageID))
For y = 1 To ImageHeight(ImageID)-2
For x = 1 To ImageWidth(ImageID)-2
Gradient(x,y) = (CharToByte(GetGrayLevel(x-1,y-1))*Sobel(0,0))+(CharToByte(GetGrayLevel(x,y-1))*Sobel(1,0))+(CharToByte(GetGrayLevel(x+1,y-1))*Sobel(2,0))+(CharToByte(GetGrayLevel(x-1,y))*Sobel(0,1))+(CharToByte(GetGrayLevel(x,y-1))*Sobel(1,1))+(CharToByte(GetGrayLevel(x+1,y))*Sobel(2,1))+(CharToByte(GetGrayLevel(x-1,y+1))*Sobel(0,2))+(CharToByte(GetGrayLevel(x,y+1))*Sobel(1,2))+(CharToByte(GetGrayLevel(x+1,y+1))*Sobel(2,2))
Gradient(x,y) * Threshold
;SetGadgetState(0,Progress) : SmartWindowRefresh(0,1)
; Progress + 1
Next
Next
StopDrawing()
EndProcedure
Global Dim SobelX(2,2) :
SobelX(0,0)=-1 : SobelX(1,0)=-2 : SobelX(2,0)=-1
SobelX(0,1)=0 : SobelX(1,1)=0 : SobelX(2,1)=0
SobelX(0,2)=1 : SobelX(1,2)=2 : SobelX(2,2)=1
Global Dim SobelY(2,2) :
SobelY(0,0)=-1 : SobelY(1,0)=0 : SobelY(2,0)=1
SobelY(0,1)=-2 : SobelY(1,1)=0 : SobelY(2,1)=2
SobelY(0,2)=-1 : SobelY(1,2)=0 : SobelY(2,2)=1
UsePNGImageDecoder()
UseJPEG2000ImageDecoder()
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
UsePNGImageEncoder()
UseJPEG2000ImageEncoder()
UseJPEGImageEncoder()
UsePNGImageEncoder()
Procedure CouleurGris(x,y)
Color = Point(x,y)
Red = Red(Color)
Green = Green(Color)
Blue = Blue(Color)
Gray = (Red+Green+Blue)/3
ProcedureReturn Gray
EndProcedure
Procedure ConvertirSepia(ImageID)
StartDrawing(ImageOutput(ImageID))
For y = 0 To ImageHeight(ImageID)-1
For x = 0 To ImageWidth(ImageID)-1
Gray=CouleurGris(x,y)
Plot(x,y,RGB((gray+112)/2,(gray+44)/2,(gray+20)/2)); (112, 44, 20)
Next
Next
StopDrawing()
EndProcedure
Procedure ConvertirGris(ImageID)
StartDrawing(ImageOutput(ImageID))
For y = 0 To ImageHeight(ImageID)-1
For x = 0 To ImageWidth(ImageID)-1
Gray=CouleurGris(x,y)
Plot(x,y,RGB(gray,gray,gray))
Next
Next
StopDrawing()
EndProcedure
Procedure ConvertirProfondeur(ImageID)
Global Dim GradientX.f(ImageWidth(ImageID),ImageHeight(ImageID))
Global Dim GradientY.f(ImageWidth(ImageID),ImageHeight(ImageID))
Conv3x3(ImageID, gradientX(), sobelX() );
Conv3x3(ImageID, gradientY(), sobelY() );
StartDrawing(ImageOutput(ImageID))
For y = 0 To ImageHeight(ImageID)-1
For x = 0 To ImageWidth(ImageID)-1
V.VECTOR3
SetVector3(V,GradientX(x,y),GradientY(x,y),1)
Normalize(V)
Color.VECTOR3
SetVector3(Color,ByteToChar(V\x),ByteToChar(V\y),ByteToChar(V\z))
Map0_to_255(Color)
Plot(x,y,RGB(Color\x,Color\y,Color\z))
Next
Next
StopDrawing()
EndProcedure
Filtre$ = "Images|*.bmp;*.jpg;*.png;*.tga;*.tif"
If OpenWindow(#Window_0, 0, 0, 800, 700, "",#PB_Window_ScreenCentered| #PB_Window_TitleBar )
CreateImage(#image_0,800,600)
ImageGadget(#image_1, 0, 0, 800,600, ImageID(#image_0))
ButtonGadget(#button_0,10,600,150,30,"Ouvrir image")
ButtonGadget(#button_1,400,600,150,30,"Sepia piere")
ButtonGadget(#button_3,400,650,150,30,"Gris dessin")
ButtonGadget(#button_4,200,600,150,30,"Sepia")
ButtonGadget(#button_5,200,650,150,30,"Gris")
ButtonGadget(#button_2,600,650,40,30,"Fermer")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget()=#button_2
End
EndIf
If EventGadget()=#button_0
fichier$=OpenFileRequester("Ouvrir image","",Filtre$,0)
If fichier$
LoadImage(#image_origine,fichier$)
ResizeImage(#image_origine,800,600)
SetGadgetState(#image_1,ImageID(#image_origine))
EndIf
EndIf
If EventGadget()=#button_1
CopyImage(#image_origine,#image)
ConvertirProfondeur(#image)
ConvertirSepia(#image)
SetGadgetState(#image_1,ImageID(#image))
EndIf
If EventGadget()=#button_3
CopyImage(#image_origine,#image)
ConvertirProfondeur(#image)
ConvertirGris(#image)
SetGadgetState(#image_1,ImageID(#image))
EndIf
If EventGadget()=#button_4
CopyImage(#image_origine,#image)
ConvertirSepia(#image)
SetGadgetState(#image_1,ImageID(#image))
EndIf
If EventGadget()=#button_5
CopyImage(#image_origine,#image)
ConvertirGris(#image)
SetGadgetState(#image_1,ImageID(#image))
EndIf
EndIf
ForEver
EndIf