【发布时间】:2015-09-16 02:19:26
【问题描述】:
是否有这样一种过滤器可以模糊边缘同时保留边界内的所有内容?
【问题讨论】:
标签: opencv image-processing computer-vision
是否有这样一种过滤器可以模糊边缘同时保留边界内的所有内容?
【问题讨论】:
标签: opencv image-processing computer-vision
我认为没有这样的过滤器!但是如果你想要一个,你必须写一个!这是我的边缘平滑算法!希望你会发现这很有用!
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);
}
【讨论】: