0% found this document useful (0 votes)
101 views20 pages

Image Imread ('Input - JPG') Image - RGB Rgb2gray (Image) F fft2 (Double (Image - RGB) ) Imshow (Abs (Fftshift (F) ), (24 100000) )

The document describes various image processing techniques applied to images, including: converting images to grayscale; taking Fourier transforms and reconstructing images from magnitude and phase; reducing image resolution through resizing; filtering images with averaging masks; edge detection using Sobel filters and discrete approximations of Laplacian and gradient operators. Images are read in, transformed, filtered and edges are detected to demonstrate these fundamental image processing concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views20 pages

Image Imread ('Input - JPG') Image - RGB Rgb2gray (Image) F fft2 (Double (Image - RGB) ) Imshow (Abs (Fftshift (F) ), (24 100000) )

The document describes various image processing techniques applied to images, including: converting images to grayscale; taking Fourier transforms and reconstructing images from magnitude and phase; reducing image resolution through resizing; filtering images with averaging masks; edge detection using Sobel filters and discrete approximations of Laplacian and gradient operators. Images are read in, transformed, filtered and edges are detected to demonstrate these fundamental image processing concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

>> image = imread('input.

jpg')
>> image_rgb = rgb2gray(image)
>> F = fft2(double(image_rgb))
>> imshow(abs(fftshift(F)),[24 100000])

>> RGB = imread('input2.png')


>> I = rgb2gray(RGB)
>> imshow(I)

>> F=fft2(double(I))
>> imshow(abs(fftshift(F)),[24 100000])

>> imshow(angle(fftshift(F)),[-pi pi])

>> FA=abs(F)
>> FB=exp(i*angle(F))
% inverse Fourier transform of FA (magnitude) and FB (phase):
>> IA = ifft2(FA)
%image reconstructed using magnitude information
>> IB = ifft2(FB)
%image reconstructed using phase information
% iift color ranges have to be set using imshow
>> cmin = min(min(abs(IA)))
>> cmax = max(max(abs(IA)))

>> dmin = min(min(abs(IB)))


>> dmax = max(max(abs(IB)))
>> imshow(abs(IA), [cmin cmax])

% imshow works automatically for natural images but for reconstruction, proper color limits should be
% set to display sufficient amount of detail in the image since FFT are infinite.
>> imshow(abs(FB), [dmin dmax])

>> im1 = imread('ariana.jpg')


>> imshow(im1)

% convert the rgb image (if it is) to gray-image.


>> im1 = rgb2gray(im1)

% 64 gray-level image
>> [IM5,map5]=gray2ind(im1,64)
% 16 gray-level image
>> [IM4,map4]=gray2ind(im1,16)
% 8 gray-level image
>> [IM3,map3]=gray2ind(im1,8)
% 4 gray-level image
>> [IM2,map2]=gray2ind(im1,4)
% 2 gray-level image
>> [IM1,map1]=gray2ind(im1,2)
>> figure(2), subplot(221), subimage(im1), title('original'), subplot(222), subimage(IM5,map5),
title('gray-level=64'),subplot(223), subimage(IM4,map4), title('gray-level=16'),subplot(224),
subimage(IM3,map3), title('gray-level=8'),pause

>> figure(3), subplot(221), subimage(im1), title('original'), subplot(222), subimage(IM3,map3),


title('gray-level=8'),subplot(223), subimage(IM2,map2), title('gray-level=4'),subplot(224),
subimage(IM1,map1), title('gray-level=2'),pause

>> im1 = imread(ariana.jpg)


% reduce the resolution by half the original value
>> IMG1 = imresize(im1,0.5)
>> IMG2 = imresize(im1,0.25)
>> IMG3 = imresize(im1,0.125)
>> figure(2), subplot(221), subimage(im1), title('orginal'),subplot(222), subimage(IMG1),
title('/2 resolution'),subplot(223), subimage(IMG2), title('/4 resolution'),subplot(224),
subimage(IMG3), title('/8 resolution'),pause

>> img = imread(dots.jpg)


>> img = grb2gray(img)
>> img1 = im2double(img)
>> mf =ones(5,5)/25
>> y = filter2(mf,img1)
>> imshow(y)

% averaging mask of size 5*5

>> mf =ones(11,11)/121

% averaging mask of size 11*11

>> y = filter2(mf,img1)
>> imshow(y)

>> img = imread(dots.jpg)


>> af=fftshift(fft2(img))
>> [x,y]=meshgrid(-128:127,-128:127)
>>z=sqrt(x.^2+y.^2)
>>c=z<15
>> af1=af.*c
>> af1iifft2(af1)
>> ifftshow(af1i)
>> fftshow(af1)

>> img = imread(strips.jpg)


>> af=fftshift(fft2(img))
>> [x,y]=meshgrid(-128:127,-128:127)

>>z=sqrt(x.^2+y.^2)
>>c=z>10
>> af1=af.*c
>> af1iifft2(af1)
>> ifftshow(af1i)
>> fftshow(af1)

>> img = imread(strips.jpg)


>> px=[-1 0 1; -1 0 1; -1 0 1]
>> icx = filter2(px,ic)
>> py=px
>> py =px;
>> icy=filter2(py,ic)
>> pedge = sqrt(icx.^2,icy.^2)

>> imshow(pedge/255)

>> A=imread('ariana.jpg');
>> B=rgb2gray(A);
>> C=double(B);
>> for i=1:size(C,1)-2
for j=1:size(C,2)-2
%Sobel mask for x-direction:
Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
%Sobel mask for y-direction:
Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
B(i,j)=sqrt(Gx.^2+Gy.^2);

end
end
>> figure,imshow(B); title('Sobel gradient');

>> a=imread('ariana.jpg');
>> a=rgb2gray(a);
>> b=im2double(a);
>> [m,n]=size(a)
>> N(1:m,1:n)=0
for i=1:m-2;
for j=1:m-2;
N(i,j)=-1*b(i,j)-1*b(i,j+1)-1*b(i,j+2)+0+0+0+1*b(i+2,j)+1*b(i+2,j+1)+1*b(i+2,j+2);
end;
end;

>> O(1:m,1:n)=0
>> for i=1:m-2;
for j=1:m-2;
O(i,j)=-1*b(i,j)+0+1*b(i,j+2)-1*b(i+2,j)+0+1*b(i+1,j+2)-1*b(i+2,j)+0+1*b(i+2,j+2);
end;
end;
>> Z=N+O;
>> imshow(Z);

>> a=imread('ariana.jpg');
>> b=im2double(a);
>> [m,n]=size(a);
>> L(1:m,1:n)=0
>> for i=1:m-2;
for j=1:m-2;
L(i,j)=-1*b(i,j)+0+0+1*b(i+1,j+1);
end;

end;
>> M(1:m,1:n)=0
>> for i=1:m-2;
for j=1:m-2;
M(i,j)=0-1*b(i,j+1)+1*b(i+1,j)+0;
end;
end;
>> N=M+L;
>> imshow(N);

You might also like