[英]Gabor Filter on on each Superpixel
I am working on superpixel for the feature extraction. 我正在研究超像素的特征提取。 I have successfully applied superpixel function to the image.
我已成功将超像素功能应用于图像。
A = imread('kobi.png');
[L,N] = superpixels(A,5);
figure
BW = boundarymask(L);
figure;imshow(imoverlay(A,BW,'cyan'),'InitialMagnification',67)
Now I want to extract texture feature from each of the segment (ie Gabor features). 现在我想从每个片段(即Gabor特征)中提取纹理特征。 Anyone please help me to explain how can I apply Gabor features on each superpixel?
有人请帮我解释如何在每个超像素上应用Gabor功能?
UPDATE: 更新:
idx=label2idx(L);
meanColor = zeros(N,3);
[m,n] = size(L);
for i = 1:N
meanColor(i,1) = mean(A(idx{i}));
meanColor(i,2) = mean(A(idx{i}+m*n));
meanColor(i,3) = mean(A(idx{i}+2*m*n));
end
numColors = 6;
[pidx,cmap] = kmeans(meanColor,numColors,'replicates',2);
cmap = lab2rgb(cmap);
Lout = zeros(size(A,1),size(A,2));
for i = 1:N
Lout(idx{i}) = pidx(i);
end
imshow(label2rgb(Lout))
How can I have separate variable for each variable
如何为每个变量分别设置变量
Try This. 试试这个。 I hope This will solve your problem of extracting each pixel.
我希望这将解决你提取每个像素的问题。 I hope someone will explain about Gabor features.
我希望有人能解释一下Gabor的功能。
for i=1:size(Lout,1)
for j=1:size(Lout,2)
if (Lout (i,j) == 4)
Patch(i,j)=A(i,j);
end
end
end
mask = Patch > 0;
mask = bwareafilt(mask, 1);
% Invert mask and get bounding box.
props = regionprops(mask, 'BoundingBox');
% Crop image.
croppedImage = imcrop(Patch, props.BoundingBox);
figure;imshow(croppedImage)
Following the MATLAB tutorial about Gabor features , I can apply a Gabor filter bank to the 'kobi' image: 按照关于Gabor功能的MATLAB教程 ,我可以将Gabor滤波器组应用于'kobi'图像:
wavelengthMin = 4/sqrt(2);
wavelength = 2.^(0:4) * wavelengthMin;
deltaTheta = 45;
orientation = 0:deltaTheta:(180-deltaTheta);
g = gabor(wavelength,orientation);
A = imread('kobi.png');
Agray = rgb2gray(A);
gabormag = imgaborfilt(Agray,g);
g
contains, in this case, 20 filter kernels (see the documentation to gabor
). 在这种情况下,
g
包含20个过滤器内核(请参阅gabor
的文档 )。 imgaborfilt
applies each of those kernels (by convolution) to the image Agray
, a grey-value version of the 'kobi' image. imgaborfilt
将每个内核(通过卷积)应用于图像Agray
,即“kobi”图像的灰度值版本。 gabormag
now is a 3D image, with 20 planes, each one the magnitude of the output of one of the Gabor filters. gabormag
现在是一个3D图像,有20个平面,每个平面都是一个Gabor滤波器输出的幅度。
The Gabor filter response is sometimes taken as the features for each pixel. Gabor滤波器响应有时被视为每个像素的特征。 In the MATLAB tutorial they apply local averaging, meaning that for each pixel, the Gabor features are averages of the filter responses within a small neighborhood.
在MATLAB教程中,他们应用局部平均,这意味着对于每个像素,Gabor特征是小邻域内滤波器响应的平均值。 For use with superpixels it makes sense to average the filter responses within each superpixel.
为了与超像素一起使用,在每个超像素内平均滤波器响应是有意义的。 Let's repeat your code to get superpixels first:
让我们重复你的代码来获得超像素:
[L,N] = superpixels(A,500);
L
is a labeled image: each pixel has the value corresponding to the ID of a superpixel. L
是标记图像:每个像素具有与超像素的ID对应的值。 These labels start at 1 and are consecutive. 这些标签从1开始并且是连续的。
Using regionprops
we can compute the mean intensity within each labeled region: 使用
regionprops
我们可以计算每个标记区域内的平均强度:
K = size(gabormag,3);
gaborfeatures = zeros(N,K);
for ii=1:K
res = regionprops(L,gabormag(:,:,ii),'MeanIntensity');
gaborfeatures(:,ii) = [res.MeanIntensity]';
end
(You can also use label2idx
and iterate over its output arrays like you did in the edit to your question.) (您也可以使用
label2idx
并迭代其输出数组,就像您在编辑问题时所做的那样。)
gaborfeatures
now contains one row for each superpixel, and one column for each Gabor feature. gaborfeatures
现在每个超gaborfeatures
包含一行,每个Gabor功能包含一列。 For example, gaborfeatures(294,:)
are the Gabor features for the superpixel L==294
, which is on the dog's nose: 例如,
gaborfeatures(294,:)
是超像素L==294
的Gabor特征,它位于狗的鼻子上:
>> gaborfeatures(294,:)
ans =
1.0e+04 *
Columns 1 through 9
0.0008 0.0040 0.0171 0.0848 1.0617 0.0009 0.0040 0.0193 0.1304
Columns 10 through 18
0.7753 0.0008 0.0040 0.0165 0.0872 1.0672 0.0010 0.0046 0.0208
Columns 19 through 20
0.0842 0.6736
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.