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);
Renkli görüntünün tüm katmanlarında histogram eşitleme
I = imread('lenacolor.jpg'); subplot(1,3,1);imshow(I); subplot(1,3,2);imshow(histeq(I)); R = I(:,:,1); R = histeq(R); G = I(:,:,2); G = histeq(G); B = I(:,:,3); B = histeq(B); subplot(1,3,3);imshow(cat(3,R,G,B));
Renkli görüntünün tüm katmanlarında gürültüden kurtulmak için medyan filtresi
clear;clc; I = imread('lenacolor.jpg'); I = imnoise(I, 'salt & pepper'); subplot(1,2,1);imshow(I); R = I(:,:,1); R = medfilt2(R); G = I(:,:,2); G = medfilt2(G); B = I(:,:,3); B = medfilt2(B); subplot(1,2,2);imshow(cat(3,R,G,B));
Renkli görüntüde katman katman kenar tespiti
clear;clc; I = imread('lenacolor.jpg'); subplot(1,2,1);imshow(edge(im2gray(I),'sobel')); R = I(:,:,1); Rr = edge(R,'sobel'); G = I(:,:,2); Rg = edge(G,'sobel'); B = I(:,:,3); Rb = edge(B,'sobel'); sonuc = (Rr|Rg|Rb) subplot(1,2,2);imshow(sonuc);
Görüntüde erozyon ve genişleme
I = imread('lenacolor.jpg'); se = strel('disk',5); Ier = imerode(I,se); Idi = imdilate(Ier,se); subplot(1,2,1);imshow(I); subplot(1,2,2);imshow(Idi);
Görüntüde morfolojik açılma sonrası renk bölgesi seçimi
I = imread('baboon.png'); subplot(121);imshow(I); se = strel('disk',25); Idi = imopen(I,se); Ihsv = rgb2hsv(Idi); K = (Ihsv(:,:,1)>0.5) & (Ihsv(:,:,1)<0.83); subplot(122);imshow(im2double(I).*K);
Görüntü segmentasyonu
I = imread('coins.jpeg'); Ibw = im2bw(I); subplot(221);imshow(Ibw); mk = 255-uint8(bwdist(~Ibw)); subplot(222);imshow(mk); g = watershed(mk); % Su havzası algoritması abs = g == 0; subplot(223); imshow(labeloverlay(double(Ibw),double(abs),'Colormap',[1 1 0], 'Transparency',0)); title('Segmentlere ayrıldı'); subplot(224); imshow(label2rgb(g)); title('Renklendirilmiş');
Plaka okuma
I = imread('carplate1.jpeg'); %K = I(100:300, 500:1100); K = I; se = strel('Ball',3,1); K = imopen(K,se); imshow(K) metin = ocr(K);
Yüz tespiti
clear; clc; I = imread('lenacolor.jpg'); Yuz = vision.CascadeObjectDetector(); % Yüz tanımlayıcı yapı oluştur YuzunKonumu = step(Yuz,I); % Yüzün konumunu ver BulunanYuz = insertShape(I, 'Rectangle', YuzunKonumu); imshow(BulunanYuz);