02.11.2023 derste yazılan bazı kodlar
Tekrar tekrar jpg sıkıştırma
clear,clc; J = imread('lenacolor.jpg'); imwrite(J, '1.jpg'); I = J; figure; subplot(1,2,1);imshow(J); for i=1:100 I=imread('1.jpg'); imwrite(I, '1.jpg', 'Quality',10); end subplot(1,2,2);imshow(I);
Gradyan oluşturma
I = zeros(256,256); I = uint8(I); for i=0:255 I(:,i+1) = i; end I = imresize(I, 2); imshow(I); J= imread('lenaGS.jpg'); imshow(J+I);
Yeniden boyutlandırma
I = imread('lenags.jpg'); subplot(1,2,1);imshow(I); I = imresize(I, 1/16); I = imresize(I, 16); subplot(1,2,2);imshow(I); sum(sum(I == J))
Parça kesme
I = imread('cameraman.jpg'); Parca = I(100:299, 200:499); Parca = imresize(Parca, [512 512]); imwrite(Parca, 'ders.jpg'); subplot(1,2,1);imshow(I);title('orj'); subplot(1,2,2);imshow(Parca);title('kesilen parça');
16.11.2023 derste yazılan bazı kodlar
Ortalama filtresi
I = imread('lenags.jpg'); K = I; filtre = [-0.5 0.2 0.3; 0.1 0.6 0.09; 1 -0.4 0.3] for i=2:511 for j = 2:511 K(i,j) = uint8(sum(sum(double(I(i-1:i+1, j-1:j+1)).*filtre))); end end subplot(1,2,1);imshow(I); subplot(1,2,2);imshow(K);
Laplacian HPF
I = imread('cameraman.jpg'); filtrem = fspecial('laplacian'); I = (uint8(filter2(filtrem,I))); imshow(I);
Gauss Filtresi
50×50 boyutunda, standart sapması 3 olan Gauss filtresi
clc,clear I = imread('cameraman.jpg'); a = 50;s = 3; filtre = fspecial('gaussian', [a a],s); subplot(1,2,1),surf(1:a,1:a,filtre); subplot(1,2,2), imshow(uint8(filter2(filtre,I)));
Salt&Pepper gürültüsü ve Average filtresi
I = imread('lenags.jpg'); subplot(1,3,1);imshow(I); I = imnoise(I,'salt & pepper'); subplot(1,3,2);imshow(I); filtrem = fspecial('average'); I = uint8(filter2(filtrem,I)); subplot(1,3,3);imshow(I);
Prewitt maskesi ile kenar tespiti
Px = [-1 0 1;-1 0 1;-1 0 1 ]; I = uint8(filter2(Px,I)); subplot(1,2,1);imshow(I); Py = [-1 -1 -1;0 0 0;1 1 1 ]; I = uint8(filter2(Py,I)); subplot(1,2,2);imshow(I);
zeros fonksiyonu ile RGB görüntü oluşturma
I = zeros(512,512,3); I = uint8(I); I(40:80,40:80,1) = 255; I(100:150,80:120,2) = 255; I(200:250,200:300,3) = 255; imshow(I);
3 matrisi birleştirerek görüntü oluşturma
R = uint8(zeros(512)); G = uint8(zeros(512)); B = uint8(zeros(512)); B = B+200; resim = cat(3,R,G,B); imshow(resim);
RGB-HSV arası dönüşüm
I = imread('baboon.png'); subplot(1,3,1);imshow(I); K = rgb2hsv(I); subplot(1,3,2);imshow(K); L = hsv2rgb(K); subplot(1,3,3);imshow(L);
HSV uzayındaki görüntüde mavi renkli alanı seçme
I = imread('baboon.png'); subplot(1,2,1);imshow(I); I = rgb2hsv(I); K = (I(:,:,1)>0.5) & (I(:,:,1)<0.83); subplot(1,2,2);imshow(K);