0% found this document useful (0 votes)
31 views3 pages

1main Filtering

1. The document discusses various image processing techniques including filtering, convolution, translations, reflections, and rotations. 2. Filtering operations are performed using low-pass and high-pass kernels to smooth or sharpen images. Convolution is used to apply the kernels. 3. Translation is done by shifting each pixel by a specified number of rows and columns. Reflection is done by flipping the image across the x or y-axis. 4. Rotation is performed by calculating new row and column values for each pixel based on a rotation angle and the cosine and sine of that angle.

Uploaded by

Irvan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

1main Filtering

1. The document discusses various image processing techniques including filtering, convolution, translations, reflections, and rotations. 2. Filtering operations are performed using low-pass and high-pass kernels to smooth or sharpen images. Convolution is used to apply the kernels. 3. Translation is done by shifting each pixel by a specified number of rows and columns. Reflection is done by flipping the image across the x or y-axis. 4. Rotation is performed by calculating new row and column values for each pixel based on a rotation angle and the cosine and sine of that angle.

Uploaded by

Irvan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1MAIN FILTERING 1KONVOLUSI

%pembahasan filtering function val = konvolusi( img,kernel)


img = imread('cameraman.tif'); [row, col] = size(kernel);
mul = img.*kernel;
%kernel low-pass(low-pass filter) val = sum(reshape(mul,[row*col 1]));
kernel1 = 1/9*[1 1 1;1 1 1;1 1 1]; end

%kernel high-pass(high-pass filter) 2BASIC


kernel2 = 1/9*[0 -1 0;-1 4 -1;0 -1 0]; clc;clear;
%Baca Citra & simpan citra pada variabel
%filtering citra1 = imread ('autumn.tif');
result = Filtering(img,kernel1); citra2 = imread ('moon.tif');
result = Filtering(result,kernel2); %menampilkan citra
%Operasi Aritmatika untuk mencerahkan subplot (2,2,1);
result = 40*result; imshow (citra1);
result = Filtering(result,kernel1); subplot (2,2,2);
%tampil imshow (citra2);
subplot (1,2,1); %menampilkan ukuran citra
imshow(img); fprintf('Baris citra1: %d \n',
title('Origin'); size(citra1,1));
subplot(1,2,2); fprintf('Baris citra2: %d \n',
imshow(result); size(citra1,2));
title('Hasil'); %menampilkan info citra
imfinfo moon.tif
1MEAN FILTERING %membuat citra
function result = meanFiltering(img) citra_buatan = rand(300, 300);
[row,col] = size(img); subplot(2,2,3);
imshow(citra_buatan);
%membuat citra warna (RGB)
%kernel Rata-Rata(low pass filter) citra_warna_buatan = rand(300, 300, 3);
% kernel = [ 1/9 1/9 1/9; subplot(2,2,4);
% 1/9 1/9 1/9; imshow(citra_warna_buatan);
% 1/9 1/9 1/9]; %menyimpan citra
imwrite(citra_buatan, 'citra buatan.jpg');
%kernel High pass filter
kernel = [ 0 1/8 0;
1/8 1/8 1/8; 2OPERASI_CITRA
0 1/8 0]; clc; clear;
%geometri
%inisialisasi citra = imread('cameraman.tif');
result = zeros(row,col); %Translasi
for ii = 2:row-1; baris = size(citra, 1);
for jj = 2:col-1; kolom = size(citra, 2);
%Konvolusi %inisialisasi citra baru
val = konvolusi(double(img(ii- citra_translasi = zeros(baris, kolom);
1:ii+1,jj-1:jj+1)),kernel); citra_translasi = uint8(citra_translasi);
result(ii, jj)=val; %translasi
end x = 10; y = 25;
end for ii = 1:baris-y
result = uint8(result); for jj = 1:kolom-x
end citra_translasi(ii+y, jj+x) = ...
citra(ii, jj);
end
1FILTERING end
function result = Filtering(img,kernel) subplot (1,2,1);
[row,col] = size(img); imshow(citra_translasi);
%rotasi
%inisialisasi %inisialisasi citra rotasi
result = zeros(row,col); citra_rotasi = zeros (baris, kolom);
for ii = 2:row-1; citra_rotasi = uint16(citra_rotasi);
for jj = 2:col-1; derajat = 10;
%Konvolusi theta = derajat*pi/180;
val = konvolusi(double(img(ii- for ii = 1:baris
1:ii+1,jj-1:jj+1)),kernel); for jj = 1:kolom
result(ii, jj)=val; kolom_baru = cos(theta)*(jj)...
end -sin(theta)*(baris-ii+1);
end kolom_baru = uint16(kolom_baru);
result = uint8(result); baris_baru = sin(theta)*(jj)...
end +cos(theta)*(baris - ii + 1);
baris_baru = uint8(baris_baru);
if (baris_baru > 0 && baris_baru <= function [ r ] = ref_img(img, dir)
baris) %dir = direction
if(kolom_baru > 0 && kolom_baru %merupakan arah refleksi
<= kolom) %dir = 0 sumbu-x(vertical)
citra_rotasi(baris - %dir = 1 sumbu-y(horizontal)
baris_baru, kolom_baru) = ...
citra(ii, jj); %refleksi(flipping)
end %sumbu-x;
end %x' = x
end %y' = #row-y
end
subplot(1,2,2); %ambil ukuran citra
imshow(citra_rotasi); [row,col,dim]=size(img);

LATIHAN %inisialisasi r (citra hasil)


A = zeros(5,8,3); r = uint8(zeros(row,col,dim));
%A = uint8 (A);
%A = uint16(A);
for x= 1:col
%A = uint32(A);
for y=1:row
%Warna merah (Red)
if dir == 0
A(:, :, 1) = [0.4 0.3 0.5 0.44 0.8 0.651
new_row = row-y+1;
0.456345 0.34623;
new_col = x;
0 0 0 0.8 0.8 0 0 0;
else
0 0 0 0.6 0.6 0 0 0;
%(...?)
0 0 0 0.7 0.7 0 0 0;
end
0.9 0.8 0.7 0.6 0.5 0.6 0.7
r(new_row,new_col) = img(y,x);
0.8];
end
%Warna Hijau (Green)
end
A(:, :, 2) = [0.7 0.7 0.7 0.7 0.4 0.6 0.5
0.3;
0 0 0 0.6 0.6 0 0 0; 3ROT_IMG
0 0 0 0.4 0.7 0 0 0; function [r] = rot_img(img,theta)
0 0 0 0.8 0.5 0 0 0; %theta(dalam radian)
0.9 0.6 0.5 0.3 0 0 0 0]; theta = theta*pi/180;
%Warna Biru (Blue)
A(:, :, 3) = [0.9 0.9 0.9 0.9 0.9 0.9 0.9 %matriks rotasi
0.3; %[cos(theta) -sin(theta)
0 0 0 1 0 0 0 0; % sin(theta) cos(theta);
0 0 1 1 1 0 0 0; % atau
0 1 1 1 1 1 0 0; % x' = xcos(theta)-ysin(theta)
1 0 0 0 0 0 0 0]; % y' = xsin(theta)+ycos(theta)
imshow(A);
3MAIN %ambil ukuran citra
% Operasi Geometri [row,col,dim] = size(img);
%baca citra
img = imread('cameraman.tif'); %inisialisasi r
% Translasi r = uint8(zeros(row,col,dim));
%r_img merupakan citra hasl operasi
r_img = trans_img(img,10,100); for x=1:col
% Refleksi(flipping) for y=1:row
r_img_ref = ref_img(img,0); new_col =round(x*cos(theta)-
% Rotasi y*sin(theta));
r_rotasi = rot_img(img,30); new_row
%tampil citra =round(x*sin(theta)+y*cos(theta));
subplot(1,4,1);
imshow(img);
if(new_col>0 && new_col<=col)
title('Citra');
if(new_row>0 && new_row<=row)
subplot(1,4,2);
r(new_row,new_col) =
imshow(r_img);
img(y,x);
title('Translasi');
end
subplot(1,4,3);
end
imshow(r_img_ref);
end
title('Refleksi');
end
subplot(1,4,4);
end
imshow(r_rotasi);
title('Rotasi');
3TRANS_IMG
function t = trans_img(img,tx,ty)
%x' = x+tx <- new colomn
3REF_IMG %y' = y+ty <- new colomn
end
%ambil atribut ukuran citra end
[row,col,dim] = size(img); 4TRANSFORMASI_MAIN
img = imread('cameraman.tif');
%inisialisasi t %Citra Negatif
t = uint8((zeros(row, col, dim))); [row, col] = size(img);
vector_img = reshape(img, [row*col, 1]);
for x=1:col maximum = max(vector_img);
for y=1:row neg_img = maximum - img;
new_col = x+tx;new_row = y+ty; figure;
t(new_row,new_col)= img(y,x); subplot(1,2,1);
end imshow(img);
end title('Original');
% t merupakan citra hasil operasi translasi subplot(1,2,2);
imshow(neg_img);
title('Negative');
4DETEKSI_TEPI_MAIN %Transformasi Log
img = imread('cameraman.tif'); %Log basi 10
c = 100; r = 10;
[Gmagnitude, Gdirection] = log_img = c*log10(double(img) + r);
imgradient(medianFilter(img,3)); log_img = uint8(log_img);
Gmagnitude = uint8(Gmagnitude); figure;
subplot(1,2,1);
subplot(1,2,1); imshow(img);
imshow(img); title('Original');
subplot(1,2,2); subplot(1,2,2);
imshow(Gmagnitude); imshow(log_img); %Default dalam uint8 [0
255]
%imshow(log_img, [0 255]);
4FILTERING_MAIN title('Log');
clear;clc; %Transformasi Gamma Correction
img = imread('cameraman.tif'); % 0<gamma<1
%smoothing gamma = 0.9;
%pada kasus noise removeal gamma_img = double(img).^(1/gamma);
noise_img = imnoise(img, 'salt & pepper', gamma_img = uint8(gamma_img);
0.25); figure;
%noise_img = imnoise(img, 'poisson'); subplot(1,2,1);
window_size = 7; %kernel 3x3 imshow(img);
clear_img = medianFilter(noise_img, title('Original');
window_size); subplot(1,2,2);
clear_img = uint8(clear_img); imshow(gamma_img, [0 511]);
figure; title('Gamma');
subplot(1,3,1);
imshow(img);
title('Original');
subplot(1,3,2);
imshow(noise_img);
title('Noisy Image');
subplot(1,3,3);
imshow(clear_img);
title('Median');

4MEDIAN FILTER
function f = medianFilter(img, s);
%s = size window
%kernel sxs
%inisialisasi matrik hasil
[row, col] = size(img);
f = zeros(row, col);
diff = floor(s/2);
for ii = 1 : row - s-1
for jj = 1: col - s-1
window = img(ii:ii + s-1 , jj:jj +
s-1);
vector_window = reshape(window,
[s^2,1]);
f(ii + diff, jj + diff) =
median(vector_window);
end

You might also like