0% found this document useful (0 votes)
85 views

'Moon - Tif': Function

The document contains MATLAB code for various image processing functions including resizing images using DCT and FFT transforms, filtering images using averaging and Gaussian filters, adjusting image contrast, brightness and gamma levels, computing image histograms and gradients, and applying transformations like negatives.

Uploaded by

Rakesh Jalla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

'Moon - Tif': Function

The document contains MATLAB code for various image processing functions including resizing images using DCT and FFT transforms, filtering images using averaging and Gaussian filters, adjusting image contrast, brightness and gamma levels, computing image histograms and gradients, and applying transformations like negatives.

Uploaded by

Rakesh Jalla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

a=imread('moon.

tif'); function hist(file)


subplot(1,2,1),imshow(a) j=im2double(imread(file));
subplot(1,2,2),imhist(a) subplot(1,2,2),imshow(j);
xlabel('1.orginal picture')
g1=0,g2=0,g3=0,g4=0,g5=0,g6=0,g7=0,g8=0;
function negative (file)
g9=0,g10=0;
a=imread(file);
for ii=1:size(j,1)%hamsayegi 4
subplot(1,2,1),imshow(a)
for jj=1:size(j,2)
xlabel('orginal picture')
if j(ii,jj)<=.1
a=255-a;
g1=g1+1;
subplot(1,2,2),imshow(a)
elseif j(ii,jj)<=.2
g2=g2+1;
elseif j(ii,jj)<=.3
function compare_phase(file)
g3=g3+1;
a=imread(file);
elseif j(ii,jj)<=.4
a=im2double(a);
g4=g4+1;
b=fft2(a);
elseif j(ii,jj)<=.5
b1=abs(b)+10;
g5=g5+1;
b2=angle(b)+1;
elseif j(ii,jj)<=.6
for m=1:size(b,1)
g6=g6+1;
for n=1:size(b,2)
elseif j(ii,jj)<=.7
c(m,n)=b(m,n);
g7=g7+1;
elseif j(ii,jj)<=.8
d(m,n)=b1(m,n)*exp(i*b2(m,n));
g8=g8+1;
end
elseif j(ii,jj)<=.9
end
g9=g9+1;
c=ifft2(c);
elseif j(ii,jj)<=1
d=ifft2(d);
g10=g10+1;
subplot(2,2,1),imshow(a)
end
xlabel('orginal picture')
end
subplot(2,2,2),imshow(c)
end
xlabel('iff2 picture')
sath=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1];
subplot(2,2,3),imshow(d)
x=[g1 g2 g3 g4 g5 g6 g7 g8 g9 g10];
xlabel('chang phase&pik picture')
y=x./(size(j,1)*size(j,2));
stem(sath,y)

function grad(file)
a=im2double(imread(file));
b=0;
for m=2:size(a,1)-1
for n=2:size(a,2)-1
b(m,n)=-a(m-1,n-1)/8-2*a(m-1,n)/8-a(m-1,n+1)/8+a(m+1,n-1)/8+a(m+1,n-
1)/8+a(m,n)/8+a(m+1,n+1)/8;
c(m,n)=b(m,n)+a(m,n);
end
end
function gama(file)
subplot(1,3,1),imshow(a)
f=im2double(imread(file));
subplot(1,3,2),imshow(b)
subplot(2,2,1),
subplot(1,3,3),imshow(c)
imshow(f);
function contrast1 (file) xlabel('orginal ')
a=imread(file); f1=f.^.5;
subplot(1,2,1),imshow(a) subplot(2,2,2),
xlabel('orginal picture') imshow(f1);
for m=1:size(a,1) xlabel('gama=0.5')
for n=1:size(a,2) f2=f.^.8;
if a(m,n)<=80 subplot(2,2,3),
a(m,n)=a(m,n); imshow(f2);
elseif (a(m,n)>=80 && a(m,n)<=180) xlabel('gama=0.8')
a(m,n)=120; f3=f.^3;
else a(m,n)=a(m,n); subplot(2,2,4),
end imshow(f3);
end xlabel('gama=3')
end
subplot(1,2,2),imshow(a)
function filterrgb(file)
a=im2double(imread(file));
b=imnoise(a,'gaussian');
subplot(2,2,1),imshow(a)
subplot(2,2,2),imshow(b)
r=b(:,:,1);
r1=0;
g=b(:,:,2);
g1=0;
b=b(:,:,3);
b1=0;
for m=2:size(r,1)-1
for n=2:size(r,2)-1
r1(m,n)=(r(m-1,n-1)/8+r(m-1,n)/8+r(m-1,n+1)/8+r(m,n-
1)/8+r(m,n)/8+r(m,n+1)/8+r(m+1,n-1)/8+r(m+1,n)/8+r(m+1,n+1)/8);
end
end
for m=2:size(g,1)-1
for n=2:size(g,2)-1
g1(m,n)=(g(m-1,n-1)/8+g(m-1,n)/8+g(m-1,n+1)/8+g(m,n-
1)/8+g(m,n)/8+g(m,n+1)/8+g(m+1,n-1)/8+g(m+1,n)/8+g(m+1,n+1)/8);
end
end
for m=2:size(b,1)-1
for n=2:size(b,2)-1
b1(m,n)=(b(m-1,n-1)/8+b(m-1,n)/8+b(m-1,n+1)/8+b(m,n-
1)/8+b(m,n)/8+b(m,n+1)/8+b(m+1,n-1)/8+b(m+1,n)/8+b(m+1,n+1)/8);
end
end
p(:,:,1)=r1;
p(:,:,2)=g1;
p(:,:,3)=b1;
subplot(2,2,3),imshow(p)
function filter1(file)
a=imread(file);
function filter2(file)
a=im2double(a);
a=im2double(imread(file));
b=fft2(a); function contrast (file)
b=imnoise(a,'gaussian');
b1=abs(b); a=imread(file);
c=fft2(b);
b2=angle(b); subplot(1,2,1),imshow(a)
for m=1:size(a,1)
c=0; xlabel('orginal picture')
c1=0;for n=1:size(a,2) for m=1:size(a,1)
if (m<=1
for m=1:size(b,1) && n<=1) || (m>=200 && n>=200) for n=1:size(a,2)
c(m,n)=0;
for n=1:size(b,2) if a(m,n)<=80
else
if c(m,n)=c(m,n);
m<=200 && n<=200 a(m,n)=50;
a=imread('rice.png');
elseif (a(m,n)>=80 && a(m,n)<=180)
end c(m,n)=b(m,n);
b=dct2(a); a(m,n)=150;
end else c(m,n)=0;
c=idct2(b); else a(m,n)=250;
end end d=b; end
c=ifft2(c);
end e=b; end
subplot(1,3,1),imshow(a)
end f=b; end
subplot(1,3,2),imshow(b)
c=ifft2(c); d(abs(b)<50)=0;
subplot(1,2,2),imshow(a)
subplot(1,3,3),imshow(c)
for m=1:size(b,1) d=idct2(d);
for n=1:size(b,2) e(abs(b)>50 & abs(b)<200)=0;
if m>=50 && n>=50 e=idct2(e);
c1(m,n)=b(m,n); f(abs(b)>250)=0;
else c1(m,n)=0; f=idct2(f);
end subplot(2,3,1),imshow(a)
end xlabel('orginal picture')
end subplot(2,3,2),imshow(b)
c1=ifft2(c1); xlabel('DCT2 picture')
subplot(2,3,3),imshow(c,[0 255])
subplot(2,3,1),imshow(a) xlabel('IDCT2 picture')
xlabel('orginal picture') subplot(2,3,4),imshow(d,[0 255])
subplot(2,3,2),imshow(b1) xlabel('IDCT2 <50)=0 picture')
xlabel('abs fft2(a) picture') subplot(2,3,5),imshow(e,[0 255])
subplot(2,3,3),imshow(b2) xlabel('IDCT2 >50&<200)=0 picture')
xlabel('angle fft2(a) picture') subplot(2,3,6),imshow(f,[0 255])
subplot(2,3,4),imshow(c) xlabel('IDCT2 >250)=0 picture')
subplot(2,3,5),imshow(c1)
function average(file)
a=im2double(imread(file));
b=imnoise(a,'gaussian');
subplot(1,3,1),imshow(a)
subplot(1,3,2),imshow(b)
c=b;
for m=2:size(b,1)-1
for n=2:size(b,2)-1
c(m,n)=b(m-1,n-1)/9+ b(m-1,n)/9+ b(m-1,n+1)/9+ b(m,n-1)/9+ b(m,n)/9+ b(m,n+1)/9+
b(m+1,n-1)/9+ b(m+1,n)/9+ b(m+1,n+1)/9;
end
end
subplot(1,3,3),imshow(c)

function resize (file,s1,s2)


% resize with dct2 transfer
a=imread(file);
function resize_dct2 (file)
ad=im2double(a);
% resize with dct2 transfer
b=a(1:1/s1:end,1:1/s2:end);
a=imread(file);
figure;imshow(a);
ad=im2double(a);
xlabel('orginal picture')
%subplot(1,2,1);imshow(a),subplot(1,2,2),imshow(ad);
figure,imshow(b);
ze=zeros(598,50);
xlabel('resize picture')
j=dct2(ad);
j2=[j,ze];
j3=idct2(j2);
subplot(1,2,1);imshow(ad);
xlabel('orginal picture')
subplot(1,2,2),imshow(j3);
xlabel('resize picture')
function [j4,ad]=resize_dct2 (file,d,c)
% resize with fft2 transfer
a=imread(file);
ad=im2double(a);
%subplot(1,2,1);imshow(a),subplot(1,2,2),imshow(ad);
b=size(a,1);
e=size(a,2);
ze1=zeros(e+c,d);
ze2=zeros(b,c);
j=dct2(ad);
j2=[j,ze2];
j2=j2';
j2=[j2,ze1];
j3=j2';
j4=idct2(j3);
subplot(1,2,1);imshow(ad);
xlabel('orginal picture')
subplot(1,2,2),imshow(j4);
xlabel('resize picture')

function [j4,ad]=resize_fft2 (file,d,c)


% resize with fft2 transfer
a=imread(file);
ad=im2double(a);
%subplot(1,2,1);imshow(a),subplot(1,2,2),imshow(ad)
;
b=size(a,1);
e=size(a,2); function astane(file)
ze1=zeros(e+c,d); a=imread(file);
ze2=zeros(b,c); subplot(1,2,1),imshow(a)
j=fft2(ad); xlabel('orginal picture')
j2=[j,ze2]; for m=1:size(a,1)
j2=j2'; for n=1:size(a,2)
j2=[j2,ze1]; if a(m,n)<= 100
j3=j2'; a(m,n)=0;
j4=ifft2(j3); else a(m,n)=1;
subplot(1,2,1);imshow(ad); end
xlabel('orginal picture') end
subplot(1,2,2),imshow(j4); end
xlabel('resize picture') a=a*255;
subplot(1,2,2),imshow(a)

M_Saki 87/04/22

You might also like