Rumus Revisi
Rumus Revisi
img_original = imread('path_to_your_image.jpg');
histogram = zeros(1, 256);
for i = 1:size(img_original, 1)
for j = 1:size(img_original, 2)
intensity = img_original(i, j);
histogram(intensity + 1) = histogram(intensity + 1) + 1;
end
end
figure;
bar(0:255, histogram, 'BarWidth', 1, 'FaceColor', 'k');
title('Histogram Citra Original');
xlabel('Nilai Intensitas Piksel');
ylabel('Frekuensi');
xlim([0 255]);
note:
tidak usah dipakai jika menampilkan citra original
if size(img_original, 3) == 3
img_original = rgb2gray(img_original);
end
Rumus Mirip Grayscale
img=imread('buah.jpg');
[tinggi, lebar, dimensi]=size(img);
histogram=zeros(1, 256);
if dimensi == 3
for i = 1:666
for j = 1:666
R = img(i, j, 1);
G = img(i, j, 2);
B = img(i, j, 3);
nilaiKeabuan = 0.2989 * R + 0.5870 * G + 0.1140 * B;
histogram(nilaiKeabuan + 1) = histogram(nilaiKeabuan + 1) + 1;
end
end
end
x = 0:255;
bar(x, histogram);
title('Histogram Citra Buah Warna');
xlabel('Nilai Keabuan');
ylabel('Frekuensi');
Rumus GrayScale
img=imread('buah.jpg');
gray=rgb2gray(img);
[tinggi, lebar, dimensi]=size(gray);
histogram=zeros(1, 256);
if dimensi == 1
for i = 1:666
for j = 1:666
nilaiKeabuan = gray(i, j);
histogram(nilaiKeabuan + 1) = histogram(nilaiKeabuan + 1) + 1;
end
end
end
x = 0:255;
bar(x, histogram);
title('Histogram Citra Buah GrayScale');
xlabel('Nilai Keabuan');
ylabel('Frekuensi');
Ar = img(:, :, 1);
Ag = img(:, :, 2);
Ab = img(:, :, 3);
figure(2);
subplot(1, 3, 1); image(Ar); axis off;
colorbar; colormap(gray);
title('Red Layer');
subplot(1, 3, 2); image(Ag); axis off;
colorbar;
title('green layer');
subplot(1, 3, 3); image(Ab); axis off;
colorbar;
title('blue layer');
figure(3);
title('Red Layer'); axis off; colorbar;
colormap([0, 0, 0; 0.25, 0, 0; 0.5, 0, 0; 0.75, 0, 0; 1, 0, 0]); (diproses terpisah)
figure(4); imshow(Ag);
title('Green Layer'); axis off; colorbar;
colormap([0, 0, 0; 0, 0.25, 0; 0, 0.5, 0; 0, 0.75, 0; 0, 1, 0]); (diproses terpisah)
figure(5); imshow(Ab);
title('Blue Layer'); axis off; colorbar;
colormap([0, 0, 0; 0, 0, 0.25; 0, 0, 0.5; 0, 0, 0.75; 0, 0, 1]); (diproses terpisah)
figure(6);
subplot(1, 3, 1); imhist(Ar);
title('Red Layer Buah Histogram');
subplot(1, 3, 2); imhist(Ag);
title('Green Layer Buah Histogram');
subplot(1, 3, 3); imhist(Ab);
title('Blue Layer Buah Histogram');
Rumus Citra Abu ke Warna Buatan
gray_image = imread('boat.bmp');
color = ind2rgb(gray2ind(gray_image, 256), jet(256));
hsv = rgb2hsv(color);
hsv(:, :, 2) = hsv(:, :, 2) * 2;
rgb = hsv2rgb(hsv);
imshow(rgb);
figure(1);
imhist(rgb);
s = ar + b
img = imread('buah.jpg');
dbl = im2double(img);
a = 1.2;
b = 0.2;
adj = a *dbl + b;
adj = min(max(adj, 0), 1);
adj_uint8 = im2uint8(adj);
imshow(adj_uint8);
title('Contrast and Brightened Image');