clc;
clearvars;
close all;
workspace;
format long g;
format compact;
fontSize = 20;
grayImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage);
title('Original Image', 'FontSize', fontSize);
sortedGrayLevels = double(sort(grayImage(:), 'descend'));
percentage = cumsum(sortedGrayLevels);
percentage = percentage / percentage(end);
subplot(2, 2, 2);
plot(percentage, 'b-', 'LineWidth', 2);
grid on;
title('Cumulative Distribution Function', 'FontSize', fontSize);
index75 = find(percentage >= 0.75, 1, 'first')
grayLevel75 = grayImage(index75)
binaryImage = grayImage > grayLevel75;
subplot(2, 2, 3);
imshow(binaryImage);
title('Brighter 75%', 'FontSize', fontSize);
index75 = find(percentage >= 0.25, 1, 'first')
grayLevel25 = grayImage(index75)
binaryImage25 = grayImage < grayLevel25;
subplot(2, 2, 4);
imshow(binaryImage25);
title('Darker 75%', 'FontSize', fontSize);
Best Answer