Histogram Citra


Histogram citra merupakan diagram yang menggambarkan distribusi frekuensi nilai intensitas warna dalam suatu citra.

Sumbu horizontal merupakan nilai intensitas warna sedangkan sumbu vertikal merupakan frekuensi/jumlah piksel.

Histogram dapat merepresentasikan karakteristik dari suatu citra.

Berikut ini merupakan representasi citra dan histogramnya:

1. Citra RGB
peppersRGB_Hist

2. Kanal Merah
RedRed_Hist

3. Kanal Hijau
GreenGreen_Hist

4. Kanal Biru
BlueBlue_Hist

5. Citra Grayscale
GrayGray_Hist
Source code untuk menampilkan histogram dari citra adalah sebagai berikut:

clc;clear;close all;
Img = imread('peppers.png');

R = Img(:,:,1);
G = Img(:,:,2);
B = Img(:,:,3);

Red = cat(3,R,G*0,B*0);
Green = cat(3,R*0,G,B*0);
Blue = cat(3,R*0,G*0,B);

Gray = rgb2gray(Img);

rmap = zeros(256,3);
rmap(:,1) = 0:255;
rmap = rmap/255;

gmap = zeros(256,3);
gmap(:,2) = 0:255;
gmap = gmap/255;

bmap = zeros(256,3);
bmap(:,3) = 0:255;
bmap = bmap/255;

figure,
imshow(Img);

figure,
histogram(R(:),256,'FaceColor','r','EdgeColor','r')
hold on
histogram(G(:),256,'FaceColor','g','EdgeColor','g')
histogram(B(:),256,'FaceColor','b','EdgeColor','b')
set(gca,'XLim',[0 255])
set(gca,'YLim',[0 10000])
hold off

figure,
imshow(Red), colormap(rmap), colorbar

figure,
histogram(R(:),256,'FaceColor','r','EdgeColor','r')
set(gca,'XLim',[0 255])
set(gca,'YLim',[0 10000])
grid on

figure,
imshow(Green), colormap(gmap), colorbar

figure,
histogram(G(:),256,'FaceColor','g','EdgeColor','g')
set(gca,'XLim',[0 255])
set(gca,'YLim',[0 10000])
grid on

figure,
imshow(Blue), colormap(bmap), colorbar

figure,
histogram(B(:),256,'FaceColor','b','EdgeColor','b')
set(gca,'XLim',[0 255])
set(gca,'YLim',[0 10000])
grid on

figure,
imshow(Gray), colormap(gray), colorbar

figure,
histogram(Gray(:),256,'FaceColor',[.5 .5 .5],'EdgeColor',[.5 .5 .5])
set(gca,'XLim',[0 255])
set(gca,'YLim',[0 10000])
grid on

Save

  1. mas mau tanya soal histogram, saya bikin histogram lewat LBP ( local binary pattern ),
    ada ide buat membandingkan mirip / tidak nya histogram 1 dengan data training nya?

  2. mas mau tanya, kalo code buat ngerubah warna histogram diatas yang mana ya? saya mau coba buat program matlab sama.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: