'pixelbender flash10 shader sobel'에 해당하는 글 1건

2차원 기반의 외곽선 검출 방법을 찾던중 Sobel Operation에 대해서 알게되었다.
이 연산을 통해서 외곽선의 방향과 강도 따위를 결정할 수 있다.

그리고 Sobel Operation을 통해서 검출된 외곽선과 원본 이미지를 합성하여 보았다.
단지 그것뿐.

PIxel Bender Language는 함수도 가능하고 기타 다른 내장 함수도 사용할 수 있지만
Flash Player 10 용으로 사용할 때에는 제약상 evaluatePixel 함수만 사용하기 때문에
코드가 살짝 길어졌다. 또한 내장 함수는 아직 무엇이 있는지 잘 몰라서 행렬연산을
직접 하나씩 풀어내었더니 더 길어진듯.
어쨌거나 잘 동작한다. 코드는 다음과 같고

 <languageVersion : 1.0;>


kernel SobelFilter

<   namespace : "buzzler";

    vendor : "Mobsword Systems";

    version : 1;

    description : "Sobel Operation";

>

{

    input   image4  src;

    output  pixel4  dst;

    const   pixel4  black   = pixel4(0.0, 0.0, 0.0, 1.0);

    const   float   low     = 1.0;

    const   float   high    = 2.0;

    const   float   p_width = 1.0;


    void    evaluatePixel()

    {

        float   g, gx, gy;

        float2  coord = outCoord();

        pixel4  sampled;

        float   tone;

        

        sampled = sampleLinear(src, float2(coord[0]-p_width , coord[1]-p_width));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gx += low * tone;

        gy += low * tone;

        

        sampled = sampleLinear(src, float2(coord[0] , coord[1]-p_width));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gy += high * tone;

        

        sampled = sampleLinear(src, float2(coord[0]+p_width , coord[1]-p_width));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gx -= low * tone;

        gy += low * tone;

        

        sampled = sampleLinear(src, float2(coord[0]-p_width , coord[1]));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gx += high * tone;

        

        sampled = sampleLinear(src, float2(coord[0]+p_width , coord[1]));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gx -= high * tone;

        

        sampled = sampleLinear(src, float2(coord[0]-p_width , coord[1]+p_width));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gx += low * tone;

        gy -= low * tone;

        

        sampled = sampleLinear(src, float2(coord[0] , coord[1]+p_width));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gy -= high * tone;

        

        sampled = sampleLinear(src, float2(coord[0]+p_width , coord[1]+p_width));

        tone = (sampled.r + sampled.g + sampled.b) / 3.0;

        gx -= low * tone;

        gy -= low * tone;

        

        g = sqrt(pow(gx, 2.0) + pow(gy, 2.0));

        dst = mix(sampled, black, g);

    }

}



출력된 이미지

출력된 이미지

입력된 이미지

입력된 이미지

'Pixel Bender' 카테고리의 다른 글

PixelBender Outline View  (0) 2008.11.05
Scketch Shader를 위한 PV3D 튜닝  (0) 2008.10.07
Flex와 Pixel Bender로 iChat 흉내내기  (0) 2008.09.25
Human Detector!  (2) 2008.09.25
Sketch Shader  (0) 2008.09.18

WRITTEN BY
buzzler

,