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 (i.e. Gabor features). Anyone please help me to explain how can I apply Gabor features on each superpixel?
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
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.
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:
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). imgaborfilt applies each of those kernels (by convolution) to the image Agray, a grey-value version of the 'kobi' image. gabormag now is a 3D image, with 20 planes, each one the magnitude of the output of one of the Gabor filters.
The Gabor filter response is sometimes taken as the features for each pixel. 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. 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. These labels start at 1 and are consecutive.
Using regionprops we can compute the mean intensity within each labeled region:
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.)
gaborfeatures now contains one row for each superpixel, and one column for each Gabor feature. For example, gaborfeatures(294,:) are the Gabor features for the superpixel L==294, which is on the dog's nose:
>> 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With