nobody
nobody

Reputation: 835

Bilateral Filtering preserves the edge, but I want the opposite, an edge -bluring filter?

Is there such a filter that blurs the edge while preserves everything inside the bounding edge?

Upvotes: 0

Views: 623

Answers (1)

Balaji R
Balaji R

Reputation: 1845

I don't think there is one such filter! But if you want one you have to write one! Here is my Edge Smoothing algorithm! Hope you will find this useful!

bool SmoothEdge( Mat mInput_Bgr,Mat &mOutput_Bgr, double amount, double radius, byte Threshold) 
{
    if(mInput_Bgr.empty())
    {
        return 0;
    }

    if(radius<1)
        radius=1;

    Mat mInput,mOutput;
    Mat mChannel[3];

    split(mInput_Bgr,mChannel);

    for (int i = 0; i < 3; i++)
    {
        mInput= mChannel[i];
        SmoothEdgeSingleChannel(mInput,mOutput,amount, radius,Threshold); 
        mOutput.copyTo(mChannel[i]);
    }
    merge(mChannel,3,mOutput_Bgr);


    return true;
}

bool SmoothEdgeSingleChannel( Mat mInput,Mat &mOutput, double amount, double radius, byte Threshold) 
{
    if(mInput.empty())
    {
        return 0;
    }
    if(radius<1)
        radius=1;

    Mat mGSmooth,mDiff,mAbsDiff;
    mOutput = Mat(mInput.size(),mInput.type());

    GaussianBlur(mInput,mGSmooth,Size(0,0),radius); 

    subtract(mGSmooth,mInput,mDiff);
    mDiff*=amount;
    threshold(abs(2* mDiff),mAbsDiff,Threshold,255,THRESH_BINARY_INV);

    mDiff.setTo(Scalar(0),mAbsDiff);

    add(mInput,mDiff,mOutput);

    return true;
}

int main(int argc, char* argv[])
{
    string FileName_S="Path\\Image.jpg";
    double m_Amount=1.5;
    double m_Radius=5.5;
    int m_Threshold=0;

    Mat mSource_Bgr,mSmoothEdge;
    mSource_Bgr= imread(FileName_S,1);

    SmoothEdge(mSource_Bgr,mSmoothEdge,m_Amount,m_Radius,m_Threshold);

    imshow("Source Image",mSource_Bgr);
    imshow("Output Image",mSmoothEdge); 
}

Here is my Results: Input Image enter image description here

Output: enter image description here

Upvotes: 2

Related Questions