图像的邻域和块操作(matlab)

图像的邻域操作是指输出图像的像素点取值决定于输入图像的某个像素点及其领域内的像素,通常远小于图像自身尺寸、形状规则的像素块。

1.滑动邻域

B = nlfilter(A,[m,n],fun)

[m,n]:滑动区域;
fun:可取(mean、std、std、min、max、var、自定义函数)

>> A=imread('E:\persional\matlab\images\ba.tif');
>> A1 = im2double(A);
>> B1 = nlfilter(A1,[4,4],'std2');%对图像A利用滑动邻域操作函数进行处理
>> fun =@(x) max(x(:));%对图像A利用滑动邻域操作函数进行处理
>> B2 = nlfilter(A1,[3,3],fun);
>> B3 = nlfilter(A1,[6,6],fun);
>> figure,
>> subplot(131),imshow(B1);
>> subplot(132),imshow(B2);
>> subplot(133),imshow(B3);

在这里插入图片描述

2.列向量邻域:

B= colfilt(A,[m,n],block_type,fun)

[m,n]:临时组成的列矩阵;
block_type:取值:‘distinct’(分离邻域重新组合)、‘sliding’(滑动邻域重新组合)
fun:可取(mean、std、std、min、max、var、自定义函数)

>> A=imread('E:\persional\matlab\images\ba.tif');
>> A1 = im2double(A);
>> f = @(x) min(x);
>> A2 = colfilt(A1,[4,4],'sliding',f);
>> m=2;n=2;
>> f=@(x) ones(m*n,1)*min(x);
>> A3 = colfilt(A1,[m,n],'distinct',f);
>> m=4;n=4;
>> f=@(x) ones(m*n,1)*min(x);
>> A4 = colfilt(A1,[4,4],'distinct',f);
>> figure,
>> subplot(131),imshow(A2);
>> subplot(132),imshow(A3);
>> subplot(133),imshow(A4);

在这里插入图片描述

3.分离邻域操作

B = blockproc(A,[M,N],fun)
[M,N]:采用尺寸为MxN的进行分块;
fun:可取(mean、std、std、min、max、var、自定义函数)

>> A=imread('E:\persional\matlab\images\ad1.tif');
>> fun = @(block_struct) imrotate(block_struct.data,30);%获取分离块操作的函数句柄
>> A1 = blockproc(A,[27,27],fun);%进行分离快操作,每个像素点旋转30°的结果,分为27×27的像素点
>> fun=@(block_struct) std2(block_struct.data);
>> A2 = blockproc(A,[54,54],fun);%图形分成54×54的像素,再设定每一块的值
>> fun=@(block_struct) block_struct.data(:,:,[3 1 2]);%切换RGB图像的红色和绿色波段
>> blockproc(A,[108,108],fun,'Destination','E:\persional\matlab\images\ad1.tif');
>> figure,
>> subplot(221),imshow(A);
>> subplot(222),imshow(A1);
>> subplot(223),imshow(A2,[]);
>> subplot(224),imshow('E:\persional\matlab\images\ad1.tif');

在这里插入图片描述

4.block结构体中的变量名:

1.block_struct.border:是一个两元素向量[V,K]说明块数据的垂直和水平结构;
2.block_struct.blockSize:是一个两元素向量[rows cols]说明块尺寸;
3.block_struct.data:是一个MxN或者MxNxP的矩阵;
4.block_struct.imageSize:是一个两元素向量[rows cols]说明图像尺寸;
5.block_struct.location:是一个两元素向量[rows cols]说明输入图像的块数据中第一像素位置;

猜你喜欢

转载自blog.csdn.net/weixin_56260304/article/details/127260787
今日推荐