| |
|
|
Sven Bader | here have I a code for a Weichzeichen-filter, from performance-Found sooner for small Graphics suitable.
About whom third Parameter the Blur-function can itself steer, How often the filter applied becomes.
Proc Blur
Parameters width&, height&, passes&
Declare avg_red&, avg_green&, avg_blue&, new_image&[width&-1, height&-1, 2]
Declare count&, box&, x&, y&, i&, j&
whileLoop passes&
box& = 1
WhileLoop 0, width& - 1
i& = &loop
WhileLoop 0, height& - 1
j& = &loop
clear avg_red&, avg_blue&, avg_green&, count&
WhileLoop (i& - box&), (i& + box&)
x& = &loop
Case (x& = width&) : Break
Case (x& < 0) : Continue
WhileLoop (j& - box&), (j& + box&)
y& = &loop
case (y& = height&) : Break
case (y& < 0) : Continue
inc count&
avg_red& = avg_red& + image&[x&, y&, 0]
avg_green& = avg_green& + image&[x&, y&, 1]
avg_blue& = avg_blue& + image&[x&, y&, 2]
EndWhile
EndWhile
new_image&[i&, j&, 0] = avg_red& / count&
new_image&[i&, j&, 1] = avg_green& / count&
new_image&[i&, j&, 2] = avg_blue& / count&
EndWhile
EndWhile
MAT image&[] = new_image&[]
EndWhile
ENDPROC
Cls
Declare x&, y&, px&, width&, height&
'===================== Image aray reading
DrawIcon "EIS", 50, 50
width& = 32
height& = 32
Declare image&[width&-1, height&-1, 2]
WhileLoop 0, height& - 1
y& = &loop
WhileLoop 0, width& - 1
x& = &loop
px& = GetPixel(50 + x&, 50 + y&)
image&[x&, y&, 0] = GetRValue(px&)
image&[x&, y&, 1] = GetGValue(px&)
image&[x&, y&, 2] = GetBValue(px&)
EndWhile
EndWhile
'===================== filter utilize
Blur(width&, height&, 5)
'===================== geglättetes Image Show
WhileLoop 0, height& - 1
y& = &loop
WhileLoop 0, width& - 1
x& = &loop
SetPixel 100 + x&, y& + 50, RGB(image&[x&, y&, 0], image&[x&, y&, 1], image&[x&, y&, 2])
EndWhile
EndWhile
WaitKey
End
The Flaschenhals is not once the filter self (where the too) separate the GetPixel and SetPixel. bypass could to the to that example over a 24-bit-Bitmap-File, everybody can as block einliest.
One qualitativer Tweak would, The function only a Teilbereich glätten To let, The Borders but nevertheless in the aray vorzuhalten. then would The Randbereiche not so disjointed looks. For this, should one then The 4 Case-inquire Remove and the x/y-Offset as Parameter mitgeben.
plenty Fun at Glätten |
|
|
| |
|
|