Imitation coal drawing
Posted: Thu Nov 24, 2016 10:15 am
It was

and became

code program:

and became

code program:
Code: Select all
UseJPEGImageEncoder()
UseJPEGImageDecoder()
Value = 0 ; Or 1
Threshold =270 ;The threshold of sensitivity
Pattern$ = "Image |*.jpg;*.bmp"
Pattern = 0
File$ = OpenFileRequester("Image JPG,BMP", StandardFile$, Pattern$, Pattern)
If File$
If LoadImage(0,File$)
Dim Colors(ImageWidth(0),ImageHeight(0))
StartDrawing( ImageOutput(0))
For x = 0 To ImageWidth(0) -1
For y = 0 To ImageHeight(0)-1
Colors(x,y) = Point(x, y)
Next
Next
StopDrawing()
CopyImage(0, 1)
EndIf
StartDrawing( ImageOutput(1))
For x = 1 To ImageWidth(0) - 2
For y = 1 To ImageHeight(0) - 2
temp = Colors(x,y)
Orig_blue = Blue(temp)
Orig_green = Green(temp)
Orig_red = Red(temp)
Diff = 0
For xx = x - 1 To x + 1
For yy = y - 1 To y + 1
If (xx <> x) Or (yy <> y)
temp = Colors(xx,yy)
Other_blue = Blue(temp)
Other_green = Green(temp)
Other_red = Red(temp)
temp = (Orig_red - Other_red) * (Orig_red - Other_red) + (Orig_blue - Other_blue)*(Orig_blue - Other_blue)+(Orig_green - Other_green) * (Orig_green - Other_green)
Diff = Diff +Sqr(temp)
EndIf
Next yy
Next xx
If Value = 0
Diff = 255 - Diff
If Diff < 0: Diff = 0: EndIf
If Diff > 255: Diff = 255:EndIf
Plot (x, y, RGB(Diff, Diff, Diff))
Else
If Diff > Threshold
Diff = 255 - (Diff - Threshold)
If Diff < 0 : Diff = 0:EndIf
If Diff > 255 : Diff = 255:EndIf
Plot (x, y, RGB(Diff, Diff, Diff))
Else
Plot (x, y, RGB(255, 255, 255))
EndIf
EndIf
Next y
Next x
StopDrawing()
If SaveImage(1,GetTemporaryDirectory() + "charcoal.jpg",#PB_ImagePlugin_JPEG)
RunProgram(GetTemporaryDirectory() + "charcoal.jpg")
EndIf
Else
MessageRequester("Information", "The requester was canceled.", 0)
EndIf