Exemplo n.º 1
0
void ImageUtility3::Dilate(int numNeighbors, std::array<int, 3> const* delta,
    Image3<int> const& inImage, Image3<int>& outImage)
{
    int const bound0M1 = inImage.GetDimension(0) - 1;
    int const bound1M1 = inImage.GetDimension(1) - 1;
    int const bound2M1 = inImage.GetDimension(2) - 1;
    for (int i2 = 1; i2 < bound2M1; ++i2)
    {
        for (int i1 = 1; i1 < bound1M1; ++i1)
        {
            for (int i0 = 1; i0 < bound0M1; ++i0)
            {
                if (inImage(i0, i1, i2) == 0)
                {
                    for (int n = 0; n < numNeighbors; ++n)
                    {
                        int d0 = delta[n][0];
                        int d1 = delta[n][1];
                        int d2 = delta[n][2];
                        if (inImage(i0 + d0, i1 + d1, i2 + d2) == 1)
                        {
                            outImage(i0, i1, i2) = 1;
                            break;
                        }
                    }
                }
                else
                {
                    outImage(i0, i1, i2) = 1;
                }
            }
        }
    }
}
//----------------------------------------------------------------------------
void ImageUtility3::GetComponents18(Image3<int>& image,
    std::vector<std::vector<int> >& components)
{
    // Incremental 1D offsets for 18-connected neighbors.  Store +1 and -1
    // first, the xy-offsets second, to be cache friendly during the
    // depth-first search.
    int const dim0 = image.GetDimension(0);
    int const dim01 = dim0*image.GetDimension(1);
    int const delta[18] =
    {
        +1,
        -1,
        -1 - dim0,
        0 - dim0,
        +1 - dim0,
        -1 + dim0,
        0 + dim0,
        +1 + dim0,
        0 + dim01,
        +1 + dim01,
        -1 + dim01,
        0 - dim0 + dim01,
        0 + dim0 + dim01,
        0 - dim01,
        +1 - dim01,
        -1 - dim01,
        0 - dim0 - dim01,
        0 + dim0 - dim01
    };

    GetComponents(18, delta, image, components);
}
//----------------------------------------------------------------------------
void ImageUtility3::GetComponents6(Image3<int>& image,
    std::vector<std::vector<int> >& components)
{
    // Incremental 1D offsets for 6-connected neighbors.  Store +1 and -1
    // first to be cache friendly during the depth-first search.
    int const dim0 = image.GetDimension(0);
    int const dim01 = dim0*image.GetDimension(1);
    int const delta[6] =
    {
        +1,
        -1,
        -dim0,
        +dim0,
        +dim01,
        -dim01
    };

    GetComponents(6, delta, image, components);
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
void SetInitial3 (Image3<float>& initial)
{
    const int n0 = initial.GetDimension(0);
    const int n1 = initial.GetDimension(1);
    const int n2 = initial.GetDimension(2);
    for (int i2 = 0; i2 < n2; ++i2)
    {
        float x2 = -1.0f + 2.0f*i2/(float)(n2-1);
        float value2 = 1.0f - x2*x2;
        for (int i1 = 0; i1 < n1; ++i1)
        {
            float x1 = -1.0f + 2.0f*i1/(float)(n1-1);
            float value1 = 1.0f - x1*x1;
            float value12 = value1*value2;
            for (int i0 = 0; i0 < n0; ++i0)
            {
                float x0 = -1.0f + 2.0f*i0/(float)(n0-1);
                float value0 = 1.0f - x0*x0;
                initial(i0, i1, i2) = value0*value12;
            }
        }
    }
}
Exemplo n.º 5
0
void ImageUtility3::ComputeCDConvex(Image3<int>& image)
{
    int const dim0 = image.GetDimension(0);
    int const dim1 = image.GetDimension(1);
    int const dim2 = image.GetDimension(2);

    Image3<int> temp = image;
    int i0, i1, i2;
    for (i1 = 0; i1 < dim1; ++i1)
    {
        for (i0 = 0; i0 < dim0; ++i0)
        {
            int i2min;
            for (i2min = 0; i2min < dim2; ++i2min)
            {
                if ((temp(i0, i1, i2min) & 1) == 0)
                {
                    temp(i0, i1, i2min) |= 2;
                }
                else
                {
                    break;
                }
            }
            if (i2min < dim2)
            {
                int i2max;
                for (i2max = dim2 - 1; i2max >= i2min; --i2max)
                {
                    if ((temp(i0, i1, i2max) & 1) == 0)
                    {
                        temp(i0, i1, i2max) |= 2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (i2 = 0; i2 < dim2; ++i2)
    {
        for (i0 = 0; i0 < dim0; ++i0)
        {
            int i1min;
            for (i1min = 0; i1min < dim1; ++i1min)
            {
                if ((temp(i0, i1min, i2) & 1) == 0)
                {
                    temp(i0, i1min, i2) |= 2;
                }
                else
                {
                    break;
                }
            }
            if (i1min < dim1)
            {
                int i1max;
                for (i1max = dim1 - 1; i1max >= i1min; --i1max)
                {
                    if ((temp(i0, i1max, i2) & 1) == 0)
                    {
                        temp(i0, i1max, i2) |= 2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (i2 = 0; i2 < dim2; ++i2)
    {
        for (i1 = 0; i1 < dim1; ++i1)
        {
            int i0min;
            for (i0min = 0; i0min < dim0; ++i0min)
            {
                if ((temp(i0min, i1, i2) & 1) == 0)
                {
                    temp(i0min, i1, i2) |= 2;
                }
                else
                {
                    break;
                }
            }
            if (i0min < dim0)
            {
                int i0max;
                for (i0max = dim0 - 1; i0max >= i0min; --i0max)
                {
                    if ((temp(i0max, i1, i2) & 1) == 0)
                    {
                        temp(i0max, i1, i2) |= 2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (size_t i = 0; i < image.GetNumPixels(); ++i)
    {
        image[i] = (temp[i] & 2 ? 0 : 1);
    }
}