% GaborTextureSegment: Texture Segmentation using Gabor Filters
%
% seg = GaborTextureSegment(I,K,Sx,Sy,F,Theta,FUN,Wx,Wy,sigma)
%
% Input and output arguments ([]'s are optional):
% I (matrix) of size NxM: Input Image of size NxM.
% K (scalar): The # of expected segments. A param for k-means.
%
% gamma (scalar): The spatial aspect ratio, x to y. (x与y的空间比率)
% Lambda (vector): The wavelengthes of the sinusoidal functions(正弦函数的波长).
% b (scalar): The spatial frequency band-width(空间频率带宽) (in octaves)
% Theta (vector): The orientations of the gabor filters(高斯滤波的方位).
% phi (scalar): The phase offset(相位偏移量). 0 is real part (实部)of Gabor filter or
% even-symmetric(偶对称), pi/2 is imaginary part (虚部)of Gabor filter or
% odd-symmetric(奇对称).
% shape (string): shape option for conv2 to apply Gabor filter to image.
% 'same' or 'valid' or 'full'. See help conv2.
% (valid:Returns only those parts of the convolution that are computed without the zero-padded edges.
% Using this option, C has size [ma-mb+1,na-nb+1] when all(size(A) >= size(B)).
% Otherwise conv2 returns [].)
% Note: sigma (scalar): The spread of Gabor filter or the standard
% deviation of Gaussian is automatically computed from lambda and b.
% (sigma是高斯标准差,由lambda和b计算而来)
% seg (matrix) of size NxM: The segmented image. Each element has its
% partition(分割) id.
%
% Author : Naotoshi Seo, sonots@umd.edu
% Date : Oct, 2006
function seg = GaborTextureSegment(I, K, gamma, Lambda, b, Theta, phi, shape)
[nRow, nCol, C] = size(I);
% Step 1. Gabor Filter bank
i = 0;
for lambda = Lambda
for theta = Theta
i = i + 1;
D = gabor2(I, gamma, lambda, b, theta, phi, shape);
% Normalize into [0, 1]
D = D - min(reshape(D, [], 1)); D = D / max(reshape(D, [], 1));
%figure; imshow(uint8(D * 255));
% Adjust image size to the smallest size if 'valid' (Cut off)
if (isequal(shape, 'valid') && i >= 2)
[nRow, nCol, C] = size(O(:, :, i-1));
[Nr, Nc, C] = size(D);
DNr = (Nr - nRow)/2;
DNc = (Nc - nCol)/2;
D = D(1+floor(DNr):Nr-ceil(DNr), 1+floor(DNc):Nc-ceil(DNc));
end
O(:, :, i) = D;
end
end
[nRow, nCol, N] = size(O);
% Step 2. Energy (Feature Extraction)
% Step 2-1. Nonlinearity
for i=1:N
D = O(:, :, i);
alpha = 1;
D = tanh(double(O(:, :, i)) .* alpha); % Eq. (3). Input is [0, 1]
% Normalize into [0, 1] although output of tanh is originally [0, 1]
D = D - min(reshape(D, [], 1)); D = D / max(reshape(D, [], 1));
%figure; imshow(uint8(D * 255));
O(:, :, i) = D;
end
% Step 2-2. Smoothing
for i=1:N
D = O(:, :, i);
lambda = Lambda(floor((i-1)/length(Theta))+1);
% (1) constant
% sigma = 5;
% (2) Use lambda. 0.5 * lambda should be near equal to gabor's sigma
% sigma = .5 * lambda;
% (3). Use gabor's sigma
sigma = (1 / pi) * sqrt(log(2)/2) * (2^b+1) / (2^b-1) * lambda;
sigma = 3 * sigma;
D = gauss2(D, sigma, shape); % Instead of Eq, (4) Avg filter
% Normalize into [0, 1]
D = D - min(reshape(D, [], 1)); D = D / max(reshape(D, [], 1));
%figure; imshow(uint8(D * 255));
% Adjust image size to the smallest size if 'valid' (Cut off)
if (isequal(shape, 'valid') && i >= 2)
[nRow, nCol, C] = size(P(:, :, i-1));
[Nr, Nc, C] = size(D);
DNr = (Nr - nRow)/2;
DNc = (Nc - nCol)/2;
D = D(1+floor(DNr):Nr-ceil(DNr), 1+floor(DNc):Nc-ceil(DNc));
end
P(:, :, i) = D;
end
O = P; clear P;
[nRow, nCol, N] = size(O);
% Step 3. Clustering
% Step 3-1. Adding coordinates information to involves adjacency
for i=1:nRow
for j=1:nCol
O(i, j, N+1) = i / nRow; % [0, 1]
O(i, j, N+2) = j / nCol;
end
end
% Step 3-2. Clustering
data = reshape(O, [], size(O, 3)); % (# of data) x (# of dimensions)
[cluster, codebook] = kmeans_light(data, K); %stopIter的默认值为0.05
seg = reshape(cluster, nRow, nCol, 1); % 2D
end
gaborxiaobo.rar_小波图像检索
版权申诉
144 浏览量
2022-09-14
17:30:36
上传
评论
收藏 68KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/36163497263541e6b6d5b627b1692a97_weixin_42653691.jpg!1)
朱moyimi
- 粉丝: 65
- 资源: 1万+
最新资源
- MyBatisCodeHelperPro 3.3.2-2322 2023.2-2024.1
- 基于Python的简单的学生成绩管理程序设计(课程设计)
- jdk-8u20-windows-x64安装版本-jdk-8u301-linux-x64解压版
- 植物大战僵尸杂交版 修改阳光和冷却
- html css js网页设计ntion-model-for-开发笔记
- 数据库课程设计-processing开发笔记
- matlab画图sic-开发demo
- 数据库原理课程设计-图书馆数据库管理系统
- IEC101Sim IEC870-5-101协议仿真主站、子站 (含源码 C++Builder)
- 2212503007陈熙炜跨境2202作业2.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)