Pixel intensity vs distance (probability distribution function)
11 views (last 30 days)
Show older comments
Dear All,
I have to compute the PDF for pixel separations of similar intensity values for an image.
For intensity values I tried imhist, but the plot is number of pixels/intensity. I need a distribution function for distance/pixels with similar intensity.
How to do it?
0 Comments
Answers (1)
Sudarsanan A K
on 2 Nov 2023
Hello Andreea,
It is my understanding that you are asking how to compute the Probability Density Function (PDF) for pixel separations of similar intensity values in an image using MATLAB. Specifically, you are interested in obtaining a distribution function for the distance in pixels between pixels with similar intensity values in the image.
I assume that you can use a threshold to quantify the similarity of intensity values of pixels in the image.
Here is an example which performs this:
% Step 1: Read the image
image = imread('cameraman.jpg');
% Step 2: Convert the image to grayscale
grayImage = rgb2gray(image);
% Step 3: Calculate the intensity values
[counts, grayLevels] = imhist(grayImage);
% Step 4: Compute separations between similar intensity values
threshold = 500; % Adjust this threshold as needed
similarIntensities = find(counts > threshold);
separations = diff(similarIntensities);
% Step 5: Plot the histogram
figure;
subplot(1, 2, 1);
bar(grayLevels, counts);
xlabel('Intensity');
ylabel('Count');
title('Image Histogram');
% Step 6: Plot the PDF of separations
subplot(1, 2, 2);
histogram(separations, 'Normalization', 'pdf');
xlabel('Pixel Separation');
ylabel('PDF');
title('PDF of Pixel Separations');
% Adjust figure width
set(gcf, 'Position', [100, 100, 1200, 400]);
Note that the "threshold" is used to determine what intensity values are considered similar. By setting a threshold value, we can filter out low-frequency intensity values that may not be of interest and focus on those intensity values that are more prevalent or significant in the image.
Yo can additionally refer the following MathWorks documentations for better understanding of the "imhist()", "find()" and "diff()" functions that I have used in the example:
I hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!