示例#1
0
float4 ExpandedFirstOctaveColor(uint i)  //Calculate octv 0, layer 0's ith pixel's color - (expand original image & smooth it first).
{
    GSift 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.x + c2.x + c3.x + c4.x) / 4.0f, green = (c1.y + c2.y + c3.y + c4.y) / 4.0f, blue = (c1.z + c2.z + c3.z + c4.z) / 4.0f, alpha = (c1.w + c2.w + c3.w + c4.w) / 4.0f;
    //float4 color = new float4(red, green, blue, alpha);
    float4 color = (c1 + c2 + c3 + c4) / 4;

    return(color);
}
示例#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 g = G;
    uint  index = i; uint2 currentSize = g.imageSize / (uint)(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);
}
示例#3
0
// G# compute_or_material_shader >>>>>
//*********************GPU Methods*******************//
uint GetIndex(uint octv, uint layer, uint i)
{
    GSift 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);
}
示例#4
0
    public override void onLoaded()
    {
        base.onLoaded();
        imageSize       = new uint2((uint)image.width, (uint)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-----------------------------//
    }
示例#5
0
    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 >>>>>
    }