当前位置: 首页 > news >正文

解决cv::dilate处理后的图像边缘像素出现异常值的问题

cv::dilate处理后的图像莫名出现黑边或者白边.最后发现是borderType参数不合适导致的.
通过将第六个参数(borderType)改成cv::BORDER_ISOLATED解决问题.
如下:

int kernelSize = 3;  // 可以根据需要调整,如5,7等
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(kernelSize, kernelSize));
cv::dilate(src, dst, kernel, cv::Point(-1, -1), 1, cv::BORDER_ISOLATED);

此API的参数说明:

/** @brief Dilates an image by using a specific structuring element.The function dilates the source image using the specified structuring element that determines the
shape of a pixel neighborhood over which the maximum is taken:
\f[\texttt{dst} (x,y) =  \max _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In
case of multi-channel images, each channel is processed independently.@param src input image; the number of channels can be arbitrary, but the depth should be one of
CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
@param dst output image of the same size and type as src.
@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular
structuring element is used. Kernel can be created using #getStructuringElement
@param anchor position of the anchor within the element; default value (-1, -1) means that the
anchor is at the element center.
@param iterations number of times dilation is applied.
@param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not suported.
@param borderValue border value in case of a constant border
@sa  erode, morphologyEx, getStructuringElement*/
CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,Point anchor = Point(-1,-1), int iterations = 1,int borderType = BORDER_CONSTANT,const Scalar& borderValue = morphologyDefaultBorderValue() );
http://www.dtcms.com/a/316857.html

相关文章:

  • 结构化设计工具与技术详解
  • Spring 的优势
  • 内部排序算法总结(考研向)
  • 从递归到动态规划-解码方法Ⅱ
  • 软件测试面试如何避坑呢?
  • 8.5 各种攻击实验
  • 使用 BAML 模糊解析改进 LangChain 知识图谱提取:成功率从25%提升到99%
  • 无人机陀螺仪模块技术解析
  • SQL的LEFT JOIN优化
  • 【C语言】动态内存管理详解
  • Centos7 、9 、OpenEuler 22、24对比
  • TCP协议与UDP协议
  • 十六、请求响应-响应:三层架构-分层解耦
  • 信息安全的概述
  • RabbitMQ延时队列的两种实现方式
  • C++算法竞赛篇(九)字符数组题型讲解
  • 坚鹏:AI智能体软件是知行学成为AI智能体创新应用引领者的抓手
  • uvm-register-backdoor-access
  • SpringBoot AI心理学训练实战
  • 更改CodeBuddy的默认terminal为Git Bash
  • 随机森林算法详解:从集成学习原理到代码实现
  • Java技术栈/面试题合集(11)-设计模式篇
  • java web 未完成项目,本来想做个超市管理系统,前端技术还没学。前端是个简单的html。后端接口比较完善。
  • MySQL内外连接详解
  • 学习笔记-相似度匹配改进2
  • 机器学习——随机森林
  • Python高级编程与实践:Python高级数据结构与编程技巧
  • 【C++】Stack and Queue and Functor
  • C++二级考试核心知识点【内附操作题真题及解析】
  • Juc高级篇:可见性,有序性,cas,不可变,设计模式