* Ảnh âm bản:
I=imread('tire.tif');
imshow(I)
J=imcomplement(I);
figure, imshow(J)
* Biến đổi gamma:
I=imread('tire.tif');
J=imadjust(I,[],[],1);
J2=imadjust(I,[],[],3);
J3=imadjust(I,[],[],0.4);
imshow(J);
figure,imshow(J2);
figure,imshow(J3);
* Biến đổi logarit:
I=imread('tire.tif');
imshow(I)
I2=im2double(I);
J=1*log(1+I2);
J2=2*log(1+I2);
J3=5*log(1+I2);
figure,imshow(J)
figure,imshow(J2)
figure, imshow(J3)
* Kéo dài độ tương phản:
I=imread('tire.tif');
I2=im2double(I);
m=mean2(I2)
contrast1=1./(1+(m./(I2+eps)).^4);
contrast2=1./(1+(m./(I2+eps)).^5);
contrast3=1./(1+(m./(I2+eps)).^10);
imshow(I2)
figure,imshow(contrast1)
figure,imshow(contrast2)
figure,imshow(contrast3)
* Lọc trung bình và padding:
Với h =
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
a=imread('C:\Users\pc\Downloads\cat.jpg');
imshow(a); title('Original');
h=fspecial('average',5);
a1=imfilter(a,h);
figure; imshow(a1); title('zero-padding');
a2=imfilter(a,h,'replicate');
figure; imshow(a2); title('replicate');
a3=imfilter(a,h,'symmetric');
figure; imshow(a3); title('symmetric');
a4=imfilter(a,h,'circular');
figure; imshow(a4); title('circular');
* Lọc trung vị:
a = imread('eight.tif');
b = imnoise(a,'salt & pepper',0.02);
figure, imshow(b)
c = medfilt2(b,[3 3]);
figure, imshow(c)
* Làm sắc nét:
- Với h =
-0.1667 -0.6667 -0.1667
-0.6667 4.3333 -0.6667
-0.1667 -0.6667 -0.1667
I=imread('pout.tif');
figure; imshow(I);
h=fspecial('unsharp');
a=imfilter(I,h);
figure; imshow(a)
* Edge-detection:
(Prewit) h 1 = 1 1 1
0 0 0
-1 -1 -1
(Sobel) h2 = 1 2 1
0 0 0
-1 -2 -1
- Tìm cạnh ngang:
I=imread('circuit.tif');
figure; imshow(I);
h1=fspecial('prewit');
h2=fspecial('sobel');
a1=imfilter(I,h1);
a2=imfilter(I,h2);
figure; imshow(a1); title('Prewit');
figure; imshow(a2); title('Sobel');
- Tìm cạnh đứng:
I=imread('circuit.tif');
figure; imshow(I);
h1=fspecial('prewit');
h2=fspecial('sobel');
a1=imfilter(I,h1');
a2=imfilter(I,h2');
figure; imshow(a1); title('Prewit');
figure; imshow(a2); title('Sobel');
* Max filter:
a=imread('C:\Users\pc\Desktop\Nhóm 20_A02\pepper noise.jpg');
imshow(a)
maxf=@(x) max(x(:));
b=nlfilter(rgb2gray(a),[3 3],maxf);
figure; imshow(b)
* Min filter:
a= imread('C:\Users\pc\Desktop\Nhóm 20_A02\salt noise.jpg');
imshow(a)
minf=@(x) min(x(:));
b=nlfilter(rgb2gray(a),[3 3],minf);
figure; imshow(b)