× Aktuálně z oboru

Vychází Game Ready ovladače pro Far Cry 5 [ clanek/2018040603-vychazi-game-ready-ovladace-pro-far-cry-5/ ]
Celá zprávička [ clanek/2018040603-vychazi-game-ready-ovladace-pro-far-cry-5/ ]

Práce s grafikou XIII - Plastický obraz

[ http://programujte.com/profil/27-jiri-chytil/ ]Google [ ?rel=author ]       [ http://programujte.com/profil/75-martin-zak/ ]Google [ :?rel=author ]       5. 2. 2006       9 788×

Ve světě grafiky je tolik filtrů, že si to snad ani nedovedeme představit. A ještě víc je jejich modifikací a jejich kombinací a tak dále. Nastavením různých parametrů opět dosahujeme jiných změn...
..

Některé filtry se objeví jen tak. Náhodou píšete, píšete a je to tu. Stejně jako tento filtr, který je vlastně vedlejším produktem při tvorbě úplně jiného filtru, o kterém jsem psal a to je ostření.

Jeho kód vypadá takto:


Public Sub Plastic(Img As PictureBox, img2 As PictureBox, Value As Long)
    Img.DrawWidth = 1
    Img.ScaleMode = 3
    Img.AutoRedraw = True
    rgbmax = 256
    On Error Resume Next
        For x = 0 To Img.ScaleWidth
            For y = 0 To Img.ScaleHeight
                DoEvents
                ImgP = GetPixel(Img.hdc, x, y)
                b0 = ImgP  rgbmax  rgbmax
                g0 = (ImgP  rgbmax) Mod rgbmax
                r0 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x + Value, y)
                b1 = ImgP  rgbmax  rgbmax
                g1 = (ImgP  rgbmax) Mod rgbmax
                r1 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x, y + Value)
                b2 = ImgP  rgbmax  rgbmax
                g2 = (ImgP  rgbmax) Mod rgbmax
                r2 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x - Value, y)
                b3 = ImgP  rgbmax  rgbmax
                g3 = (ImgP  rgbmax) Mod rgbmax
                r3 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x, y - Value)
                b4 = ImgP  rgbmax  rgbmax
                g4 = (ImgP  rgbmax) Mod rgbmax
                r4 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x - Value, y - Value)
                b5 = ImgP  rgbmax  rgbmax
                g5 = (ImgP  rgbmax) Mod rgbmax

                r5 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x + Value, y - Value)
                b6 = ImgP  rgbmax  rgbmax
                g6 = (ImgP  rgbmax) Mod rgbmax
                r6 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x - Value, y + Value)
                b7 = ImgP  rgbmax  rgbmax
                g7 = (ImgP  rgbmax) Mod rgbmax
                r7 = ImgP Mod rgbmax
               ImgP = GetPixel(Img.hdc, x + Value, y + Value)
                b8 = ImgP  rgbmax  rgbmax
                g8 = (ImgP  rgbmax) Mod rgbmax
                r8 = ImgP Mod rgbmax
                
                r = ((-r0) - (r5 + r7 + r3)) + (r1 + r6 + r8 + r2 + r4)
                g = ((-g0) - (g5 + g7 + g3)) + (g1 + g6 + g8 + g2 + g4)
                b = ((-b0) - (b5 + b7 + b3)) + (b1 + b6 + b8 + b2 + b4)

                If r >= 255 Then r = 255
                If g >= 255 Then g = 255
                If b >= 255 Then b = 255
                If r <= 0 Then r = 0
                If g <= 0 Then g = 0
                If b <= 0 Then b = 0
                
                Call SetPixel(img2.hdc, x, y, RGB(r, g, b))
            Next y
            DoEvents
        Next x
End Sub

Upřímně řečeno, když vidím ten vzorec, tak nic moc. Se docela divím, že to vůbec funguje. Tak jak ten vzorec vidíte, tak vypadl, když jsem ho napsal prakticky omylem. Tak jsem ho trochu upravil.


r = (r1 + r6 + r8 + r2 + r4) - (r0 + r5 + r7 + r3)

Jak jednoduché jsou to rozdíly součtů jednotlivých okolních bodů. A tak pěkně to funguje. Však zkuste a uvidíte, optimální hodnoty jsou asi:


Plastic Picture1, Picture2, 1

Při hodnotách jiných se tento efekt výrazně mění (např. s hodnotami 10 a víc-ale ne o moc-tak do 30, ale to už často nepoznáte předešlý motiv, ale stojí za to to vyzkoušet, ale pak je potřeba tento efekt přejmenovat).

Třeba mně se povedlo s hodnotami:


Plastic Picture1, Picture2, 60

Dosáhnout tohoto:

A to z koňské hlavy, kterou používám jako testovací obrázek.

To je pro dnešek vše.


Článek stažen z webu Programujte.com [ http://programujte.com/clanek/2006013101-prace-s-grafikou-xiii-plasticky-obraz/ ].