MATLAB | Display histogram of a grayscale Image
An image histogram is chart representation of the distribution of intensities in an Indexed image or grayscale image. It shows how many times each intensity value in image occurs.
Code #1: Display histogram of an image using MATLAB library function.
read image is an RGB image
# using imhist()
Code #2: Display Histogram of an Image without using MATLAB Library function.
- Read the source image file into image matrix
- Convert it to grayscale, if it is an RGB image
- Iterate over image matrix and count the frequency of every possible value of intensity
- plot the counted frequency
img = imread(
[x, y] = size(img);
frequency = 1 : 256;
count = 0;
i = 1 : 256
j = 1 : x
k = 1 : y
img(j, k) == i-1
count = count + 1;
frequency(i) = count;
count = 0;
n = 0 : 255;
'Number of pixels with such intensity levels -->'
'Intensity Levels -->'
'HISTOGRAM OF THE IMAGE'
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!