Skip to content

Instantly share code, notes, and snippets.

@ahmadyogi543
Created November 13, 2022 00:29
Show Gist options
  • Save ahmadyogi543/af19efd8a5b6ee1fa7b9387cb6c7779d to your computer and use it in GitHub Desktop.
Save ahmadyogi543/af19efd8a5b6ee1fa7b9387cb6c7779d to your computer and use it in GitHub Desktop.
clear;
clc;
% load citra skala kelabu
img = imread("path ke gambar");
hist_img = img;
total_piksel = rows(img) * columns(img);
max_piksel = max(max(img));
fk = 0;
for i = 0:max_piksel
% dapatkan frekuensi
frekuensi_piksel = sum(img(:) == i);
% dapatkan frekuensi kumulatif
fk = fk + frekuensi_piksel;
% normalisasi
norm_piksel = fk / total_piksel;
% dapatkan nilai piksel baru
new_piksel = round(norm_piksel * max_piksel);
% ubah piksel lama dengan piksel baru
hist_img(img == i) = new_piksel;
end
% plotting
subplot(2, 2, 1);
imshow(img);
subplot(2, 2, 2);
imhist(img);
subplot(2, 2, 3);
imshow(hist_img);
subplot(2, 2, 4);
imhist(hist_img);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment