Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (2 posts)

Pattern recognition Pixel Shader won't compile [HLSL]

Last post 2/9/2016 6:52 AM by Charybdis. 1 replies.
  • 3/30/2012 10:05 AM

    Pattern recognition Pixel Shader won't compile [HLSL]

    Hi,

    I have a need  for a very simple pattern recognition on a big image (resolution 1650*1050). The image is all black and white. I thought about using a pixel shader, since it works on all the pixel of an image at the same time, I thought  it would be faster than using the C# Bitmap class GetPixel function.

    Here's the approach I am using :

    I put the image where I want to find the pattern in the s0 register.
    I put the pattern in the s1 register (both texture are 512x512)

    For each pixel of my original image (where I want to find the pattern), I check it's surrounding pixel against the pixel of the texture in my s1 register. If the all match, I output a pink (255,0,255) pixel on my original image.

    here is the code for my IsPattern function :

    bool isPattern(float2 texCoord)

    {

        float2 currentTest;

        float2 offset;

        offset = 0.5 / 512.0;

        bool final;

        final = true;

        currentTest.x = 0 / 512.0;

        currentTest.y = 0 / 512.0;

        final = final && (tex2D(TextureSampler, texCoord + currentTest) == tex2D(pattern, currentTest + offset));

        currentTest.x = 0 / 512.0;

        currentTest.y = 1 / 512.0;

        final = final && (tex2D(TextureSampler, texCoord + currentTest) == tex2D(pattern, currentTest + offset));

        currentTest.x = 1 / 512.0;

        currentTest.y = 0 / 512.0;

        final = final && (tex2D(TextureSampler, texCoord + currentTest) == tex2D(pattern, currentTest + offset));

        currentTest.x = 1 / 512.0;

        currentTest.y = 1 / 512.0;

        final = final && (tex2D(TextureSampler, texCoord + currentTest) == tex2D(pattern, currentTest + offset));

        return final;

    }


    And here is the code that calls this function :

    if (isPattern(texCoord))

    {

        tex.r = 1;

        tex.g = 0;

        tex.b = 1;

    }


    This works perfectly ! i can recognistion any 2x2 pattern. However, as soon as I start to increase the number of pixels I am checking, the shader code stops compiliing (ie 5x5 doesn't compile, and I would need to go as high as 10x10). Is there something I can optimise?

    Alternatively, if using a pixel shader is not a good idea for this, can you recommend an alternative way of recognising pattern on a large image ? (My image are Black & White, and the pattern recognition would need to be exact. It would not need to run in real time, so up to half a second for a full (1650x150) image would be ok.

    Thank you for any suggestions you might have !
  • 2/9/2016 6:52 AM In reply to

    Re: Pattern recognition Pixel Shader won't compile [HLSL]

    What shader profile do you need to use for your target system?
Page 1 of 1 (2 posts) Previous Discussion Next Discussion