Beispiel #1
0
float4 ExpandedFirstOctaveColor(uint i)  //Calculate octv 0, layer 0's ith pixel's color - (expand original image & smooth it first).
{
    GSIFT_AliS g = G;
    uint       id1 = 0, id2 = 0, id3 = 0, id4 = 0;

    if (i % g.imageSize.x == g.imageSize.x - 1 && i / g.imageSize.x == g.imageSize.y - 1)
    {
        id1 = i; id2 = i - 1; id3 = i - g.imageSize.x; id4 = i - g.imageSize.x - 1;
    }
    else if (i % g.imageSize.x == g.imageSize.x - 1 && i / g.imageSize.x < g.imageSize.y - 1)
    {
        id1 = i; id2 = i - 1; id3 = i + g.imageSize.x; id4 = i + g.imageSize.x - 1;
    }
    else if (i % g.imageSize.x != g.imageSize.x - 1 && i / g.imageSize.x == g.imageSize.y - 1)
    {
        id1 = i; id2 = i + 1; id3 = i - g.imageSize.x; id4 = i - g.imageSize.x + 1;
    }
    else
    {
        id1 = i; id2 = i + 1; id3 = i + g.imageSize.x; id4 = i + g.imageSize.x + 1;
    }
    float4 c1 = c32_f4(OriginalImage[id1]), c2 = c32_f4(OriginalImage[id2]), c3 = c32_f4(OriginalImage[id3]), c4 = c32_f4(OriginalImage[id4]);
    float  red = (c1.r + c2.r + c3.r + c4.r) / 4.0f, green = (c1.g + c2.g + c3.g + c4.g) / 4.0f, blue = (c1.b + c2.b + c3.b + c4.b) / 4.0f, alpha = (c1.a + c2.a + c3.a + c4.a) / 4.0f;
    float4 color = new float4(red, green, blue, alpha); return(color);
}
Beispiel #2
0
float4 GetBeforeBlurPixel(uint octv, uint i)  //using current octv and current i, to find the pixel from 2 times expanded original images.
{
    GSIFT_AliS g = G;
    uint       index = i; uint2 currentSize = g.imageSize / (1 << (int)octv); uint2 currentID = i_to_id(i, currentSize);

    for (int oc = 0; oc < octv; oc++)
    {
        currentSize = currentSize * 2; index = currentID.y * currentSize.x * 2 + currentID.x * 2; currentID = i_to_id(index, currentSize);
    }
    //float4 color = c32_f4(OriginalImage[index]); return color;
    float4 color = ExpandedFirstOctaveColor(index); return(color);
}
Beispiel #3
0
// G# compute_or_material_shader >>>>>
//*********************GPU Methods*******************//
uint GetIndex(uint octv, uint layer, uint i)
{
    GSIFT_AliS g = G;
    uint       index = 0; int t = 1;

    for (int oc = 0; oc < octv; oc++)
    {
        index += (uint)(g.layers * product(g.imageSize) / t); t = (int)(pow(4, oc + 1));
    }
    index += (uint)(layer * product(g.imageSize) / t); index += i;
    return(index);
}
Beispiel #4
0
    public override void onLoaded()
    {
        base.onLoaded();
        imageSize       = new uint2(image.width, image.height);
        guassMatrixSize = new uint2((uint)(1.6 * 6), (uint)(1.6 * 6));
        octaves         = 5; layers = 8; //octaves = 0 ~ 2, layers = 0 ~ 4
        oTracking       = 0; lTracking = 0; processCtrl = 0; nImageSize = imageSize;
        uint blurredSize = 0;            //cpu variable

        for (int i = 0; i < octaves; i++)
        {
            double t = Math.Pow(4, i); blurredSize += (uint)(product(imageSize) * layers / t);
        }
        InitBuffers();
        AddComputeBufferData(ref OriginalImage, image.GetPixels32()); AddComputeBuffer(ref BlurredImages, blurredSize); AddComputeBuffer(ref FeaturePntIDs, 1); AddComputeBuffer(ref Guassian, guassMatrixSize);
        var g = G;

        //-------------------------STEP 1---------------------------------------//
        //Resize & Blurry
        g.processCtrl = 1; g.nImageSize = g.imageSize;
        for (g.oTracking = 0; g.oTracking < octaves; g.oTracking++)
        {
            for (g.lTracking = 0; g.lTracking < layers; g.lTracking++)
            {
                G = g; GenerateGuassianMatrix(g.oTracking, g.lTracking); Step1_ExtremaDetection();
            }
            g.nImageSize = g.nImageSize / 2;
        }
        //doG Calculation
        g.processCtrl = 2; g.nImageSize = g.imageSize;
        for (g.oTracking = 0; g.oTracking < octaves; g.oTracking++)
        {
            for (g.lTracking = 0; g.lTracking < layers - 1; g.lTracking++)
            {
                G = g; Step1_ExtremaDetection();
            }
            g.nImageSize = g.nImageSize / 2;
        }
        //Find Extrema
        g.processCtrl = 3; g.nImageSize = g.imageSize;
        for (g.oTracking = 0; g.oTracking < octaves; g.oTracking++)
        {
            for (g.lTracking = 1; g.lTracking < layers - 2; g.lTracking++)
            {
                G = g; Step1_ExtremaDetection();
            }
            g.nImageSize = g.nImageSize / 2;
        }
        //-----------------------------STEP1 DONE-----------------------------//
    }
Beispiel #5
0
    // G# ActionMethods >>>>>

    void InitBuffers()
    {
        var g = G;

        g.imageSize       = imageSize;
        g.guassMatrixSize = guassMatrixSize;
        g.nImageSize      = nImageSize;
        g.octaves         = octaves;
        g.layers          = layers;
        g.oTracking       = oTracking;
        g.lTracking       = lTracking;
        g.processCtrl     = processCtrl;
        G = g;
        // <<<<< G# InitBuffers
        //var g = G;
        //g.imageSize = imageSize;
        //g.guassMatrixSize = guassMatrixSize;
        //g.nImageSize = nImageSize;
        //g.octaves = octaves;
        //g.layers = layers;
        //g.oTracking = oTracking;
        //g.lTracking = lTracking;
        //g.processCtrl = processCtrl;
        //g.imageSize = imageSize;
        //g.guassMatrixSize = guassMatrixSize;
        //g.nImageSize = nImageSize;
        //g.octaves = octaves;
        //g.layers = layers;
        //g.oTracking = oTracking;
        //g.lTracking = lTracking;
        //g.processCtrl = processCtrl;
        //G = g;
        //AddComputeBuffer(ref OriginalImage, 1);
        //AddComputeBuffer(ref BlurredImages, 1);
        //AddComputeBuffer(ref Guassian, 1);
        //AddComputeBuffer(ref FeaturePntIDs, 1);
        // G# InitBuffers >>>>>
    }