perform the following operations on the images you have taken. a. apply histogram equalization to the image. do not use matlab functions (histeq) for histogram equalization. write your own code in matlab

To perform histogram equalization on an image without using the histeq function in MATLAB, you can write your own code using the following steps:

  1. Read the image using the imread function.
  2. Convert the image to grayscale if it is not already.
  3. Calculate the histogram of the input image by counting the occurrences of each pixel intensity value.
  4. Calculate the cumulative distribution function (CDF) of the histogram.
  5. Normalize the CDF to the range of pixel intensity values.
  6. Map the pixels of the input image to new intensity values based on the normalized CDF.
  7. Create the histogram-equalized image by replacing the original pixel intensities with the mapped intensity values.
  8. Display the original and histogram-equalized images using the imshow function.

Here is an example code snippet in MATLAB:

main.m
% Read the input image
inputImage = imread('your_image.jpg');

% Convert the image to grayscale
grayImage = rgb2gray(inputImage);

% Calculate the histogram of the input image
pixelCounts = zeros(256, 1);
for i = 1:size(grayImage, 1)
    for j = 1:size(grayImage, 2)
        pixelIntensity = grayImage(i, j);
        pixelCounts(pixelIntensity + 1) = pixelCounts(pixelIntensity + 1) + 1;
    end
end

% Calculate the cumulative distribution function (CDF)
histogramCumulative = cumsum(pixelCounts);

% Normalize the CDF
cdfNormalized = histogramCumulative / sum(pixelCounts);

% Map the pixels of the input image to new intensity values based on the normalized CDF
mappedImage = zeros(size(grayImage));
for i = 1:size(mappedImage, 1)
    for j = 1:size(mappedImage, 2)
        pixelIntensity = grayImage(i, j);
        mappedIntensity = round(cdfNormalized(pixelIntensity + 1) * 255);
        mappedImage(i, j) = mappedIntensity;
    end
end

% Display the original and histogram-equalized images
figure;
subplot(1, 2, 1), imshow(grayImage), title('Original Image');
subplot(1, 2, 2), imshow(uint8(mappedImage)), title('Histogram Equalized Image');
1149 chars
36 lines

Make sure to replace 'your_image.jpg' with the path to your actual image file.

Please note that this code assumes grayscale input images. If you have a color image, you can take the average pixel intensities across the color channels to convert it to grayscale.

gistlibby LogSnag