Isolating one Texture from LBP

I'm trying to use local binary patterns to categorize/sort images into five categories. I'd like to be able to look at what textures are common in images from each category/what the numbers with the highest frequency in the LBP histograms relate to. I'm using extractLBPFeatures to get the LBP data.
Ideally, I'm aiming for something like this image above, however the same textures/features (edge, flat, corner) don't apply well to my images.

Answers (2)

Umar
Umar on 11 Jul 2024
Hi Veronica,
Are you familiar with extractLBPFeatures function in Matlab because this will help you extract the LBP features. Once you have the LBP histograms, you can identify the patterns with the highest frequencies to understand the prevalent textures in each image category. For more information on this function, please refer to:
https://www.mathworks.com/help/vision/ref/extractlbpfeatures.html Let me further illustrate with example in order to help achieve your goal.
So, I will use extractLBPFeatures function in MATLAB to compute the LBP features for your images. This function calculates the LBP features for each pixel in the image. Here's a basic example of how you can extract LBP features from an image:
% Read an image
img = imread('sample_image.jpg');
% Convert the image to grayscale
grayImg = rgb2gray(img);
% Extract LBP features
lbpFeatures = extractLBPFeatures(grayImg);
Once I have extracted the LBP features, I can analyze the LBP histograms to understand the texture patterns present in your images. The histogram values represent the frequency of different patterns in the image which will help you visualize these histograms to gain insights into the textures.
% Compute LBP histogram
lbpHistogram = imhist(lbpFeatures);
% Visualize the LBP histogram
bar(lbpHistogram);
title('LBP Histogram');
xlabel('LBP Patterns');
ylabel('Frequency');
Now, I will categorize images into five distinct categories based on their textures, you can use clustering algorithms such as k-means clustering. By clustering images using their LBP features, you can group similar textures together.
% Perform k-means clustering
numCategories = 5;
[idx, C] = kmeans(lbpFeatures, numCategories);
% Display the clustered categories
figure;
for i = 1:numCategories subplot(2, 3, i); imshow(img(idx == i)); title(['Category ', num2str(i)]); end
After categorizing the images, I can now analyze the clustered categories to identify common textures within each category and the LBP patterns with the highest frequency in the histograms will correspond to dominant textures present in the images belonging to a specific category. If you adjust parameters such as the LBP radius and number of points, you can further refine the analysis based on your specific image dataset.

6 Comments

Hello Umar, thank you for your response! I am familiar with extractLBPFeatures, it's what I currently use in my code. What I have looks similar to yours. However, where I'm getting stuck is I want to visualize/understand what textures the lbp data represents.
For example, when I run my code, I get a 1x59 vector with decimals representing the frequency of each texture. Say entry 58 has the largest frequency for one of my images, is there some way for me to see what texture entry 58 corresponds to or to see what parts of my image have that specific texture?
Hi Veronica,
There is a way to solve this problem. So, in order to visualize the specific texture corresponding to entry 58 and identify the parts of your image with that texture, you can use the following MATLAB code snippet as an example:
% Assume 'lbpData' is your 1x59 vector representing LBP frequencies
% Assume 'image' is your input image
% Define a mapping of LBP codes to texture labels
textureLabels = {'Texture1', 'Texture2', ...}; % Define your texture labels here
% Get the index of the maximum frequency in lbpData
[~, maxIndex] = max(lbpData);
% Retrieve the corresponding texture label
maxTexture = textureLabels{maxIndex};
% Visualize the parts of the image with the specific texture
% You can use thresholding or segmentation techniques based on your specific application to highlight the regions with the identified texture
% Display results
disp(['The texture corresponding to entry 58 is: ', maxTexture]);
% Add code for visualizing specific texture in image
So, first define a mapping of LBP codes to texture labels. Then, find the index of the maximum frequency in lbpData and retrieve the corresponding texture label. Finally, add code for visualizing specific textures in the image using thresholding or segmentation techniques based on your specific application. If you have any further questions or need additional assistance, feel free to ask!
That is very helpful! Thank you, can you expand on how to then visualize the actual image (I.e. what thresholding or segmentation technique you would use)?
Hi Veronica,
No problem. You asked in the recent post, “can you expand on how to then visualize the actual image (I.e. what thresholding or segmentation technique you would use)?”
In orde to achieve this, you need to define a mapping of LBP codes to texture labels.Then, find the index of the maximum frequency in the LBP data vector.Afterwords, retrieve the corresponding texture label using the index and finally, implement a thresholding or segmentation technique to highlight regions with the identified texture in the image.
This should help you get started with your project now.
Thank you, but how do I implement a thresholding or segmentation technique to highlight regions in the image?
Hi Veronica,
If you are trying to covnvert grayscale images to binary images on a specified threshold value then I would recommend using imbinarize function.
For more information to utilize this function in your code, please refer to
https://www.mathworks.com/help/images/ref/imbinarize.html

Sign in to comment.

It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
I'm also attaching my LBP demo, for what it's worth. It's not adapted to your data.
If you have an LBP image and want to find pixels having a particular LBP value, you can create a mask of those pixels and then call regionprops to measure things about the regions.
mask = lbpImage == yourDesiredValue; % A binary image.
props = regionprops(mask, 'Area', 'Perimeter') % List whatever measurements you want.
allAreas = [props.Area];
allPerims = [props.Perimeter];

Asked:

on 11 Jul 2024

Answered:

on 20 Jul 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!