dilate函数

dilate函数

函数的调用形式:
void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, intborderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() )

函数参数的详解:

src:原图像。

dst:目标图像。

element:腐蚀操作的内核。 如果不指定,默认为一个简单的 bubuko.com,布布扣 矩阵。否则,我们就要明确指定它的形状,可以使用函数getStructuringElement().

anchor:默认为Point(-1,-1),内核中心点。省略时为默认值。

iterations:腐蚀次数。省略时为默认值1。

borderType:推断边缘类型,具体参见borderInterpolate函数。默认为BORDER_DEFAULT,省略时为默认值。

borderValue:边缘值,具体可参见createMorphoogyFilter函数。可省略。



函数的含义:
使用腐蚀操作中的核,对相应的像素进行相乘,取最大的乘积

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:

\texttt{dst} (x,y) =  \max _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')



opencv代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;




int main()
{
	Mat img = imread("d:6.jpg");
	Mat dst(img.size(),8,1);
	cvtColor(img, img, CV_BGR2GRAY);
	threshold(img, img, 100, 255, CV_THRESH_BINARY);
	dilate(img, dst, NULL, Point(-1, -1), 10, BORDER_DEFAULT, Scalar(0, 0, 255));
	namedWindow("shiyan");
	imshow("shiyan", dst);
	waitKey(0);
	return 0;
}
实验结果:

在MATLAB中,`dilate`函数用于对图像进行膨胀操作。膨胀是一种图像处理技术,用于扩大图像中的像素区域,通常用于消除小的噪声和连接的像素。 `dilate`函数的使用方法如下: ```matlab % 读取图像 img = imread('image.jpg'); % 转换为灰度图像(如果需要) img = rgb2gray(img); % 定义结构元素(可以是任何大小的矩阵) se = strel('disk', 3); % 使用半径为3的圆形结构元素进行膨胀操作 % 应用膨胀操作 dilated_img = imdilate(img, se); % 显示原始图像和膨胀后的图像 subplot(1, 2, 1); imshow(img); title('原始图像'); subplot(1, 2, 2); imshow(dilated_img); title('膨胀后的图像'); ``` 这里有几个要点需要注意: 1. `imread`函数用于读取图像文件。你可以根据需要替换为你自己的图像文件路径。 2. 如果输入图像是彩色图像,需要使用`rgb2gray`函数将其转换为灰度图像,因为膨胀操作是对灰度图像进行的。 3. `strel`函数用于创建结构元素。在这个例子中,我们使用`disk`类型,半径为3的结构元素进行膨胀操作。你可以根据需要调整结构元素的类型和大小。 4. `imdilate`函数用于应用膨胀操作。它接受输入图像和结构元素作为参数,并返回膨胀后的图像。 5. 最后,使用`subplot`和`imshow`函数来显示原始图像和膨胀后的图像。 希望这个简单的示例能帮助你理解`dilate`函数的用法。如果你有任何其他问题,请随时提问!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值