├── Assignment 1 ├── Assignment1_question1.m ├── Assignment1_question2.m ├── Assignment1_question3.m ├── Assignment1_question4.m └── README.md ├── Assignment 2 ├── Assignment2_question1.m ├── Assignment2_question2.m ├── Assignment2_question3.m └── README.md ├── Assignment 3 ├── Assignment3_question1.m ├── Assignment3_question2.m └── README.md ├── Assignment 4 ├── Assignment4_question1.m └── README.md ├── Assignment 5 ├── Assignment5_question1.m ├── Assignment5_question1_modified.m └── README.md ├── Assignment 6 ├── Assignment6_question1.m └── README.md ├── README.md ├── guassian_high_pass.m ├── guassian_low_pass.m ├── ideal_high_pass.m └── ideal_low_pass.m /Assignment 1/Assignment1_question1.m: -------------------------------------------------------------------------------- 1 | % Assignment 1 2 | % Question No1 3 | clc 4 | close all 5 | clear all 6 | %reading imge 7 | img = imread('tissue.png'); 8 | %seperating channels 9 | red = img(:,:,1); 10 | green = img(:,:,2); 11 | blue = img(:,:,3); 12 | 13 | %plotting 14 | subplot(2,2,1),imshow(img),title('Original Image'); 15 | subplot(2,2,2),imshow(red),title('Red Plane'); 16 | subplot(2,2,3),imshow(green),title('Green Plane'); 17 | subplot(2,2,4),imshow(blue),title('Blue Plane'); 18 | -------------------------------------------------------------------------------- /Assignment 1/Assignment1_question2.m: -------------------------------------------------------------------------------- 1 | %Assignment 1 2 | %Question 2 3 | 4 | clear all 5 | close all 6 | clc 7 | 8 | c = zeros(300,300); 9 | c(:,:) = 255; 10 | for x =1 :300 11 | for y =1 :300 12 | r = (x-150)*(x-150) + (y-150)*(y-150); 13 | r = sqrt(r); 14 | r = uint8(r); 15 | if(r==100) 16 | c(x,y) = 0; 17 | end 18 | end 19 | end 20 | 21 | figure; imshow(c); 22 | -------------------------------------------------------------------------------- /Assignment 1/Assignment1_question3.m: -------------------------------------------------------------------------------- 1 | %Assignment 1 2 | %Question 3 3 | 4 | clc 5 | clear all 6 | close all 7 | 8 | img = double(imread('cameraman.tif')); 9 | [row,col] = size(img); 10 | row= row/2; 11 | col=col/2; 12 | img_new = zeros(row,col); 13 | for r=1:1:256 14 | for c=1:1:256 15 | img_new(round(r/2),round(c/2)) = img(r,c); 16 | end 17 | end 18 | 19 | row=row/2; 20 | col=col/2; 21 | img_new1 = zeros(row,col); 22 | for r=1:1:128 23 | for c=1:1:128 24 | img_new1(round(r/2),round(c/2)) = img_new(r,c); 25 | end 26 | end 27 | 28 | img_new = uint8(img_new); 29 | img_new1 = uint8(img_new1); 30 | 31 | imwrite(img_new,'128x128.jpg','jpg'); 32 | imwrite(img_new1,'64x64.jpg','jpg'); 33 | 34 | subplot(1,3,1),imshow(img,[]),title('Original Image'); 35 | subplot(1,3,2),imshow(img_new),title('Image Size 1/2'); 36 | subplot(1,3,3),imshow(img_new1),title('Image Size 1/4'); -------------------------------------------------------------------------------- /Assignment 1/Assignment1_question4.m: -------------------------------------------------------------------------------- 1 | %Assignment 1 2 | %Question 4 3 | 4 | clc 5 | clear all 6 | close all 7 | 8 | img = double(imread('cameraman.tif')); 9 | 10 | [row,col] = size(img); 11 | 12 | counter = zeros(1,256); 13 | 14 | for r=1:row 15 | for c=1:col 16 | a=img(r,c); 17 | counter(1,a) = counter(1,a)+1; 18 | end 19 | 20 | end 21 | plot(counter); 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Assignment 1/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Assignment 1 4 | 5 | ## Question 1 6 | 7 | Read the color image (i.e. tissue.tif), display it using and imshow. Display the individual R , G , B planes of the image in gray in a single window using subplot. 8 | To use subplot function, read Matlab help. 9 | 10 | ## Question 2 11 | 12 | Write your own code that can draw a circle of radius = 100. 13 | Use following eq: x2 + y2 <= r2 14 | 15 | 16 | ## Question 3 17 | 18 | Load cameraman.tif, available in matlab, descimate it to 1/2, 1/4, of original spacial resolution display it using subplot and also save the results. 19 | 20 | ## Question 4 21 | 22 | Write tour own Matlab Code required to compute Histogram of an image (i.e. “cameraman.tif”). 23 | -------------------------------------------------------------------------------- /Assignment 2/Assignment2_question1.m: -------------------------------------------------------------------------------- 1 | %Question1 2 | clc 3 | close all 4 | clear all 5 | img = imread('cameraman.tif'); 6 | 7 | [row,col] = size(img); 8 | total_size = row*col; 9 | hist = zeros(1,256); 10 | 11 | for r=1:row 12 | for c=1:col 13 | a = img(r,c); 14 | hist(1,a) = hist(1,a)+1; 15 | end 16 | end 17 | 18 | pdf = zeros(1,256); 19 | pdf(:,:) = hist(:,:)./total_size; 20 | 21 | 22 | 23 | cdf = zeros(1,256); 24 | cdf(1,1) = pdf(1,1); 25 | for i=2:256 26 | cdf(1,i) = cdf(1,i-1)+pdf(1,i); 27 | end 28 | 29 | img_new = zeros(row,col); 30 | for r=1:row 31 | for c=1:col 32 | img_new(r,c) = cdf(1,img(r,c)); 33 | end 34 | end 35 | 36 | % figure,plot(hist); 37 | % figure,plot(pdf); 38 | % figure,plot(cdf); 39 | subplot(1,2,1),imshow(img),title('Original Image'); 40 | subplot(1,2,2),imshow(img_new),title('Histogram Equilized Image'); 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Assignment 2/Assignment2_question2.m: -------------------------------------------------------------------------------- 1 | %Question 2 2 | 3 | clc 4 | close all 5 | clear all 6 | 7 | img = imread('cameraman.tif'); 8 | [row,col] = size(img); 9 | 10 | filter3x3 = ones(3,3)/9; 11 | filter5x5 = ones(5,5)/25; 12 | 13 | %leave the first row and first column because filter does not fit 14 | %%-------------------3x3 Filter Code-----------------------------------% 15 | sum=0; 16 | x=0; 17 | y=0; 18 | img_new = zeros(row,col); 19 | for r=2:row-1 20 | for c=2:col-1 21 | 22 | for fr=1:3 23 | for fc=1:3 24 | sum = sum + img(r+x-1,c+y-1)*filter3x3(fr,fc); 25 | y=y+1; 26 | end 27 | y=0; 28 | x=x+1; 29 | end 30 | x=0; 31 | img_new(r,c) = sum; 32 | sum=0; 33 | end 34 | end 35 | %%-------------------------End of 3x3 Filter-----------------------------% 36 | 37 | %%---------------------5x5 Filter Code-----------------------------------%% 38 | sum=0; 39 | x=0; 40 | y=0; 41 | img_new1 = zeros(row,col); 42 | for r=3:row-2 43 | for c=3:col-2 44 | 45 | for fr=1:5 46 | for fc=1:5 47 | sum = sum + img(r+x-2,c+y-2)*filter5x5(fr,fc); 48 | y=y+1; 49 | end 50 | y=0; 51 | x=x+1; 52 | end 53 | x=0; 54 | img_new1(r,c) = sum; 55 | sum=0; 56 | end 57 | end 58 | %---------------------------End of 5x5 Filter----------------------%% 59 | 60 | subplot(1,3,1),imshow(img),title('Original Image'); 61 | subplot(1,3,2),imshow(img_new,[]),title('3x3 Filter Applied'); 62 | subplot(1,3,3),imshow(img_new1,[]),title('5x5 Filter Applied'); 63 | 64 | -------------------------------------------------------------------------------- /Assignment 2/Assignment2_question3.m: -------------------------------------------------------------------------------- 1 | %question 3 2 | 3 | clc 4 | clear all 5 | close all 6 | 7 | img = imread('cameraman.tif'); 8 | [row,col] = size(img); 9 | img_new = zeros(row,col); 10 | med_filter = zeros(3,3); 11 | x=0; 12 | y=0; 13 | for r=2:row-1 14 | for c=2:col-1 15 | for i=1:3 16 | for j=1:3 17 | med_filter(i,j) = img(r+x-1,c+y-1); 18 | y = y+1; 19 | end 20 | y=0; 21 | x=x+1; 22 | end 23 | x=0; 24 | med_filter = sort(med_filter); 25 | img_new(r,c) = med_filter(2,2); 26 | end 27 | end 28 | 29 | % test1 = medfilt2(img); 30 | 31 | subplot(1,2,1),imshow(img),title('Original Image'); 32 | subplot(1,2,2),imshow(img_new,[]),title('Image After 3x3 Median Filter'); 33 | %subplot(1,3,3),imshow(test1),title('test image'); -------------------------------------------------------------------------------- /Assignment 2/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Assignment 2 3 | 4 | ## Question 1 5 | 6 | Write your own MATLAB code to find the Histogram Equalized Image for any given image (i.e. “cameraman.tif”). Comment the code such that all the steps can be easily identified. 7 | 8 | ## Question 2 9 | 10 | Write the Matlab code to perform averaging (smoothing) on an image (i.e.‘cameraman.tif’) using box filter. 11 | 12 | i) Size of box filter: 3x3 13 | 14 | ii) Size of box filter: 5x5 15 | 16 | ## Question 3 17 | 18 | Write the Matlab code to perform median filtering for filter size 3x3 on any image (i.e.‘cameraman.tif’). 19 | 20 | Note: These are not optimized version of matlab scripts. For optimized versions of this assignment, goto DIP group on facebook. 21 | 22 | -------------------------------------------------------------------------------- /Assignment 3/Assignment3_question1.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | im = double(imread('cameraman.tif')); 6 | [row,col] = size(im); 7 | new_img = zeros(row,col); 8 | 9 | sobel_h = [-1 -2 -1;0 0 0;1 2 1]; 10 | sobel_v = [-1 0 1; -2 0 2;-1 0 1]; 11 | 12 | for r=2:row-1 13 | for c=2:col-1 14 | Gx = sum(sum(im(r-1:r+1,c-1:c+1).*sobel_h)); 15 | Gy = sum(sum(im(r-1:r+1,c-1:c+1).*sobel_v)); 16 | Gx = round(sqrt(Gx*Gx)); 17 | Gy = round(sqrt(Gy*Gy)); 18 | G = (Gx+Gy); 19 | new_img(r,c) = G; 20 | end 21 | end 22 | 23 | 24 | 25 | for r=1:row 26 | for c=1:col 27 | if(new_img(r,c)<=127) 28 | new_img(r,c) = 0; 29 | else 30 | new_img(r,c) = 1; 31 | end 32 | end 33 | end 34 | 35 | 36 | subplot(121);imshow(im,[]),impixelinfo,title('Original Image'); 37 | subplot(122);imshow(new_img,[]),impixelinfo,title('Sobel Image'); -------------------------------------------------------------------------------- /Assignment 3/Assignment3_question2.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | im = double(imread('cameraman.tif')); 6 | [row,col] = size(im); 7 | 8 | seg_img = zeros(row,col); 9 | 10 | k=2; 11 | 12 | cluster1 = []; 13 | cluster2 = []; 14 | 15 | c1_center = round(rand()*255); 16 | c2_center = round(rand()*255); 17 | c1 = 0; 18 | c2 = 0; 19 | 20 | while(c1~=c1_center && c2~=c2_center) 21 | for r=1:row 22 | for c=1:col 23 | x1 = round(sqrt((im(r,c)-c1_center)^2)); 24 | x2 = round(sqrt((im(r,c)-c2_center)^2)); 25 | if(x1 > x2) 26 | cluster2=im(r,c); 27 | else 28 | cluster1=im(r,c); 29 | end 30 | end 31 | 32 | end 33 | c1 = c1_center; 34 | c2 = c2_center; 35 | c1_center = mean(cluster1); 36 | c2_center = mean(cluster2); 37 | end 38 | 39 | for r=1:row 40 | for c=1:col 41 | x1 = round(sqrt((im(r,c)-c1_center)^2)); 42 | x2 = round(sqrt((im(r,c)-c2_center)^2)); 43 | if(im(r,c) > 127) 44 | seg_img(r,c) = 1; 45 | %else 46 | % seg_img(r,c) = 0; 47 | end 48 | end 49 | end 50 | 51 | subplot(121);imshow(im,[]),impixelinfo,title('Original Image') 52 | subplot(122);imshow(seg_img,[]),impixelinfo,title('Segmented Image') -------------------------------------------------------------------------------- /Assignment 3/README.md: -------------------------------------------------------------------------------- 1 | ##Assignment 3 2 | ###Language: Matlab 3 | 4 | ##Question 1 5 | ###Write your own Matlab Code to compute gradient magnitude (apply sobel based convolution) of an image (i.e. “cameraman.tif”). Apply thresholding on gradient magnitude image to obtain edge image. 6 | 7 | ##Question 2 8 | ###Read a color image in Matlab. Use RGB values of every pixel as feature and apply Segmentation using K-Mean clustering. K can be selected by user depending on the input image. 9 | 10 | Note: Question 2 is only for GRAYSCALE images. 11 | -------------------------------------------------------------------------------- /Assignment 4/Assignment4_question1.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | img = double(imread('cameraman.tif')); 6 | [row,col] = size(img); 7 | I = edge(img,'canny'); 8 | [M,N] = size(I); 9 | 10 | r_min = round(-sqrt(M^2+N^2)); 11 | r_min = abs(r_min)+1; 12 | r_max = r_min + round(sqrt(M^2+N^2)); 13 | 14 | A = zeros(180,r_max); 15 | 16 | for x=1:M 17 | for y=1:N 18 | if I(x,y)==1 19 | for t=1:180 20 | r = x*cos(deg2rad(t))+y*sin(deg2rad(t)); 21 | r = round(r); 22 | if r>0 23 | A(t,r+r_min) = A(t,r+r_min)+1; 24 | end 25 | end 26 | end 27 | end 28 | end 29 | 30 | imshow(A,[]); 31 | t1 = zeros(3,1); 32 | r1 = zeros(3,1); 33 | 34 | 35 | count =1; 36 | while count<=3 37 | max_A = max(max(A)); 38 | for i=1:size(A,1) 39 | for j=1:size(A,2) 40 | if A(i,j) == max_A 41 | t1(count,1)=i; 42 | r1(count,1) = j-r_min; 43 | A(i,j) = 0; 44 | end 45 | end 46 | end 47 | count = count+1; 48 | end 49 | 50 | 51 | for p=1:3 52 | x=0:max(M,N); 53 | y=round((r1(p,1)-x*cos(deg2rad(t1(p,1))))/sin(deg2rad(t1(p,1)))); 54 | figure,imshow(I,[]); 55 | hold on; 56 | plot(y,x,'r'); 57 | end 58 | 59 | -------------------------------------------------------------------------------- /Assignment 4/README.md: -------------------------------------------------------------------------------- 1 | ##Assignment 4 2 | ###Language: Matlab 3 | 4 | ##Question 1 5 | ###Write your own Matlab Code of Hough Transform in Polar coordinates to extract Best Three Lines from an image (i.e. “cameraman.tif”). 6 | 7 | -------------------------------------------------------------------------------- /Assignment 5/Assignment5_question1.m: -------------------------------------------------------------------------------- 1 | % Haris Corner Detection 2 | 3 | im = double(imread('cameraman.tif')); 4 | sobel_x = [1 2 1; 5 | 0 0 0; 6 | -1 -2 -1 7 | ]; 8 | 9 | sobel_y = transpose(sobel_x); 10 | 11 | Ix = conv2(im,sobel_x,'same'); 12 | Iy = conv2(im,sobel_y,'same'); 13 | Ixy = Ix .* Iy; 14 | R = zeros(size(im)); 15 | k = 0.05; 16 | for i=1:size(im,1) 17 | for j=1:size(im,1) 18 | M = [Ix(i,j).^2 Ixy(i,j); 19 | Ixy(i,j) Iy(i,j).^2 20 | ]; 21 | e = eig(M); 22 | det = e(1) * e(2); 23 | trace = e(1) + e(2); 24 | t = det - (k*(trace.^2)); 25 | if(t<-100000000) 26 | R(i,j) =255; 27 | else 28 | R(i,j) = 0; 29 | end 30 | end 31 | end 32 | max(max(R)) 33 | new_img = zeros(size(R)); 34 | 35 | for r=1:size(R,1) 36 | for c=1:size(R,2) 37 | 38 | 39 | end 40 | end 41 | 42 | figure,imshow(R,[]); 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Assignment 5/Assignment5_question1_modified.m: -------------------------------------------------------------------------------- 1 | clc 2 | close all 3 | clear global 4 | k = 0.04; 5 | Threshold = 50000; 6 | sigma = 1; 7 | halfwid = sigma * 3; 8 | [xx, yy] = meshgrid(-halfwid:halfwid, -halfwid:halfwid); 9 | Gxy = exp(-(xx .^ 2 + yy .^ 2) / (2 * sigma ^ 2)); 10 | Gx = xx .* exp(-(xx .^ 2 + yy .^ 2) / (2 * sigma ^ 2)); 11 | Gy = yy .* exp(-(xx .^ 2 + yy .^ 2) / (2 * sigma ^ 2)); 12 | I = imread('cameraman.tif'); 13 | numOfRows = size(I, 1); 14 | numOfColumns = size(I, 2); 15 | Ix = conv2(Gx, I); 16 | Iy = conv2(Gy, I); 17 | size(Ix) 18 | Ix2 = Ix .^ 2; 19 | Iy2 = Iy .^ 2; 20 | Ixy = Ix .* Iy; 21 | Sx2 = conv2(Gxy, Ix2); 22 | Sy2 = conv2(Gxy, Iy2); 23 | Sxy = conv2(Gxy, Ixy); 24 | im = zeros(numOfRows, numOfColumns); 25 | for x=1:numOfRows 26 | for y=1:numOfColumns 27 | H = [Sx2(x, y) Sxy(x, y); Sxy(x, y) Sy2(x, y)]; 28 | R = det(H) - k * (trace(H) ^ 2); 29 | if (R > Threshold) 30 | im(x, y) = R; 31 | end 32 | end 33 | end 34 | output = im > imdilate(im, [1 1 1; 1 0 1; 1 1 1]); 35 | figure, imshow(I); 36 | figure, imshow(output) 37 | 38 | max_val = max(max(output)); 39 | for i=1:size(output,1) 40 | for j=1:size(output,2) 41 | if max_val==output(i,j) 42 | i_max = i; 43 | j_max = j; 44 | break; 45 | 46 | end 47 | end 48 | end 49 | 50 | 51 | my = zeros(size(output)); 52 | my(i_max,j_max) = 1; 53 | figure, imshow(my,[]); 54 | 55 | figure,imshow(I,[]); 56 | -------------------------------------------------------------------------------- /Assignment 5/README.md: -------------------------------------------------------------------------------- 1 | ##Assignment 5 2 | ###Language: Matlab 3 | 4 | ##Question 1 5 | ###Write your own Matlab Code of Harris Corner Point detector to extract Best Corner Points from an image (i.e. “cameraman.tif”). 6 | -------------------------------------------------------------------------------- /Assignment 6/Assignment6_question1.m: -------------------------------------------------------------------------------- 1 | clear global 2 | close all 3 | clc 4 | im = imread('cameraman.tif'); 5 | f_im = fft2(im); 6 | Y = fftshift(f_im); 7 | mag = abs(Y); 8 | mag = log10(1+mag); 9 | figure; 10 | imshow(mag,[]); 11 | 12 | reverse = ifft2(f_im); 13 | 14 | figure; 15 | imshow(reverse,[]); -------------------------------------------------------------------------------- /Assignment 6/README.md: -------------------------------------------------------------------------------- 1 | ##Assignment 6 2 | 3 | ###Question 1 4 | 5 | Take fourier transform of 'cameraman.tif' display the fft and then take reverse of the fourier transform and display it.. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Digital Image Processing 3 | 4 | ### Course Instructor: 5 | Dr. Mobeen Ghafoor 6 | 7 | ### Course Books: 8 | 1. R. C. Gonzalez and R. E. Woods, “Digital Image Processing”, 2nd edition, Pearson Education, Inc., 2002 9 | 2. “Digital Image Processing using MATLAB” R. C. Gonzalez , R. E. Woods and S.L. Eddins Pearson Education, Inc., 2004 10 | 11 | ### Software 12 | MATLAB (Any Version) 13 | -------------------------------------------------------------------------------- /guassian_high_pass.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | 6 | low = 50; 7 | im = double(imread('cameraman.tif')); 8 | transform=fftshift(fft2(im)); 9 | real_part=real(transform); 10 | 11 | 12 | 13 | circle=zeros(size(im)); 14 | center=rows/2; 15 | [rows,columns]=size(im); 16 | 17 | 18 | 19 | for u=1:rows 20 | for v=1:columns 21 | circle(u,v)= exp(-(sqrt((u-center).^2+(v-center).^2).^2/low^2)); 22 | end 23 | end 24 | circle = 1 - circle; 25 | new_fft=transform.*circle; 26 | 27 | 28 | subplot(221);imshow(log2(real_part+1),[]);impixelinfo, title('fft') 29 | subplot(222);imshow(circle,[]),impixelinfo, title('High Pass circle') 30 | subplot(223);imshow(log2(new_fft+1),[]),impixelinfo, title('retained fft') 31 | subplot(224);imshow(ifft2(fftshift(new_fft)),[]),impixelinfo, title('image from retained fft') 32 | -------------------------------------------------------------------------------- /guassian_low_pass.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | 6 | low = 25; 7 | im = double(imread('cameraman.tif')); 8 | transform=fftshift(fft2(im)); 9 | real_part=real(transform); 10 | 11 | 12 | 13 | circle=zeros(size(im)); 14 | center=rows/2; 15 | [rows,columns]=size(im); 16 | 17 | 18 | 19 | for u=1:rows 20 | for v=1:columns 21 | circle(u,v)= exp(-(sqrt((u-center).^2+(v-center).^2).^2/low^2)); 22 | end 23 | end 24 | 25 | 26 | 27 | new_fft=transform.*circle; 28 | 29 | 30 | subplot(221);imshow(log2(real_part+1),[]);impixelinfo, title('fft') 31 | subplot(222);imshow(circle,[]),impixelinfo, title('Low pass circle') 32 | subplot(223);imshow(log2(new_fft+1),[]),impixelinfo, title('retained fft') 33 | subplot(224);imshow(ifft2(fftshift(new_fft)),[]),impixelinfo, title('image from retained fft') 34 | -------------------------------------------------------------------------------- /ideal_high_pass.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | 6 | 7 | %cutoff frequency for high pass 8 | high = 25; 9 | 10 | 11 | im = double(imread('cameraman.tif')); 12 | 13 | transform=fftshift(fft2(im)); 14 | real_part=real(transform); 15 | 16 | [rows,columns ,depth]=size(im); 17 | 18 | center=rows/2; 19 | circle=zeros(size(im)); 20 | 21 | for u=1:rows 22 | for v=1:columns 23 | circle(u,v)=sqrt((u-center).^2+(v-center).^2); 24 | end 25 | end 26 | 27 | 28 | circle_high=circle>high; 29 | 30 | 31 | 32 | %for high 33 | new_fft=transform.*circle_high; 34 | 35 | 36 | 37 | 38 | subplot(221);imshow(log2(real_part+1),[]);impixelinfo, title('fft of image'); 39 | subplot(222);imshow(circle_high,[]),impixelinfo, title('high pass circle'); 40 | subplot(223);imshow(log2(new_fft+1),[]),impixelinfo, title('retained fft from high pass'); 41 | subplot(224);imshow(ifft2(fftshift(new_fft)),[]),impixelinfo, title('image from high pass'); 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ideal_low_pass.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear global 3 | close all 4 | 5 | %cutoff frequency for low pass 6 | low = 25; 7 | 8 | im = double(imread('cameraman.tif')); 9 | 10 | transform=fftshift(fft2(im)); 11 | real_part=real(transform); 12 | 13 | [rows,columns ,depth]=size(im); 14 | 15 | center=rows/2; 16 | circle=zeros(size(im)); 17 | 18 | for u=1:rows 19 | for v=1:columns 20 | circle(u,v)=sqrt((u-center).^2+(v-center).^2); 21 | end 22 | end 23 | 24 | circle_low=circle