Exemplo n.º 1
0
static G12Buffer *CannyDetector::doFilter(G12Buffer *input, const CannyParameters &mCannyParameters)
{
    if (input == NULL) {
        return NULL;
    }

    // non-maximum suppression
    DerivativeBuffer derBuf(input);
    G12Buffer *suppressedBuffer = derBuf.nonMaximalSuppression();

    // double thresholding
    for (int i = 0; i < suppressedBuffer->h; i++)
    {
        for (int j = 0; j < suppressedBuffer->w; j++ )
        {
             uint16_t pixel = suppressedBuffer->element(i,j);
             if (pixel < mCannyParameters.minimumThreshold())
             {
                 suppressedBuffer->element(i,j) = 0;
                 continue;
             }
             if (pixel > mCannyParameters.maximumThreshold())
             {
                 suppressedBuffer->element(i,j) = CannyFilter::white;
                 continue;
             }
             suppressedBuffer->element(i,j) = CannyFilter::gray;
        }
    }

    // edge tracking
    if (mCannyParameters.shouldEdgeDetect())
    {
        for (int i = 0; i < suppressedBuffer->h; i++)
        {
            for (int j = 0; j < suppressedBuffer->w; j++ )
            {
                if (suppressedBuffer->element(i,j) == CannyFilter::white)
                    CannyFilter::recursiveEdgeProver(suppressedBuffer, i, j);
            }
        }
        for (int i = 0; i < suppressedBuffer->h; i++)
            for (int j = 0; j < suppressedBuffer->w; j++ )
                if (suppressedBuffer->element(i,j) == CannyFilter::gray) suppressedBuffer->element(i,j) = 0;
    }

    return suppressedBuffer;
}
Exemplo n.º 2
0
G12Buffer *RGB24Buffer::toG12Buffer()
{
    G12Buffer *toReturn = new G12Buffer(h,w, false);
    for (int i = 0; i < h; i++)
    {
        RGBColor *in  = &this->element(i,0);
        uint16_t *out = &toReturn->element(i,0);
        int j = 0;
#ifdef WITH_SSE_
        const int inspan  = SSEReader8BBBB_DDDD::BYTE_STEP / sizeof(RGBColor);
        const int outspan = 8;

        Int16x8 conR(11);
        Int16x8 conG(16);
        Int16x8 conB( 5);

        for (; j + inspan <= w; j += inspan)
        {
            FixedVector<Int16x8,4> r = SSEReader8BBBB_DDDD::read((uint32_t*)in);
            enum {B1, G1, R1};

            Int16x8 result = (conR * r[R1] + conG * r[G1] + conB * r[B1]) >> 1;
            result.save(out);
            in  += inspan;
            out += outspan;
        }

#endif
        for (; j < w; j++)
        {
            uint16_t result = element(i,j).luma12();
            if (result > G12Buffer::BUFFER_MAX_VALUE - 1) result = G12Buffer::BUFFER_MAX_VALUE - 1;
            toReturn->element(i, j) = result;
        }
    }
    return toReturn;
}
Exemplo n.º 3
0
void testBilinerTransform (void)
{
    Matrix33 inverseLeftMatrix(
    1, 0, -13,
    0, 1, -9.5,
    0, 0, 1);

    ProjectiveTransform inverseLeft(inverseLeftMatrix);

    G12Buffer *image = BufferFactory::getInstance()->loadG12Bitmap("data/pair/image0001_c0.pgm");
    ASSERT_TRUE(image, "Could not open test image\n");
    ASSERT_TRUE(image->verify(),"Input image is corrupted");
    G12Buffer *buffer1Transformed = image->doReverseTransform<ProjectiveTransform>(&inverseLeft, image->h, image->w);
    ASSERT_TRUE(buffer1Transformed->verify(),"Result image is corrupted");

    BMPLoader *loader = new BMPLoader();
    RGB24Buffer *toSave = new RGB24Buffer(buffer1Transformed);
    loader->save("proc.bmp", toSave);

    delete toSave;
    delete loader;
    delete buffer1Transformed;
    delete image;
}