You are on page 1of 8

BI TP X L NH CHNG 3

3.1Gin tng phn


f = imread(funny.jpg)
gray = rgb2gray(f)
g = imadjust(gray, [0.1 0.3], [0.2 0.4])
figure(1), imshow(gray)
figure(2), imshow(g)

3.2 Bin i mt vng mc xm


x = imread('tire.tif');
x = imresize(x, [256 256]);
y = double(x);
[m,n] = size(y);
L = double(255);
a = double(round(L/1.25));
b = double(round(2*L/2));
for i=1:m
for j=1:n
if(y(i,j)>=a & y(i,j)<=b)
z(i,j)=L;
else
z(i,j)=0;
end
end
end

imshow(uint8(y));
figure,imshow(uint8(z));

3.3 Tnh ton lc xm chun ha


f = imread('funny.jpg');
gray = rgb2gray(f);
[a,b] = hist(f(:),0:1:255);
figure(1), plot(b,a)

3.4 Cn Bng v Khp lc mc xm


image = imread('tire.tif');
% xac dinh luoc do muc xam
hist = imhist(image);
% can bang luoc do muc xam
cdf = cumsum(hist1) / numel(image);
output = cdf(double(image) + 1);
figure(1) ,imshow(image), title('Image');
figure(2) ,imshow(output), title('Ouput');
figure(3) ,imhist(image), title('Histogram Image');
figure(4) ,imhist(output), title('Histogram Output');

3.5 Lc khng gian u vo


input=imread('funny.jpg')
f=rgb2gray(input)
figure,imshow(f);
title('Original Image');
corr=[0 0.5 0.5;-1 0.5 0.2; 0.4 0.2 0;];
pad1=size(corr,1)-1;
pad2=size(corr,2)-1;
output=uint8(zeros(size(f)));
if(size(corr,1)==1)
B=zeros(size(f,1),size(f,2)+pad2);
m=0;
n=floor(size(corr,2)/2);
sz1=size(B,1);
sz2=size(B,2)-pad2;
elseif(size(corr,2)==1)
B=zeros(size(f,1)+pad1,size(f,2));
m=floor(size(corr,1)/2);
n=0;
sz1=size(B,1)-pad1;
sz2=size(B,2);
else
B=zeros(size(f,1)+pad1,size(f,2)+pad2);
m=floor(size(corr,1)/2);
n=floor(size(corr,2)/2);
sz1=size(B,1)-pad1;
sz2=size(B,2)-pad2;
end
for i=1:size(f,1)
for j=1:size(f,2)
B(i+m,j+n)=f(i,j);
end
end
szcorr1=size(corr,1);
szcorr2=size(corr,2);

for i=1:sz1
for j=1:sz2
sum=0;
m=i;
n=j;
for x=1:szcorr1
for y=1:szcorr2
sum=sum+(B(m,n)*corr(x,y));
n =n+1;
end
n=j;
m=m+1;
end
output(i,j)= sum;
end
end
figure,imshow(output);
title('After linear filtering');

3.6 Vit hm matlab thc hin lc trung v,lc cc i,lc cc tiu

3.6.1. Lc Trung V
input=imread('funny.jpg')
f = rgb2gray(input)
output = uint8(zeros(size(f)));
% bo loc mxn
m = 15;
n = 15;
extendImage = zeros(size(f, 1) + m - 1, size(f, 2)+ n - 1);
for x=1:size(f,1)
for y=1:size(f,2)
extendImage(x + floor(m / 2),y + floor(n / 2)) = f(x, y);
end
end
%lc trung v mxn
for i = 1:size(f, 1)
for j = 1:size(f, 2)
%tao 1 mang m * n phan tu tuong ung ma tran mxn
window = zeros(1, (m * n));
index = 1;
for x = 1:m
for y = 1:n
window(index) = extendImage(i + x - 1, j + y - 1);
index = index + 1;
end
end
windownSorted = sort(window);

output(i, j) = windownSorted(round((m * n) / 2));


end
end
figure(1),imshow(f)
figure(2),imshow(output)

3.6.2 Lc cc i
input=imread('funny.jpg')
f = rgb2gray(input)
output = uint8(zeros(size(f)));
% bo loc mxn
m = 3;
n = 3;
extendImage = zeros(size(f, 1) + m - 1, size(f, 2)+ n - 1);
for x=1:size(f,1)
for y=1:size(f,2)
extendImage(x + floor(m / 2),y + floor(n / 2)) = f(x, y);
end
end
%lc cc i mxn
for i = 1:size(f, 1)

for j = 1:size(f, 2)
window = zeros(1, (m * n));
index = 1;
for x = 1:m
for y = 1:n
window(index) = extendImage(i + x - 1, j + y - 1);
index = index + 1;
end
end
output(i, j) = max(window);
end
end
figure(1),imshow(f)
figure(2),imshow(output)

3.6.3. Lc Cc Tiu
input=imread('funny.jpg')
f = rgb2gray(input)
output = uint8(zeros(size(f)));
% bo loc mxn
m = 3;
n = 3;
extendImage = zeros(size(f, 1) + m - 1, size(f, 2)+ n - 1);
for x=1:size(f,1)
for y=1:size(f,2)

extendImage(x + floor(m / 2),y + floor(n / 2)) = f(x, y);


end
end
%min filter mxn
for i = 1:size(f, 1)
for j = 1:size(f, 2)
window = zeros(1, (m * n));
index = 1;
for x = 1:m
for y = 1:n
window(index) = extendImage(i + x - 1, j + y - 1);
index = index + 1;
end
end
output(i, j) = min(window);
end
end
figure(1),imshow(f)
figure(2),imshow(output)

You might also like