Pixel intensity vs distance (probability distribution function)

11 ビュー (過去 30 日間)
Andreea DUMITRESCU
Andreea DUMITRESCU 2022 年 4 月 27 日
回答済み: Sudarsanan A K 2023 年 11 月 2 日
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?

回答 (1 件)

Sudarsanan A K
Sudarsanan A K 2023 年 11 月 2 日
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!

Community Treasure Hunt

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

Start Hunting!

Translated by