图像处理常用函数(Matlab)

该博客介绍了图像处理的基本步骤,包括读取和显示图像、灰度处理、直方图均衡化、滤波、图像分割、形态学操作等。涉及到的函数有`imread`、`imshow`、`rgb2gray`、`imresize`、`imfilter`、`imbinarize`、`bwlabel`、`imclearborder`等,详细阐述了各种操作的实现及应用。
摘要由CSDN通过智能技术生成

预处理

读取图像

output = imread('image.png');

显示图像

imshow(output);

查看和浏览图像

图像查看器为显示图像和执行常见的图像处理任务提供集成环境。

imtool(output);

灰度处理

output = rgb2gray(image);

插值运算

# 双线性插值
output = imresize(image,2); 

直方图

imhist(image) # 显示直方图
hist = imhist(image); # 获取直方图数据

亮度调节

调整数据以跨越数据范围

output= imadjust(input);

求极值点

# [值,坐标]=(输入,最小波峰,最小点间距离)
[maxv,maxl]=findpeaks(hist,'minpeakheight',30,'minpeakdistance',40); 

自适应直方图均衡化

output = adapthisteq(image);  

滤波

高斯滤波

# 标准差
sigma = 7;    
# 高斯滤波,模板大小,标准差 
gausm = fspecial('gaussian',[7 7],sigma);  
# replicate 表示边缘复制    
output = imfilter(image,gausm,'replicate'); 

fspecia()函数用于建立预定义的滤波算子。 'average'时为均值滤波

中值滤波

output = medfilt2(image, [7,7]);

图像分割

Otsu算法

output = imbinarize(image, 'global');

自定义阈值分割

# 二值化,val是阈值+
output = im2bw(image,val); 

形态学处理

膨胀

# 生成结构元素
s = strel('disk',para); # para指生成结构元素的大小
output = imdilate(image,s); 

腐蚀

output = imerode(image, s);

开运算

output = imopen(image,s);

闭运算

output = imclose(image, s);

顶帽运算

output = imtophat(image, s); 

低帽运算

output = imbothat(image, s); 

细化

output = bwmorph(image,'thin',para);

'thin’表示进行细化处理,'skel’表示骨骼化
para值细化的程度,取值为1,2, … , inf。 当取inf表示进行极限细化。

填充

output = imfill(image, 'holes');

连通区域

连通区域基本参数获取

output = regionprops(image,'All');

移除小面积连通区域

output = bwareaopen(image, para, 8);

para: 面积阈值下限

标记连通区域

# 连通区域标记,数量
[lable, num4] = bwlabel(image, 4);     

清理边框

image2 = imclearborder(image);

imclearborder Suppress light structures connected to image border. IM2 = imclearborder(IM) suppresses structures that are lighter than their surroundings and that are connected to the image border. IM can be an intensity or binary image. The output image, IM2, is intensity or binary, respectively. The default connectivity is 8 for two dimensions, 26 for three dimensions, and CONNDEF(NDIMS(BW),‘maximal’) for higher dimensions.For intensity images, imclearborder tends to reduce the overall intensity level in addition to suppressing border structures.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值