- First Convert the image to grayscale if it is not already in grayscale. This can be done using the “rgb2gray” function in MATLAB.
- Calculate the gray level profile of the image. The gray level profile represents the variation of gray levels along a certain direction in the image. You can choose a specific direction (horizontal, vertical, diagonal) based on your requirements. To calculate the gray level profile, you can use the “improfile” function in MATLAB.
How to do GLPM to and image
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi guys i have an image which is this
How to do GLPM and how to find peaks by thresholding? Ty
0 comentarios
Respuestas (2)
Gourab
el 28 de Jun. de 2023
Hi pizzaa,
From your question I get that you want toperform the Gray Level Profile Method (GLPM) and find peaks by thresholding in an image.
Follow these steps to perform GLPM and find peaks:
Refer to the below code snippet.
% Convert image to grayscale
imageArray = imread('GLPM.png');
grayImage = rgb2gray(imageArray);
% Calculate gray level profile along the horizontal direction
%Pass the direction and the number of points to the "improfile" function
profile = improfile(grayImage, [50, 500], [50, 300], 10);
smoothedProfile = smoothdata(profile);
% MinPeakHeight is the threshold value
[peaks, peakLocations] = findpeaks(smoothedProfile, 'MinPeakHeight', 5);
figure;
plot(profile);
hold on;
plot(peakLocations, peaks, 'ro', 'MarkerSize', 8);
xlabel('Position');
ylabel('Gray Level');
title('Gray Level Profile with Detected Peaks');
You can refer to the below documentation for more information.
2 comentarios
Sharad
el 28 de Jun. de 2023
Hi,
As per my understanding, you are interested in doing gray-level co-occurrence matrix (GLCM) analysis and also find out the peaks by thresholding.
Here are some steps that you can follow:
- Install the Image Processing Toolbox from the MATLAB add on explorer.
- Load the image and convert it into grayscale ( if not already).
img = imread('image.jpg');
grayImage = rgb2gray(img);
- Use the graycomatrix function provided by MATLAB to compute the GLCM of the grayscale image that you created.
glcm = graycomatrix(grayImage, 'Offset', [0 1], 'NumLevels', 256);
- Compute and understand the required gclm properties.
% Compute GLCM properties
properties = {'Contrast', 'Correlation', 'Energy', 'Homogeneity'};
glcmProps = graycoprops(glcm, properties);
% Access specific GLCM property and analyze
contrast = glcmProps.Contrast;
correlation = glcmProps.Correlation;
energy = glcmProps.Energy;
homogeneity = glcmProps.Homogeneity;
- Determine the peaks using the imregionalmax function after choosing an appropriate threshold value.
threshold = 0.5; % Adjust the threshold as needed
peaks = imregionalmax(glcm) & (glcm > threshold);
Here are some documentations that you might want to follow:
2 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!