Ticker

6/recent/ticker-posts

Algoritma Contrast, Brightness, dan Histogram pada MATLAB



Pengamatan menggunakan MATLAB
Gambar Sampel
Resolusi 768 X 1366 Pixel




Max     = 255
Min      = 0
Mean   = 122.6721
Standar Deviasi  = 89.4777

1.         Contrast
1.1.   Algoritma yang digunakan
clc;        % Clear command window.
clear all;     
close all; 

 % Read data
RGB = imread('matahari.jpg');
subplot(2, 2, 1);
image(RGB);
title('Gambar Asli');

 newRange = 50;  %// choose the new maximum. (new minimum always at 0.0)
imgMin = double(min(RGB(:)));
imgMax = double(max(RGB(:)));
RGB = (RGB - imgMin) / (imgMax - imgMin) * newRange;
subplot(2, 2, 2);
image(RGB);
title('Constras = 50');



newRange = 150;  %// choose the new maximum. (new minimum always at 0.0)
imgMin = double(min(RGB(:)));
imgMax = double(max(RGB(:)));
RGB = (RGB - imgMin) / (imgMax - imgMin) * newRange;
subplot(2, 2, 3);
image(RGB);
title('Constras = 150');

 newRange = 200;  %// choose the new maximum. (new minimum always at 0.0)
imgMin = double(min(RGB(:)));
imgMax = double(max(RGB(:)));
RGB = (RGB - imgMin) / (imgMax - imgMin) * newRange;
subplot(2, 2, 4);
image(RGB);
title('Constras = 200');
1.2.   Tampilan Output
Tampilan Contrast


2.         Brightness
2.1.   Algoritma yang digunakan
clc;     % Clear command window.
clear all;
close all;

% Variabel Konstan
x=1366; % Panjang Pixel
y=768; % lebar Pixel

%mengambil data gambar
gambar = imread('matahari.jpg');
subplot(2, 2, 1);
image(gambar);
title('Gambar Asli');
%untuk mengatur konsentrasi brightness
brigthVal = 50;
for i=1:y
    for j=1:x             
        %manipulasi matrix untuk memberikan brightess
        img(i,j,1) = gambar(i,j,1) + brigthVal;
        img(i,j,2) = gambar(i,j,2) + brigthVal;
        img(i,j,3) = gambar(i,j,3) + brigthVal;
    end   
end   
subplot(2, 2, 2);
%menampikan gambar hasil manipulasi
image(img);
title('Brightness = 50');

brigthVal = 150;
for i=1:
    for j=1:x             
        %manipulasi matrix untuk memberikan brightess
        img(i,j,1) = gambar(i,j,1) + brigthVal;
        img(i,j,2) = gambar(i,j,2) + brigthVal;
        img(i,j,3) = gambar(i,j,3) + brigthVal;
    end   
end   
subplot(2, 2, 3);
%menampikan gambar hasil manipulasi
image(img);
title('Brightness = 150');


brigthVal = 200;
for i=1:y
    for j=1:x             
        %manipulasi matrix untuk memberikan brightess
        img(i,j,1) = gambar(i,j,1) + brigthVal;
        img(i,j,2) = gambar(i,j,2) + brigthVal;
        img(i,j,3) = gambar(i,j,3) + brigthVal;
    end   
end   
subplot(2, 2, 4);
%menampikan gambar hasil manipulasi
image(img);
title('Brightness = 200');


2.2.   Tampilan Output.
Tampilan Brightness



3.         Histogram
3.1.   Algoritma yang digunakan
clc;        % Clear command window.
clear all;     
close all;

% Read in standard MATLAB color demo image.
rgbImage = imread('matahari.jpg');
[rows columns numberOfColorBands] = size(rgbImage);

subplot(2, 2, 1);
imshow(rgbImage, []);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
title('Gambar Asli');

% Extract the individual color planes.
redPlane = rgbImage(:, :, 1);
greenPlane = rgbImage(:, :, 2);
bluePlane = rgbImage(:, :, 3);

% Let’s get its histograms.
[pixelCountR grayLevelsR] = imhist(redPlane);
subplot(2, 2, 2);
bar(pixelCountR, 'r');
xlim([0 grayLevelsR(end)]); % Scale x axis manually.
title('Histogram of Red Plane');

[pixelCountG grayLevelsG] = imhist(greenPlane);
subplot(2, 2, 3);
bar(pixelCountG, 'g');
xlim([0 grayLevelsG(end)]); % Scale x axis manually.
title('Histogram of Green Plane');

[pixelCountB grayLevelsB] = imhist(bluePlane);
subplot(2, 2, 4);
bar(pixelCountB, 'b');
xlim([0 grayLevelsB(end)]); % Scale x axis manually.
title('Histogram of Blue Plane');


i = imread('matahari.jpg');
j = rgb1gray(i);
k = rgb2gray(i);
l = rgb3gray(i);

subplot(2,2,1),imshow(i);
subplot(2,2,2),imshow(j);
subplot(2,2,3),imhist(k);
subplot(2,2,4),imhist(l);

3.2.   Tampilan Output
Tampilan Histogram




Posting Komentar

1 Komentar

  1. sangat membantu, jika boleh tau bagaimana untuk membaca histogram dari masing masing gambar pada poin ke 2.brightness?

    BalasHapus