Created
November 19, 2022 23:40
-
-
Save ahmadyogi543/fa9ea0107bb0ad6d1118b1a33a2c34a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear; | |
clc; | |
img = imread("images/baboon.jpg"); | |
img = rgb2gray(img); | |
[img_height, img_width] = size(img); | |
d1 = [ | |
0 128; | |
192 64 | |
]; | |
d2 = [ | |
0 128 32 160; | |
192 64 224 96; | |
48 176 16 144; | |
240 112 208 80 | |
]; | |
% Membuat matriks threshold yang ukurannya sama dengan matriks citra | |
threshold_img_d1 = repmat(d1, round(img_width/2), round(img_height/2)); | |
threshold_img_d2 = repmat(d2, round(img_width/4), round(img_height/4)); | |
% Melakukan dithering citra dengan membandingkan matriks citra dgn matriks threshold | |
dith_img_d1 = img > threshold_img_d1; | |
dith_img_d2 = img > threshold_img_d2; | |
% Plotting | |
subplot(1,3,1), imshow(img); | |
title("Citra Original"); | |
subplot(1,3,2), imshow(dith_img_d1); | |
title("Hasil Dithering dengan D1"); | |
subplot(1,3,3), imshow(dith_img_d2); | |
title("Hasil Dithering dengan D2"); | |
%imwrite(img, "original.jpg"); | |
%imwrite(dith_img_d1, "dith1.jpg"); | |
%imwrite(dith_img_d2, "dith2.jpg"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment