├── Color Image Processing ├── GRAY2IND.m ├── RGB2GRAY.m ├── RGB2HSV.m ├── RGB2NTSC.m ├── RGB_PLOT.m ├── horizontal_flip.m ├── horizontal_reflection.m ├── impadded.m ├── log_transformation.m ├── negative.m ├── power_law.m ├── quantization.m ├── sampling.m ├── slice_color_channel.m ├── vertical_flip.m └── vertical_reflection.m ├── Histogram Processing ├── histogram_equalization.m ├── histogram_matching.m └── histogram_plot.m ├── Image Compression ├── DCT2.m ├── iDCT2.m └── jpeg.m ├── Image Enhancement ├── Smoothing Filters │ ├── Avg_Weighted_Filter.m │ ├── Box_Filter.m │ ├── Max_Filter.m │ ├── Median_Filter.m │ └── Min_Filter.m ├── contrast_stretching.m └── gray_level_slicing.m ├── Image Representation └── signature_plotting.m ├── Image Restoration ├── arithmetic_mean_filter.m ├── geometric_mean_filter.m ├── harmonic_mean_filter.m ├── noise_detection_using_histogram.m ├── remove_gusssian_noise.m └── remove_uniform_noise.m ├── LICENSE ├── Morphological Operations ├── Create_your_bw_image.m ├── boundary_extraction.m ├── closing.m ├── dilation.m ├── erosion.m ├── logical_arithmetic_operations.m ├── opening.m ├── opening_closing.m └── region_filling.m ├── README.md ├── getDimensions.m └── images ├── 1.jpg ├── 2.jpg ├── Q10_result.jpg ├── boundary_extraction_result.jpg ├── circle_signature.png ├── closing_result.jpg ├── contrast_streching_result.jpg ├── dilation_result.jpg ├── e7.tif ├── eg1.jpg ├── erosion_result.jpg ├── gray_level_slicing_result.jpg ├── guassian_noise_result.png ├── histogram_matching_result.jpg ├── histogram_plot_result.jpg ├── input images ├── Fig0316(4)(bottom_left).tif ├── Low-contrast.png ├── circle.jpg ├── circles.jpg ├── e14.tif ├── e15.tif ├── e16.tif ├── e17.tif ├── e18.tif ├── e19.tif ├── e20.tif ├── e21.tif ├── e22.tif ├── e23.tif ├── e24.tif ├── e25.tif ├── e26.tif ├── e27.tif ├── e28.tif ├── e29.tif ├── e3.jpg ├── e30.tif ├── e7.tif ├── e8.tif ├── eg1.jpg ├── kevin.jpg ├── letter-j.png └── myImage.jpg ├── log_transformation_result.jpg ├── negative_result.jpg ├── noise_result.png ├── opening_closing_result.jpg ├── opening_result.jpg ├── power_law_result (2).jpg ├── region_filling_result.png ├── signature_output.png ├── smoothing_filter_result.jpg └── uniform_noise_result.png /Color Image Processing/GRAY2IND.m: -------------------------------------------------------------------------------- 1 | function imind = GRAY2IND() 2 | 3 | % replace `PATH_TO_GRAY_IMAGE` with actual image file 4 | impath = 'PATH_TO_GRAY_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert grayscale image to indexed image 10 | imind=gray2ind(img); 11 | 12 | % plot the results 13 | subplot(1,2,1),imshow(img); 14 | title('Original RGB image','FontSize',18); 15 | 16 | subplot(1,2,2),imshow(imind); 17 | title('Indexed image','FontSize',18); 18 | 19 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/RGB2GRAY.m: -------------------------------------------------------------------------------- 1 | function grayscale = RBG2GRAY() 2 | 3 | % replace `PATH_TO_RGB_COLOR_IMAGE` with actual image file 4 | impath = 'PATH_TO_RGB_COLOR_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray image 10 | grayscale=rgb2gray(img); 11 | 12 | % plot the results 13 | subplot(1,2,1),imshow(img); 14 | title('Original RGB image','FontSize',18); 15 | 16 | subplot(1,2,2),imshow(grayscale); 17 | title('GrayScale image','FontSize',18); 18 | 19 | endfunction 20 | -------------------------------------------------------------------------------- /Color Image Processing/RGB2HSV.m: -------------------------------------------------------------------------------- 1 | function imhsv = RGB2HSV() 2 | 3 | % replace `PATH_TO_RGB_COLOR_IMAGE` with actual image file 4 | %impath = 'PATH_TO_RGB_COLOR_IMAGE'; 5 | impath = '../images/input images/kevin.jpg'; 6 | 7 | % read image 8 | img = imread(impath); 9 | 10 | % convert rgb image to hsv image 11 | imhsv=rgb2hsv(img); 12 | 13 | % plot the results 14 | subplot(1,2,1),imshow(img); 15 | title('Original RGB image','FontSize',18); 16 | 17 | subplot(1,2,2),imshow(imhsv); 18 | title('HSV image','FontSize',18); 19 | 20 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/RGB2NTSC.m: -------------------------------------------------------------------------------- 1 | function imyiq = RGB2NTSC() 2 | 3 | %% 4 | % |============================================================================ 5 | % | Attribute | Description | 6 | % |---------------------------------------------------------------------------- 7 | % | | | 8 | % | | Luma, or brightness of the image. Values are in the range | 9 | % | Y | [0, 1], where 0 specifies black and 1 specifies white. | 10 | % | | Colors increase in brightness as Y increases. | 11 | % |___________|_______________________________________________________________| 12 | % | | | 13 | % | | In-phase, which is approximately the amount of blue or orange | 14 | % | | tones in the image. I in the range [-0.5959, 0.5959], where | 15 | % | I | negative numbers indicate blue tones and positive numbers | 16 | % | | indicate orange tones. As the magnitude of I increases, the | 17 | % | | saturation of the color increases. | 18 | % |___________|_______________________________________________________________| 19 | % | | | 20 | % | | Quadrature, which is approximately the amount of green or | 21 | % | | purple tones in the image. Q in the range [-0.5229, 0.5229], | 22 | % | Q | where negative numbers indicate green tones and positive | 23 | % | | numbers indicate purple tones. As the magnitude of Q | 24 | % | | increases, the saturation of the color increases. | 25 | % | | | 26 | % |============================================================================ 27 | % 28 | 29 | % replace `PATH_TO_RGB_COLOR_IMAGE` with actual image file 30 | impath = 'PATH_TO_RGB_COLOR_IMAGE'; 31 | 32 | % read image 33 | img = imread(impath); 34 | 35 | % convert rgb image to yiq image 36 | imyiq=rgb2ntsc(img); 37 | 38 | % plot the results 39 | subplot(1,3,1),imshow(img); 40 | title('Original RGB image','FontSize',18); 41 | 42 | subplot(1,3,2),imshow(imyiq); 43 | title('NTSC image','FontSize',18); 44 | 45 | subplot(1,3,3),imshow(imyiq(:,:,1)); 46 | title('Illuminace Component','FontSize',18); 47 | 48 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/RGB_PLOT.m: -------------------------------------------------------------------------------- 1 | function img = RGB_PLOT() 2 | 3 | % replace `PATH_TO_RGB_COLOR_IMAGE` with actual image file 4 | %impath = 'PATH_TO_RGB_COLOR_IMAGE'; 5 | impath = '../images/input images/kevin.jpg'; 6 | 7 | % read image 8 | img = imread(impath); 9 | 10 | % convert rgb image to hsv image 11 | imhsv=colormap(img); 12 | 13 | % plot the results 14 | subplot(1,2,1),imshow(img); 15 | title('Original RGB image','FontSize',18); 16 | 17 | subplot(1,2,2),imshow(imhsv); 18 | title('HSV image','FontSize',18); 19 | 20 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/horizontal_flip.m: -------------------------------------------------------------------------------- 1 | function resimg = horizontal_flip() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | img = imread(impath); 7 | 8 | % fetch the dimension of image 9 | % n denotes number of color channel / planes (i.e. 3 for RGB image) 10 | % nr & nc defines number of rows & columns respectively in each planes 11 | [nr,nc,n] = size(img); 12 | 13 | % logic for flipping the image 14 | for i = 1:nr 15 | 16 | resimg(i,1:nc,1:n) = img(nr-i+1,1:nc,1:n); 17 | 18 | endfor 19 | 20 | % plot the results 21 | subplot(1,2,1),imshow(img); 22 | title('Original Image','FontSize',18); 23 | 24 | subplot(1,2,2),imshow(resimg); 25 | title('Horizontally Filpped Image','FontSize',18); 26 | 27 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/horizontal_reflection.m: -------------------------------------------------------------------------------- 1 | function resimg = horizontal_reflection() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | img = imread(impath); 7 | 8 | % fetch the dimension of image 9 | % n denotes number of color channel / planes (i.e. 3 for RGB image) 10 | % nr & nc defines number of rows & columns respectively in each planes 11 | [nr,nc,n] = size(img); 12 | 13 | % copy original part 14 | resimg = img; 15 | 16 | % logic for copying flipped of the image 17 | for i = 1:nr 18 | 19 | resimg(i+nr,1:nc,1:n) = img(nr-i+1,1:nc,1:n); 20 | 21 | endfor 22 | 23 | % plot the results 24 | subplot(1,2,1),imshow(img); 25 | title('Original Image','FontSize',18); 26 | 27 | subplot(1,2,2),imshow(resimg); 28 | title('Horizontal Reflextion','FontSize',18); 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /Color Image Processing/impadded.m: -------------------------------------------------------------------------------- 1 | %% 2 | % This function accepts 5 parameters: 3 | % 4 | % impath => [string] Image File Path 5 | % addr => [int] Number of rows to be added on both the sides 6 | % addc => [int] Number of columns to be added on both the sides 7 | % showplots => [boolean] TRUE if you want to show plot else FALSE 8 | % isNotGray => [boolean] TRUE if image is colormap or rgb image else FALSE 9 | % 10 | 11 | function padded_img = impadded(impath,addr,addc,showplots,isNotGray) 12 | 13 | % read image 14 | img = imread(impath); 15 | 16 | % check if image isNotGray == TRUE then convert to grayscale 17 | if isNotGray 18 | img = rgb2gray(img); 19 | end if 20 | 21 | % fetch the dimensions of the image 22 | [nr,nc]=size(img); 23 | 24 | % initialize the padded_img with all zeros 25 | padded_img = uint8(zeros(nr+2*addr,nc+2*addc)); 26 | 27 | % copy img to center of the padded_img 28 | padded_img((addr+1):(nr+addr),(addc+1):(nc+addc)) = img; 29 | 30 | % check if subplots == TRUE then plot the results 31 | if showplots 32 | subplot(1,2,1),imshow(img); 33 | title('Input Gray Image'); 34 | subplot(1,2,2),imshow(padded_img); 35 | title('Output Gray Padded Image'); 36 | endif 37 | 38 | endfunction 39 | -------------------------------------------------------------------------------- /Color Image Processing/log_transformation.m: -------------------------------------------------------------------------------- 1 | function imlogtrans = log_transformation(impath,c) 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file path 4 | impath = 'PATH_TO_IMAGE_FILE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % c is a constant 10 | c = 1 11 | 12 | subplot(1,2,1),imshow(img); 13 | title('Original Image'); 14 | 15 | % convert uint8 to double 16 | img = double(img); 17 | 18 | % perform log transoformation using s = c * log( 1 + c ) 19 | imlogtrans = c .* log(1 + img); 20 | 21 | subplot(1,2,2),imshow(imlogtrans); 22 | title('Log Transformation Image'); 23 | 24 | endfunction 25 | -------------------------------------------------------------------------------- /Color Image Processing/negative.m: -------------------------------------------------------------------------------- 1 | function imneg = negative() 2 | % replace `PATH_TO_IMAGE` with actual image file path 3 | impath = 'PATH_TO_IMAGE_FILE'; 4 | 5 | % read image 6 | img = imread(impath); 7 | 8 | % number of spectrum of colors supported in image 9 | % 256 : for uint8 image (8 bit image) 10 | L = 256; 11 | 12 | % convert img image to imneg 13 | imneg = (L - 1) - img; 14 | 15 | % show original image 16 | imshow(img); 17 | Title('Original Image'); 18 | 19 | % show negative image 20 | imshow(imneg); 21 | title('Negative'); 22 | endfunction 23 | -------------------------------------------------------------------------------- /Color Image Processing/power_law.m: -------------------------------------------------------------------------------- 1 | function implt = power_law() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file path 4 | impath = 'PATH_TO_IMAGE_FILE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % c is a constant 10 | c = 1 11 | 12 | subplot(2,3,1),imshow(img); 13 | title('Original Image'); 14 | 15 | % normalize the image (uint8 to double) 16 | img = double(img)/255; 17 | 18 | % gamma correction array 19 | gamma = [0.2,0.4,1,2.5,5]; 20 | 21 | % computing power law for all values of gamma in array 22 | for i = 1:len(gamma) 23 | % computing s = c * (r ^ gamma) where c and gamma are positive constants 24 | implt = c * (img .^ gamma(i)); 25 | subplot(2,3,i+1),imshow(implt); 26 | title(strcat({'Gamma = '},num2str(gamma(i)))); 27 | clear implt; 28 | endfor 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /Color Image Processing/quantization.m: -------------------------------------------------------------------------------- 1 | function imquantize = qauntization() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file path 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray image 10 | imgray = rgb2gray(img); 11 | 12 | % fetch the dimensions of image 13 | [nr,nc] = size(imgray); 14 | 15 | for i = 1:nr 16 | for j = 1:nc 17 | int = imgray(i,j); 18 | if int>=0 && int<52 19 | imquantize(i,j) = 0; 20 | elseif int>=52 && int<104 21 | imquantize(i,j) = 52; 22 | elseif int>=104 && int<156 23 | imquantize(i,j) = 104; 24 | elseif int>=156 && int<208 25 | imquantize(i,j) = 156; 26 | elseif int>=208 && int<256 27 | imquantize(i,j)=208; 28 | endif 29 | endfor 30 | endfor 31 | 32 | % plot the results 33 | subplot(1,3,1),imshow(img); 34 | title('Original image'); 35 | subplot(1,3,2),imshow(imgray); 36 | title('GrayScale image'); 37 | subplot(1,3,3),imshow(imquantize); 38 | title('Quantized image'); 39 | 40 | endfunction 41 | -------------------------------------------------------------------------------- /Color Image Processing/sampling.m: -------------------------------------------------------------------------------- 1 | function [] = sampling() 2 | close all;clear;clc; 3 | 4 | % replace `PATH_TO_IMAGE_FILE` with actual image file path 5 | impath = 'PATH_TO_IMAGE_FILE'; 6 | 7 | % read image 8 | img = imread(impath); 9 | 10 | % get the dimensions of image 11 | [nr, nc] = size(img); 12 | 13 | subplot(1,3,1),imshow(img); 14 | title('Original image'); 15 | 16 | imggray = rgb2gray(img); 17 | subplot(1,3,2),imshow(imggray); 18 | title('GrayScale Image'); 19 | 20 | % set the number of skips 21 | m = 2; % reads pixel 1st and then skips 2nd pixel and reads 3rd pixel and so on... 22 | 23 | l=1; 24 | for i = 1:m:nr 25 | k=1; 26 | for j = 1:m:nc 27 | imggray_new(l,k) = imggray(i,j); 28 | k=k+1; 29 | endfor 30 | l=l+1; 31 | endfor 32 | subplot(1,3,3),imshow(imggray_new); 33 | title("GrayScale Image After Sampling"); 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /Color Image Processing/slice_color_channel.m: -------------------------------------------------------------------------------- 1 | function [imred,imblue,imgreen] = slice_color_channel() 2 | 3 | % replace `PATH_TO_RGB_COLORED_IMAGE` with actual image file path 4 | impath = 'PATH_TO_RGB_COLORED_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % fetch the width and height dimension of image 10 | [nr,nc] = size(img(:,:,1)); 11 | 12 | % red color component of img 13 | imred=uint8(zeros(nr,nc,3)); 14 | imred(:,:,1)=img(:,:,1); 15 | 16 | % green color component of img 17 | imgreen=uint8(zeros(nr,nc,3)); 18 | imgreen(:,:,2)=img(:,:,2); 19 | 20 | % blue color component of img 21 | imblue=uint8(zeros(nr,nc,3)); 22 | imblue(:,:,3)=img(:,:,3); 23 | 24 | % plot the results 25 | subplot(1,4,1),imshow(img); 26 | title('Original image','FontSize',18); 27 | 28 | subplot(1,4,2),imshow(imred); 29 | title('Red image','FontSize',18); 30 | 31 | subplot(1,4,3),imshow(imgreen); 32 | title('Green image','FontSize',18); 33 | 34 | subplot(1,4,4),imshow(imblue); 35 | title('Blue image','FontSize',18); 36 | 37 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/vertical_flip.m: -------------------------------------------------------------------------------- 1 | function resimg = vertical_flip() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | img = imread(impath); 7 | 8 | % fetch the dimension of image 9 | % n denotes number of color channel / planes (i.e. 3 for RGB image) 10 | % nr & nc defines number of rows & columns respectively in each planes 11 | [nr,nc,n] = size(img); 12 | 13 | % logic for flipping the image 14 | for i = 1:nc 15 | 16 | resimg(1:nr,i,1:n) = img(1:nr,nc-i+1,1:n); 17 | 18 | endfor 19 | 20 | % plot the results 21 | subplot(1,2,1),imshow(img); 22 | title('Original Image','FontSize',18); 23 | 24 | subplot(1,2,2),imshow(resimg); 25 | title('Vertically Filpped Image','FontSize',18); 26 | 27 | endfunction -------------------------------------------------------------------------------- /Color Image Processing/vertical_reflection.m: -------------------------------------------------------------------------------- 1 | function resimg = vertical_reflection() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | img = imread(impath); 7 | 8 | % fetch the dimension of image 9 | % n denotes number of color channel / planes (i.e. 3 for RGB image) 10 | % nr & nc defines number of rows & columns respectively in each planes 11 | [nr,nc,n] = size(img); 12 | 13 | % copy original part 14 | resimg = img; 15 | 16 | % logic for copying flipped of the image 17 | for i = 1:nc 18 | 19 | resimg(1:nr,i+nc,1:n) = img(1:nr,nc-i+1,1:n); 20 | 21 | endfor 22 | 23 | % plot the results 24 | subplot(1,2,1),imshow(img); 25 | title('Original Image','FontSize',18); 26 | 27 | subplot(1,2,2),imshow(resimg); 28 | title('Vertical Reflextion','FontSize',18); 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /Histogram Processing/histogram_equalization.m: -------------------------------------------------------------------------------- 1 | function [res] = histogram_equalization() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file path 4 | impath = 'PATH_TO_IMAGE_FILE'; 5 | 6 | % read image 7 | img=imread(imgpath); 8 | 9 | % converts rgb image to gray scale image (optional) 10 | imggray=rgb2gray(img); 11 | 12 | % find dimension of image 13 | [nr,nc]=size(imggray); 14 | 15 | %% 16 | % Generate Count array having count of pixels 17 | % 18 | 19 | arr=zeros(1,256); 20 | for i = 1:nr 21 | for j = 1:nc 22 | arr(imggray(i,j)+1)=arr(imggray(i,j)+1)+1; 23 | endfor 24 | endfor 25 | 26 | nk=arr; 27 | pk=zeros(1,256); 28 | res=zeros(1,256); 29 | sk=zeros(1,256); 30 | imgnew=imggray; 31 | 32 | % find total number of pixels 33 | n=sum(sum(nk)); 34 | 35 | % generate histogram equalization table 36 | for i=1:256 37 | pk(i)=nk(i)/n; 38 | if i>1 39 | sk(i)=sk(i-1)+pk(i); 40 | else 41 | sk(1)=pk(1); 42 | endif 43 | ans(i)=round(255*sk(i)); 44 | res(ans(i)+1)=res(ans(i)+1)+nk(i); 45 | endfor 46 | 47 | % generate a new image 48 | for i = 1:nr 49 | for j = 1:nc 50 | imgnew(i,j)=ans(imggray(i,j)+1); 51 | endfor 52 | endfor 53 | 54 | % plot the inputs & outputs 55 | subplot(2,2,1),imshow(imggray); 56 | title('Gray Image'); 57 | subplot(2,2,3),bar(0:255,arr,1); 58 | title('Histogram Plot'); 59 | subplot(2,2,4),bar(0:255,res,1); 60 | title('Histogram Equalization'); 61 | subplot(2,2,2),imshow(imgnew); 62 | title('New Image'); 63 | 64 | endfunction 65 | -------------------------------------------------------------------------------- /Histogram Processing/histogram_matching.m: -------------------------------------------------------------------------------- 1 | function [res] = histogram_matching() 2 | 3 | %% 4 | % Histogram matching transform input image such that it's histogram matches specified output image histogram 5 | % 6 | 7 | % replace `PATH_TO_INPUT_IMAGE_FILE` & `PATH_TO_OUTPUT_IMAGE_FILE` with actual image file paths 8 | inpath = 'PATH_TO_INPUT_IMAGE_FILE'; 9 | outpath = 'PATH_TO_OUTPUT_IMAGE_FILE'; 10 | 11 | % read image 12 | img1=imread(inpath); 13 | img2=imread(outpath); 14 | 15 | %% 16 | % converts rgb image to gray scale image (optional: Use ONLY when your input image is in RGB format) 17 | % if image is not in RGB format then use: 18 | % imggray1 = img1; 19 | % 20 | imggray1=rgb2gray(img1); 21 | 22 | %% 23 | % converts rgb image to gray scale image (optional: Use ONLY when your output image is in RGB format) 24 | % if image is not in RGB format then use: 25 | % imggray2 = img2; 26 | % 27 | imggray2=rgb2gray(img2); 28 | 29 | % calculate dimesions of both the images 30 | [nr1,nc1]=size(imggray1); 31 | [nr2,nc2]=size(imggray2); 32 | 33 | 34 | %% 35 | % Plot histogram for input image 36 | % 37 | arr1=zeros(1,256); 38 | for i = 1:nr1 39 | for j = 1:nc1 40 | arr1(imggray1(i,j)+1)=arr1(imggray1(i,j)+1)+1; 41 | endfor 42 | endfor 43 | 44 | nk=arr1; 45 | pk=zeros(1,256); 46 | res1=zeros(1,256); 47 | sk=zeros(1,256); 48 | imgnew1=imggray1; 49 | n=sum(sum(nk)); 50 | for i=1:256 51 | pk(i)=nk(i)/n; 52 | if i>1 53 | sk(i)=sk(i-1)+pk(i); 54 | else 55 | sk(1)=pk(1); 56 | endif 57 | ans1(i)=round(255*sk(i)); 58 | res1(ans1(i)+1)=res1(ans1(i)+1)+nk(i); 59 | endfor 60 | 61 | %% 62 | % Plot histogram for output image 63 | % 64 | arr2=zeros(1,256); 65 | for i = 1:nr2 66 | for j = 1:nc2 67 | arr2(imggray2(i,j)+1)=arr2(imggray2(i,j)+1)+1; 68 | endfor 69 | endfor 70 | 71 | nk=arr2; 72 | pk=zeros(1,256); 73 | res2=zeros(1,256); 74 | sk=zeros(1,256); 75 | imgnew2=imggray2; 76 | n=sum(sum(nk)); 77 | for i=1:256 78 | pk(i)=nk(i)/n; 79 | if i>1 80 | sk(i)=sk(i-1)+pk(i); 81 | else 82 | sk(1)=pk(1); 83 | endif 84 | ans2(i)=round(255*sk(i)); 85 | res2(ans2(i)+1)=res2(ans2(i)+1)+nk(i); 86 | endfor 87 | 88 | %% 89 | % Perform histogram matching 90 | % 91 | for i = 1:nr1 92 | for j = 1:nc1 93 | k = ans1(imggray1(i,j)+1); 94 | while 1==1 95 | inx = find(ans2==k); 96 | if size(inx) != [0 0] 97 | imgnew1(i,j)=inx(1,1)-1; 98 | break; 99 | else 100 | k=k+1; 101 | endif 102 | endwhile 103 | endfor 104 | endfor 105 | 106 | %% 107 | % Display the results 108 | % 109 | subplot(2,3,1),imshow(imggray1); 110 | title('Gray Image 1','FontSize',20); 111 | subplot(2,3,2),imshow(imggray2); 112 | title('Gray Image 2','FontSize',20); 113 | subplot(2,3,4),bar(0:255,arr1,1); 114 | title('Histogram Image 1','FontSize',20); 115 | subplot(2,3,5),bar(0:255,arr2,1); 116 | title('Histogram Image 2','FontSize',20); 117 | subplot(2,3,6),bar(0:255,res2,1); 118 | title('Histogram Output','FontSize',20); 119 | subplot(2,3,3),imshow(imgnew1); 120 | title('New Image','FontSize',20); 121 | 122 | endfunction 123 | -------------------------------------------------------------------------------- /Histogram Processing/histogram_plot.m: -------------------------------------------------------------------------------- 1 | function [count,grayscale] = histogram_plot() 2 | 3 | %% 4 | % you can also use inbuilt function `imhist()` in matlab to plot histogram for any image 5 | % 6 | 7 | % replace `PATH_TO_IMAGE` with actual image file path 8 | impath = 'PATH_TO_IMAGE_FILE'; 9 | 10 | % define grayscale (all the possible intensity value in the image) 11 | grayscale = 0:255; 12 | 13 | % read image 14 | img = imread(impath); 15 | 16 | imggray=rgb2gray(img); % optional only if image is color image 17 | 18 | % fetch image dimensions 19 | [nr,nc]=size(imggray); 20 | 21 | count=zeros(1,256); 22 | for i = 1:nr 23 | for j = 1:nc 24 | count(imggray(i,j))=count(imggray(i,j))+1; 25 | endfor 26 | endfor 27 | 28 | % Show Image 29 | subplot(1,2,1),imshow(imggray); 30 | title('Image','FontSize',20); 31 | 32 | % plot the bar chart 33 | subplot(1,2,2),bar(grayscale, count, 'BarWidth', 1); 34 | 35 | % define xlabel 36 | xlabel('Gray Level','FontSize',20); 37 | 38 | % define ylabel 39 | ylabel('Pixel Count','FontSize',20); 40 | 41 | % title of the plot 42 | title('Histogram Plot','FontSize',20); 43 | 44 | endfunction 45 | -------------------------------------------------------------------------------- /Image Compression/DCT2.m: -------------------------------------------------------------------------------- 1 | function res = DCT2(M,N=8) % matrix M on which DCT is to be applied; size of cosine matrix N; 2 | 3 | %% 4 | % 5 | % DCT2 : Discrete Cosine Transformation 6 | % 7 | % 8 | % generate cosine matrix 9 | C = zeros(N,N); 10 | 11 | for i = 1:N 12 | 13 | C(1,i) = sqrt(1/N); 14 | 15 | endfor 16 | 17 | for i = 2:N 18 | for j = 1:N 19 | 20 | C(i,j) = sqrt(2/N)*cos(((2*j-1)*pi*(i-1))/(2*N)); 21 | 22 | endfor 23 | endfor 24 | 25 | % fetch matrix dimensions 26 | [nr,nc] = size(M); 27 | 28 | res = zeros(nr,nc); 29 | 30 | %% 31 | % Apply DCT 32 | % 33 | for i=[1:N:nr] 34 | for j=[1:N:nc] 35 | zBLOCK = M(i:i+N-1,j:j+N-1); 36 | win=C*zBLOCK*C'; 37 | res(i:i+N-1,j:j+N-1)=win; 38 | end 39 | end 40 | 41 | endfunction -------------------------------------------------------------------------------- /Image Compression/iDCT2.m: -------------------------------------------------------------------------------- 1 | function res = iDCT2(M,N=8) % matrix M on which inverse DCT is to be applied; size of cosine matrix N; 2 | 3 | %% 4 | % 5 | % iDCT2 : Inverse Discrete Cosine Transformation 6 | % 7 | % 8 | % generate cosine matrix C 9 | C = zeros(N,N); 10 | 11 | for i = 1:N 12 | 13 | C(1,i) = sqrt(1/N); 14 | 15 | endfor 16 | 17 | for i = 2:N 18 | for j = 1:N 19 | 20 | C(i,j) = sqrt(2/N)*cos(((2*j-1)*pi*(i-1))/(2*N)); 21 | 22 | endfor 23 | endfor 24 | 25 | % fetch matrix dimensions 26 | [nr,nc] = size(M); 27 | 28 | res = zeros(nr,nc); 29 | 30 | %% 31 | % Apply Inverse DCT 32 | for i=[1:N:nr] 33 | for j=[1:N:nc] 34 | zBLOCK = M(i:i+N-1,j:j+N-1); 35 | win=C'*zBLOCK*C; 36 | res(i:i+N-1,j:j+N-1)=win; 37 | end 38 | end 39 | 40 | endfunction -------------------------------------------------------------------------------- /Image Compression/jpeg.m: -------------------------------------------------------------------------------- 1 | function resimg = jpeg() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray scale only if input image is colormap 10 | % img = rgb2gray(img); 11 | 12 | % get the dimensions of image 13 | [nr,nc] = size(img); 14 | 15 | if mod(nr,8)!=0 16 | 17 | nr = nr - mod(nr,8); 18 | 19 | endif 20 | 21 | if mod(nc,8)!=0 22 | 23 | nc = nc - mod(nc,8); 24 | 25 | endif 26 | 27 | img1=img; 28 | 29 | % trim the edges if not multiple of 8 30 | impadded(1:nr,1:nc) = double(img(1:nr,1:nc)); 31 | img = impadded; 32 | 33 | 34 | % fetch the image dimensions 35 | [nr, nc]= size(img); 36 | 37 | % convert image type to double 38 | img = double(img); 39 | 40 | % Subtracting each image pixel value by 128 41 | img = img - (128*ones(nr,nc)); 42 | quality = input('What quality of compression you require - '); 43 | 44 | % Quality Matrix Formulation 45 | Q50 = [ 16 11 10 16 24 40 51 61; 46 | 12 12 14 19 26 58 60 55; 47 | 14 13 16 24 40 57 69 56; 48 | 14 17 22 29 51 87 80 62; 49 | 18 22 37 56 68 109 103 77; 50 | 24 35 55 64 81 104 113 92; 51 | 49 64 78 87 103 121 120 101; 52 | 72 92 95 98 112 100 103 99]; 53 | 54 | if quality > 50 55 | QX = round(Q50.*(ones(8)*((100-quality)/50))); 56 | QX = uint8(QX); 57 | elseif quality < 50 58 | QX = round(Q50.*(ones(8)*(50/quality))); 59 | QX = uint8(QX); 60 | elseif quality == 50 61 | QX = Q50; 62 | end 63 | 64 | 65 | % initialize the size of cosine matrix N 66 | 67 | N = 8 68 | 69 | % generate cosine matrix 70 | DCT_matrix8 = zeros(N,N); 71 | 72 | for i = 1:N 73 | 74 | DCT_matrix8(1,i) = sqrt(1/N); 75 | 76 | endfor 77 | 78 | for i = 2:N 79 | for j = 1:N 80 | 81 | DCT_matrix8(i,j) = sqrt(2/N)*cos(((2*j-1)*pi*(i-1))/(2*N)); 82 | 83 | endfor 84 | endfor 85 | 86 | % calculate inverse DCT 87 | iDCT_matrix8 = DCT_matrix8'; %inv(DCT_matrix8); 88 | 89 | % Jpeg Compression 90 | dct_restored = zeros(nr,nc); 91 | QX = double(QX); 92 | 93 | %% 94 | % Jpeg Encoding 95 | % 96 | % Forward Discret Cosine Transform 97 | for i1=[1:8:nr] 98 | for i2=[1:8:nc] 99 | zBLOCK=img(i1:i1+7,i2:i2+7); 100 | win1=DCT_matrix8*zBLOCK*iDCT_matrix8; 101 | dct_domain(i1:i1+7,i2:i2+7)=win1; 102 | end 103 | end 104 | % 105 | % Quantization of the DCT coefficients 106 | for i1=[1:8:nr] 107 | for i2=[1:8:nc] 108 | win1 = dct_domain(i1:i1+7,i2:i2+7); 109 | win2=round(win1./QX); 110 | dct_quantized(i1:i1+7,i2:i2+7)=win2; 111 | end 112 | end 113 | 114 | %% 115 | % Jpeg Decoding 116 | % 117 | % Dequantization of DCT Coefficients 118 | for i1=[1:8:nr] 119 | for i2=[1:8:nc] 120 | win2 = dct_quantized(i1:i1+7,i2:i2+7); 121 | win3 = win2.*QX; 122 | dct_dequantized(i1:i1+7,i2:i2+7) = win3; 123 | end 124 | end 125 | % 126 | % Inverse DISCRETE COSINE TRANSFORM 127 | for i1=[1:8:nr] 128 | for i2=[1:8:nc] 129 | win3 = dct_dequantized(i1:i1+7,i2:i2+7); 130 | win4=iDCT_matrix8*win3*DCT_matrix8; 131 | dct_restored(i1:i1+7,i2:i2+7)=win4; 132 | end 133 | end 134 | resimg=dct_restored; 135 | 136 | % conversion of image matrix to uint8 image 137 | resimg=mat2gray(resimg); 138 | 139 | 140 | % display of results 141 | subplot(1,2,1),imshow(img1); 142 | title('Original image','FontSize',18); 143 | 144 | subplot(1,2,2),imshow(resimg); 145 | title('Compressed Image','FontSize',18); 146 | 147 | endfunction -------------------------------------------------------------------------------- /Image Enhancement/Smoothing Filters/Avg_Weighted_Filter.m: -------------------------------------------------------------------------------- 1 | function new_img = Avg_Weighted_Filter() 2 | 3 | %% 4 | % Linear Smoothing Filter 5 | % 6 | % Average Weighted Filter 7 | % 8 | % Define Odd Mask Size 3,5,7,.... 9 | m_size = 3; 10 | 11 | % replace `PATH_TO_IMAGE` with actual image file path 12 | impath = 'PATH_TO_IMAGE_FILE'; 13 | 14 | % read image 15 | img = imread(impath); 16 | 17 | % Convert BGR image to GRAY Scale Image (optional) 18 | img = rgb2gray(img); 19 | 20 | %% 21 | % Average Weighted Filter Mask 22 | % 23 | % 1 2 1 24 | % 2 4 2 25 | % 1 2 1 26 | % 27 | mask = [1 2 1; 2 4 2; 1 2 1]; 28 | 29 | % Sum Of All The Elements Of Mask 30 | msum = sum(sum(mask)); 31 | 32 | s = m_size/2-0.5; 33 | 34 | % Pad The Given Image 35 | [nr,nc]=size(img); 36 | padded_img = uint8(zeros(nr+2*s,nc+2*s)); 37 | padded_img((s+1):(nr+s),(s+1):(nc+s)) = img; 38 | 39 | % Plot Result 40 | subplot(1,3,1),imshow(img); 41 | title('Original Gray Image','FontSize',18); 42 | subplot(1,3,2),imshow(padded_img); 43 | title('Padded Image','FontSize',18); 44 | 45 | % Convert uint8 to double 46 | padded_img=double(padded_img); 47 | 48 | % Find Size of Padded Image 49 | [pnr,pnc]=size(padded_img); 50 | 51 | new_img = zeros(nr,nc); 52 | 53 | for i = (1+s):(nr+s) 54 | for j = (1+s):(nc+s) 55 | 56 | % Multiply each value with matrix and Add each value of masked image 57 | new_img(i-s,j-s) = sum(sum(mask.*padded_img(i-s:i+s,j-s:j+s))); 58 | 59 | % Divide result by the sum of mask 60 | new_img(i-s,j-s) = new_img(i-s,j-s)/msum; 61 | 62 | endfor 63 | endfor 64 | 65 | subplot(1,3,3),imshow(uint8(new_img)); 66 | title('Average Weighted Filter','FontSize',18); 67 | 68 | endfunction 69 | -------------------------------------------------------------------------------- /Image Enhancement/Smoothing Filters/Box_Filter.m: -------------------------------------------------------------------------------- 1 | function new_img = Box_Filter() 2 | 3 | %% 4 | % Linear Smoothing Filter 5 | % 6 | % Box Filter 7 | % 8 | % Define Odd Mask Size 3,5,7,.... 9 | m_size = 3; 10 | 11 | % replace `PATH_TO_IMAGE` with actual image file path 12 | impath = 'PATH_TO_IMAGE_FILE'; 13 | 14 | % read image 15 | img = imread(impath); 16 | 17 | % Convert BGR image to GRAY Scale Image (optional) 18 | img = rgb2gray(img); 19 | 20 | %% 21 | % Box Filter Mask 22 | % 23 | % 1 1 1 24 | % 1 1 1 25 | % 1 1 1 26 | % 27 | mask = ones(m_size); 28 | 29 | % Sum Of All The Elements Of Mask 30 | msum = sum(sum(mask)); 31 | 32 | s = m_size/2-0.5; 33 | 34 | % Pad The Given Image 35 | [nr,nc]=size(img); 36 | padded_img = uint8(zeros(nr+2*s,nc+2*s)); 37 | padded_img((s+1):(nr+s),(s+1):(nc+s)) = img; 38 | 39 | % Plot Result 40 | subplot(1,3,1),imshow(img); 41 | title('Original Gray Image','FontSize',18); 42 | subplot(1,3,2),imshow(padded_img); 43 | title('Padded Image','FontSize',18); 44 | 45 | % Convert uint8 to double 46 | padded_img=double(padded_img); 47 | 48 | % Find Size of Padded Image 49 | [pnr,pnc]=size(padded_img); 50 | 51 | new_img = zeros(nr,nc); 52 | 53 | for i = (1+s):(nr+s) 54 | for j = (1+s):(nc+s) 55 | 56 | % Add each value of masked image 57 | new_img(i-s,j-s) = sum(sum(mask.*padded_img(i-s:i+s,j-s:j+s))); 58 | 59 | % Divide result by the sum of mask 60 | new_img(i-s,j-s) = new_img(i-s,j-s)/msum; 61 | 62 | endfor 63 | endfor 64 | 65 | subplot(1,3,3),imshow(uint8(new_img)); 66 | title('Box Filter','FontSize',18); 67 | 68 | endfunction 69 | -------------------------------------------------------------------------------- /Image Enhancement/Smoothing Filters/Max_Filter.m: -------------------------------------------------------------------------------- 1 | function new_img = Max_Filter() 2 | 3 | %% 4 | % Non Linear Smoothing Filter 5 | % 6 | % Max Filter 7 | % 8 | % Define Odd Mask Size 3,5,7,.... 9 | m_size = 3; 10 | 11 | % replace `PATH_TO_IMAGE_FILE` with actual image file path 12 | impath = 'PATH_TO_IMAGE_FILE'; 13 | 14 | % read image 15 | img = imread(impath); 16 | 17 | % Convert BGR image to GRAY Scale Image (optional) 18 | img = rgb2gray(img); 19 | 20 | s = m_size/2-0.5; 21 | 22 | % Pad The Given Image 23 | [nr,nc]=size(img); 24 | padded_img = uint8(zeros(nr+2*s,nc+2*s)); 25 | padded_img((s+1):(nr+s),(s+1):(nc+s)) = img; 26 | 27 | % Plot Result 28 | subplot(1,3,1),imshow(img); 29 | title('Original Gray Image','FontSize',18); 30 | subplot(1,3,2),imshow(padded_img); 31 | title('Padded Image','FontSize',18); 32 | 33 | % Convert uint8 to double 34 | padded_img=double(padded_img); 35 | 36 | % Find Size of Padded Image 37 | [pnr,pnc]=size(padded_img); 38 | 39 | new_img = zeros(nr,nc); 40 | 41 | for i = (1+s):(nr+s) 42 | for j = (1+s):(nc+s) 43 | 44 | new_img(i-s,j-s) = max(max(padded_img(i-s:i+s,j-s:j+s))); 45 | 46 | endfor 47 | endfor 48 | 49 | subplot(1,3,3),imshow(uint8(new_img)); 50 | title('Max Filter','FontSize',18); 51 | 52 | endfunction 53 | -------------------------------------------------------------------------------- /Image Enhancement/Smoothing Filters/Median_Filter.m: -------------------------------------------------------------------------------- 1 | function new_img = Median_Filter() 2 | 3 | %% 4 | % Non Linear Smoothing Filter 5 | % 6 | % Median Filter 7 | % 8 | % Define Odd Mask Size 3,5,7,.... 9 | m_size = 3; 10 | 11 | % replace `PATH_TO_IMAGE_FILE` with actual image file path 12 | impath = 'PATH_TO_IMAGE_FILE'; 13 | 14 | % read image 15 | img = imread(impath); 16 | 17 | % Convert BGR image to GRAY Scale Image (optional) 18 | img = rgb2gray(img); 19 | 20 | s = m_size/2-0.5; 21 | 22 | % Pad The Given Image 23 | [nr,nc]=size(img); 24 | padded_img = uint8(zeros(nr+2*s,nc+2*s)); 25 | padded_img((s+1):(nr+s),(s+1):(nc+s)) = img; 26 | 27 | % Plot Result 28 | subplot(1,3,1),imshow(img); 29 | title('Original Gray Image','FontSize',18); 30 | subplot(1,3,2),imshow(padded_img); 31 | title('Padded Image','FontSize',18); 32 | 33 | % Convert uint8 to double 34 | padded_img=double(padded_img); 35 | 36 | % Find Size of Padded Image 37 | [pnr,pnc]=size(padded_img); 38 | 39 | new_img = zeros(nr,nc); 40 | 41 | for i = (1+s):(nr+s) 42 | for j = (1+s):(nc+s) 43 | 44 | new_img(i-s,j-s) = median(median(padded_img(i-s:i+s,j-s:j+s))); 45 | 46 | endfor 47 | endfor 48 | 49 | subplot(1,3,3),imshow(uint8(new_img)); 50 | title('Median Filter','FontSize',18); 51 | 52 | endfunction 53 | -------------------------------------------------------------------------------- /Image Enhancement/Smoothing Filters/Min_Filter.m: -------------------------------------------------------------------------------- 1 | function new_img = Min_Filter() 2 | 3 | %% 4 | % Non Linear Smoothing Filter 5 | % 6 | % Min Filter 7 | % 8 | % Define Odd Mask Size 3,5,7,.... 9 | m_size = 3; 10 | 11 | % replace `PATH_TO_IMAGE_FILE` with actual image file path 12 | impath = 'PATH_TO_IMAGE_FILE'; 13 | 14 | % read image 15 | img = imread(impath); 16 | 17 | % Convert BGR image to GRAY Scale Image (optional) 18 | img = rgb2gray(img); 19 | 20 | s = m_size/2-0.5; 21 | 22 | % Pad The Given Image 23 | [nr,nc]=size(img); 24 | padded_img = uint8(zeros(nr+2*s,nc+2*s)); 25 | padded_img((s+1):(nr+s),(s+1):(nc+s)) = img; 26 | 27 | % Plot Result 28 | subplot(1,3,1),imshow(img); 29 | title('Original Gray Image','FontSize',18); 30 | subplot(1,3,2),imshow(padded_img); 31 | title('Padded Image','FontSize',18); 32 | 33 | % Convert uint8 to double 34 | padded_img=double(padded_img); 35 | 36 | % Find Size of Padded Image 37 | [pnr,pnc]=size(padded_img); 38 | 39 | new_img = zeros(nr,nc); 40 | 41 | for i = (1+s):(nr+s) 42 | for j = (1+s):(nc+s) 43 | 44 | new_img(i-s,j-s) = min(min(padded_img(i-s:i+s,j-s:j+s))); 45 | 46 | endfor 47 | endfor 48 | 49 | subplot(1,3,3),imshow(uint8(new_img)); 50 | title('Min Filter','FontSize',18); 51 | 52 | endfunction 53 | -------------------------------------------------------------------------------- /Image Enhancement/contrast_stretching.m: -------------------------------------------------------------------------------- 1 | function [] = contrast_streching() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file path 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % find the min. value of pixel in the image 10 | rmin = min(min(img)); 11 | 12 | % find the max. value of pixel in the image 13 | rmax = max(max(img)); 14 | 15 | % find the slope of line joining point (rmin,0) to (rmax,255) 16 | % slope = (y2 - y1) / (x2 - x1) ; where (x1,y1) and (x2,y2) are two points on line 17 | m = 255/(rmax - rmin); 18 | 19 | % find the intercept of the straight line with the axis 20 | c = 255 - m*rmax; 21 | 22 | % transform the image according to new slope 23 | i_new = m*img + c; 24 | 25 | % plot the results 26 | subplot(1,2,1),imshow(img); % display original gray image 27 | title('Gray Image','FontSize',20); 28 | subplot(1,2,2),imshow(i_new); % display transformed image 29 | title('Transformed Gray Image','FontSize',20); 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /Image Enhancement/gray_level_slicing.m: -------------------------------------------------------------------------------- 1 | function [res1,res2] = gray_level_slicing() 2 | 3 | %% 4 | % There are two approaches for gray level slicing 5 | % 6 | % 1. Display high value of all gray level in desired intensity range and rest to low value. 7 | % 8 | % 2. Display high value of all gray level in desired intensity range and rest to as it is. 9 | % 10 | 11 | % replace `PATH_TO_IMAGE` with actual image file path 12 | impath = 'PATH_TO_IMAGE'; 13 | 14 | % read image 15 | img = imread(impath); 16 | 17 | % fetch the dimension of the image 18 | [nr,nc] = size(img); 19 | 20 | res1 = img; 21 | res2 = img; 22 | 23 | % Desired Range Lower Limit [rl] And Upper Limit [rh] 24 | rl = uint8(60); % change the lower limit of range from here 25 | rh = uint8(100); % change the upper limit of range from here 26 | 27 | % Resultant Low value [ansl] And High value [ansh] 28 | ansh = uint8(200); 29 | ansl = uint8(40); 30 | 31 | for i = 1:nr 32 | for j = 1:nc 33 | 34 | if img(i,j)<=rh && img(i,j)>=rl 35 | 36 | res1(i,j) = ansh; 37 | res2(i,j) = ansh; 38 | 39 | else 40 | 41 | res1(i,j) = ansl; 42 | 43 | endif 44 | 45 | endfor 46 | endfor 47 | 48 | % plot the results 49 | subplot(1,3,1),imshow(img); 50 | title('Original Gray Image','FontSize',20); 51 | subplot(1,3,2),imshow(res1); 52 | title('Approach 1 Gray Image','FontSize',20); 53 | subplot(1,3,3),imshow(res2); 54 | title('Approach 2 Gray Image','FontSize',20); 55 | 56 | endfunction 57 | -------------------------------------------------------------------------------- /Image Representation/signature_plotting.m: -------------------------------------------------------------------------------- 1 | function res = signature_plotting() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | size(img) 9 | 10 | % convert image to BW image 11 | img = im2bw(img); 12 | 13 | % detect boundaries 14 | [B,L,N] = bwboundaries(img); 15 | 16 | % display the image 17 | imshow(img); 18 | 19 | % find all the conected components and mark them 20 | for cnt = 1:N 21 | hold on; 22 | boundary = B{cnt}; 23 | plot(boundary(:,2), boundary(:,1),'r'); 24 | hold on; 25 | text(mean(boundary(:,2)), mean(boundary(:,1)),num2str(cnt)); 26 | end 27 | figure; 28 | subplotrow = ceil(sqrt(N)); 29 | 30 | % plot signatures for each connected components 31 | for cnt = 1:N 32 | boundary = B{cnt}; 33 | 34 | % calculate distance and angle for the boundary of component from its centriod 35 | [th, r]=cart2pol(boundary(:,2)-mean(boundary(:,2)),boundary(:,1)-mean(boundary(:,1))); 36 | 37 | % plot the signatures 38 | subplot(subplotrow,N/subplotrow,cnt); 39 | plot(th,r,'.'); 40 | 41 | % adjust axis according to the angle and radius you want 42 | axis([-pi pi 0 500]); 43 | 44 | % give label to axis 45 | xlabel('radian');ylabel('r'); 46 | 47 | % give title to plot 48 | title(['Object ', num2str(cnt)]); 49 | 50 | end 51 | 52 | endfunction -------------------------------------------------------------------------------- /Image Restoration/arithmetic_mean_filter.m: -------------------------------------------------------------------------------- 1 | function resimg = arithmetic_mean_filter() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray scale only if input image is colormap 10 | % img = rgb2gray(img); 11 | 12 | % create 5 x 5 mask 13 | mask = ones(5,5) / 25; 14 | 15 | % apply filter on image 16 | resimg = imfilter(img,mask); 17 | 18 | % display results 19 | subplot(1,2,1),imshow(img); 20 | title('Original Image','FontSize',18); 21 | 22 | subplot(1,2,2),imshow(resimg); 23 | title('After applying Arithmetic Mean Filter','FontSize',18); 24 | 25 | endfunction -------------------------------------------------------------------------------- /Image Restoration/geometric_mean_filter.m: -------------------------------------------------------------------------------- 1 | function resimg = geometric_mean_filter() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray scale only if input image is colormap 10 | % img = rgb2gray(img); 11 | 12 | % convert image from uint8 to double 13 | imdouble = double(img); 14 | 15 | % get image dimensions 16 | [nr,nc] = size(img); 17 | 18 | resimg(1,:) = imdouble(1,:); 19 | resimg(1:nr,1) = imdouble(1:nr,1); 20 | resimg(nr,:) = imdouble(nr,:); 21 | resimg(1:nr,nc) = imdouble(1:nr,nc); 22 | 23 | % apply filter on image 24 | for i = 2:(nr-1) 25 | for j = 2:(nc-1) 26 | 27 | resimg(i,j) = (imdouble(i-1,j-1)*imdouble(i-1,j)*imdouble(i-1,j+1)*imdouble(i,j-1)*imdouble(i,j)*imdouble(i,j+1)*imdouble(i+1,j-1)*imdouble(i+1,j)*imdouble(i+1,j+1))^(1/9); 28 | 29 | endfor 30 | endfor 31 | 32 | 33 | % convert result image from double to uint8 34 | resimg = uint8(resimg); 35 | 36 | % display results 37 | subplot(1,2,1),imshow(img); 38 | title('Original Image','FontSize',18); 39 | 40 | subplot(1,2,2),imshow(resimg); 41 | title('After applying Geometric Mean Filter','FontSize',18); 42 | 43 | endfunction -------------------------------------------------------------------------------- /Image Restoration/harmonic_mean_filter.m: -------------------------------------------------------------------------------- 1 | function resimg = harmonic_mean_filter() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray scale only if input image is colormap 10 | % img = rgb2gray(img); 11 | 12 | % convert image from uint8 to double 13 | imdouble = double(img); 14 | 15 | % get image dimensions 16 | [nr,nc] = size(img); 17 | 18 | resimg(1,:) = imdouble(1,:); 19 | resimg(1:nr,1) = imdouble(1:nr,1); 20 | resimg(nr,:) = imdouble(nr,:); 21 | resimg(1:nr,nc) = imdouble(1:nr,nc); 22 | 23 | % apply filter on image 24 | for i = 2:(nr-1) 25 | for j = 2:(nc-1) 26 | 27 | resimg(i,j) = 9/((1/(imdouble(i-1,j-1)+1))+(1/(imdouble(i-1,j)+1))+(1/(imdouble(i-1,j+1)+1))+(1/(imdouble(i,j-1)+1))+(1/(imdouble(i,j)+1))+(1/(imdouble(i,j+1)+1))+(1/(imdouble(i+1,j-1)+1))+(1/(imdouble(i+1,j)+1))+(1/(imdouble(i+1,j+1)+1))); 28 | 29 | endfor 30 | endfor 31 | 32 | 33 | % convert result image from double to uint8 34 | resimg = uint8(resimg); 35 | 36 | % display results 37 | subplot(1,2,1),imshow(img); 38 | title('Original Image','FontSize',18); 39 | 40 | subplot(1,2,2),imshow(resimg); 41 | title('After applying Harmonic Mean Filter','FontSize',18); 42 | 43 | endfunction -------------------------------------------------------------------------------- /Image Restoration/noise_detection_using_histogram.m: -------------------------------------------------------------------------------- 1 | function resimg = noise_detection_using_histogram() 2 | 3 | %% 4 | % 5 | % GAUSSIAN NOISE 6 | % 7 | % path for image file which has gaussian noise 8 | impath = 'images/input images/e20.tif'; 9 | 10 | % read image 11 | img = imread(impath); 12 | 13 | subplot(2,6,3),imshow(img); 14 | title('Gaussian Noise','FontSize',18); 15 | 16 | % plot histogram for the input image 17 | subplot(2,6,9),imhist(img); 18 | 19 | %% 20 | % 21 | % RAYLEIGH NOISE 22 | % 23 | % path for image file which has rayleigh noise 24 | impath = 'images/input images/e21.tif'; 25 | 26 | % read image 27 | img = imread(impath); 28 | 29 | subplot(2,6,4),imshow(img); 30 | title('Rayleigh Noise','FontSize',18); 31 | 32 | % plot histogram for the input image 33 | subplot(2,6,10),imhist(img); 34 | 35 | %% 36 | % 37 | % GAMMA NOISE 38 | % 39 | % path for image file which has gamma noise 40 | impath = 'images/e22.tif'; 41 | 42 | % read image 43 | img = imread(impath); 44 | 45 | subplot(2,6,2),imshow(img); 46 | title('Gamma Noise','FontSize',18); 47 | 48 | % plot histogram for the input image 49 | subplot(2,6,8),imhist(img); 50 | 51 | %% 52 | % 53 | % EXPONENTIAL NOISE 54 | % 55 | % path for image file which has exponential noise 56 | impath = 'images/input images/e23.tif'; 57 | 58 | % read image 59 | img = imread(impath); 60 | 61 | subplot(2,6,6),imshow(img); 62 | title('Exponential Noise','FontSize',18); 63 | 64 | % plot histogram for the input image 65 | subplot(2,6,12),imhist(img); 66 | 67 | %% 68 | % 69 | % UNIFORM NOISE 70 | % 71 | % path for image file which has uniform noise 72 | impath = 'images/input images/e24.tif'; 73 | 74 | % read image 75 | img = imread(impath); 76 | 77 | subplot(2,6,1),imshow(img); 78 | title('Uniform Noise','FontSize',18); 79 | 80 | % plot histogram for the input image 81 | subplot(2,6,7),imhist(img); 82 | 83 | %% 84 | % 85 | % IMPULSE NOISE 86 | % 87 | % path for image file which has impluse noise 88 | impath = 'images/input images/e25.tif'; 89 | 90 | % read image 91 | img = imread(impath); 92 | 93 | subplot(2,6,5),imshow(img); 94 | title('Impulse Noise','FontSize',18); 95 | 96 | % plot histogram for the input image 97 | subplot(2,6,11),imhist(img); 98 | 99 | endfunction -------------------------------------------------------------------------------- /Image Restoration/remove_gusssian_noise.m: -------------------------------------------------------------------------------- 1 | function resimg = remove_gusssian_noise() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray scale only if input image is colormap 10 | % img = rgb2gray(img); 11 | 12 | subplot(1,3,1),imshow(img); 13 | title('Image with Gaussian Noise','FontSize',18); 14 | 15 | % plot histogram for the input image 16 | subplot(1,3,2),imhist(img); 17 | title('Histogram','FontSize',18); 18 | 19 | % remove guassian noise using guassian filter 20 | h=fspecial('gaussian',13,.9); 21 | resimg=imfilter(img,h,'conv'); 22 | 23 | % plot the results 24 | subplot(1,3,3),imshow(resimg); 25 | title('After removing Gaussian Noise','FontSize',18); 26 | 27 | endfunction -------------------------------------------------------------------------------- /Image Restoration/remove_uniform_noise.m: -------------------------------------------------------------------------------- 1 | function resimg = remove_uniform_noise() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to gray scale only if input image is colormap 10 | % img = rgb2gray(img); 11 | 12 | subplot(1,3,1),imshow(img); 13 | title('Image with Uniform Noise','FontSize',18); 14 | 15 | % plot histogram for the input image 16 | subplot(1,3,2),imhist(img); 17 | title('Histogram','FontSize',18); 18 | 19 | % remove uniform noise using arithmetic mean filter 20 | % create 5 x 5 mask 21 | mask = ones(5,5) / 25; 22 | 23 | % apply filter on image 24 | resimg = imfilter(img,mask); 25 | 26 | % plot the results 27 | subplot(1,3,3),imshow(resimg); 28 | title('After removing Uniform Noise','FontSize',18); 29 | 30 | endfunction -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Kevin Patel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Morphological Operations/Create_your_bw_image.m: -------------------------------------------------------------------------------- 1 | function img = Create_your_bw_image() 2 | 3 | % create your own B & W image 4 | 5 | % create black square of 400px 6 | img = zeros(400); 7 | 8 | % create white square of 301px inside previous square 9 | img(50:350,50:350) = ones(301); 10 | 11 | % create black square of 201px inside previous square 12 | img(100:300,100:300) = zeros(201); 13 | 14 | % create white square of 101px inside previous square 15 | img(150:250,150:250) = ones(101); 16 | 17 | % save image with name myImage.jpg 18 | imwrite(img,'myImage.jpg'); 19 | 20 | % show image 21 | imshow(img); 22 | title('Created B & W Image','FontSize',18); 23 | 24 | endfunction 25 | -------------------------------------------------------------------------------- /Morphological Operations/boundary_extraction.m: -------------------------------------------------------------------------------- 1 | function resimg = boundary_extraction(impath) 2 | 3 | % read image 4 | img = imread(impath); 5 | 6 | % convert to grayscale 7 | % img = rgb2gray(img); 8 | 9 | % create structuring element 10 | % visit https://in.mathworks.com/help/images/ref/strel.html for more information on structig element 11 | se = strel('square',10); % create square structuring element of 10px x 10px side length 12 | 13 | % matlab function imerode 14 | temp = imerode(img,se); 15 | 16 | % subtract original image from the eroded image 17 | resimg = imsubtract(img,temp); 18 | 19 | % plot results 20 | subplot(1,2,1),imshow(img); 21 | title('Original Gray Image','FontSize',18); 22 | 23 | subplot(1,2,2),imshow(uint8(resimg)); 24 | title('Image After Boundary Extraction','FontSize',18); 25 | 26 | endfunction 27 | -------------------------------------------------------------------------------- /Morphological Operations/closing.m: -------------------------------------------------------------------------------- 1 | function resimg = closing(impath) 2 | 3 | %% 4 | % Can also try MATLAB in-built function imclose() instead of following 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert to grayscale 10 | % img = rgb2gray(img); 11 | 12 | % create circle structuring element 13 | % visit https://in.mathworks.com/help/images/ref/strel.html for more information on structig element 14 | se = strel('disk',10,0); 15 | 16 | % matlab function imdilate 17 | resimg1 = imdilate(img,se); 18 | 19 | % matlab function imerode 20 | resimg2 = imerode(resimg1,se); 21 | 22 | % plot results 23 | subplot(1,2,1),imshow(img); 24 | title('Original Gray Image','FontSize',18); 25 | 26 | subplot(1,2,2),imshow(resimg2); 27 | title('Image After Closing','FontSize',18); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /Morphological Operations/dilation.m: -------------------------------------------------------------------------------- 1 | function resimg = dilation(impath) 2 | 3 | % read image 4 | img = imread(impath); 5 | 6 | % convert to grayscale only if original image is RGB or Colormap 7 | # img = rgb2gray(img); 8 | 9 | % create structuring element 10 | % visit https://in.mathworks.com/help/images/ref/strel.html for more information on structig element 11 | se = strel('square',10); % create square structuring element of 10px x 10px side length 12 | 13 | % matlab function imdilate 14 | resimg = imdilate(img,se); 15 | 16 | % plot results 17 | subplot(1,2,1),imshow(img); 18 | title('Original Gray Image','FontSize',18); 19 | 20 | subplot(1,2,2),imshow(resimg); 21 | title('Image After Dilation','FontSize',18); 22 | 23 | endfunction 24 | -------------------------------------------------------------------------------- /Morphological Operations/erosion.m: -------------------------------------------------------------------------------- 1 | function resimg = erosion(impath) 2 | 3 | % read image 4 | img = imread(impath); 5 | 6 | % convert to grayscale only if original image is RGB or Colormap 7 | # img = rgb2gray(img); 8 | 9 | % create structuring element 10 | % visit https://in.mathworks.com/help/images/ref/strel.html for more information on structig element 11 | se = strel('square',10); % create square structuring element of 10px x 10px side length 12 | 13 | % matlab function imerode 14 | resimg = imerode(img,se); 15 | 16 | % plot results 17 | subplot(1,2,1),imshow(img); 18 | title('Original Gray Image','FontSize',18); 19 | 20 | subplot(1,2,2),imshow(resimg); 21 | title('Image After Erosion','FontSize',18); 22 | 23 | endfunction 24 | -------------------------------------------------------------------------------- /Morphological Operations/logical_arithmetic_operations.m: -------------------------------------------------------------------------------- 1 | function [] = logical_arithmetic_operations() 2 | 3 | % replace `PATH_TO_IMAGE_FILE` with actual image file path 4 | impath = 'PATH_TO_IMAGE_FILE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert rgb image to grayscale 10 | imgray = rgb2gray(img); 11 | 12 | % get the dimensions of image 13 | [nr,nc] = size(imgray); 14 | 15 | % generate black mask image of the same size of imgray 16 | imgmask = uint8(zeros(nr,nc)); 17 | 18 | % add two white rectangles in place of eyes 19 | % you need to adjust the maskeye size according to your need and imgmask size 20 | maskeye = 255 .* ones(201,251); 21 | 22 | % place the maskeye in correct cordinate where your eyes are located 23 | % create left eye mask 24 | imgmask(700:900,750:1000)= maskeye; 25 | 26 | % create right eye mask 27 | imgmask(700:900,350:600)= maskeye; 28 | 29 | %% 30 | % Logical and Arithmetic Operations 31 | % 32 | % bitwise and 33 | imand = bitand(imgray,imgmask); 34 | % bitwise or 35 | imor = bitor(imgray,imgmask); 36 | % bitwise sum 37 | imsum = uint8(imadd(imgray,imgmask)); 38 | % bitwise sub 39 | imsub = uint8(imsubtract(imgray,imgmask)); 40 | %% 41 | 42 | % display results 43 | subplot(2,3,1),imshow(imgray); 44 | title('My Gray Image','FontSize',18); 45 | subplot(2,3,4),imshow(imgmask); 46 | title('My Mask Image','FontSize',18); 47 | subplot(2,3,2),imshow(imand); 48 | title('AND Image','FontSize',18); 49 | subplot(2,3,5),imshow(imor); 50 | title('OR Image','FontSize',18); 51 | subplot(2,3,3),imshow(imsum); 52 | title('SUM Image','FontSize',18); 53 | subplot(2,3,6),imshow(imsub); 54 | title('SUB Image','FontSize',18); 55 | 56 | endfunction -------------------------------------------------------------------------------- /Morphological Operations/opening.m: -------------------------------------------------------------------------------- 1 | function resimg = opening(impath) 2 | 3 | %% 4 | % Can also try MATLAB in-built function imopen() instead of following 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert to grayscale 10 | % img = rgb2gray(img); 11 | 12 | % create circle structuring element 13 | % visit https://in.mathworks.com/help/images/ref/strel.html for more information on structig element 14 | se = strel('disk',10,0); 15 | 16 | % matlab function imerode 17 | resimg1 = imerode(img,se); 18 | 19 | % matlab function imdilate 20 | resimg2 = imdilate(resimg1,se); 21 | 22 | % plot results 23 | subplot(1,2,1),imshow(img); 24 | title('Original Gray Image','FontSize',18); 25 | 26 | subplot(1,2,2),imshow(resimg2); 27 | title('Image After Opening','FontSize',18); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /Morphological Operations/opening_closing.m: -------------------------------------------------------------------------------- 1 | function resimg = opening_closing(impath) 2 | 3 | % read image 4 | img = imread(impath); 5 | 6 | % convert to grayscale 7 | % img = rgb2gray(img); 8 | 9 | % create circle structuring element 10 | % visit https://in.mathworks.com/help/images/ref/strel.html for more information on structig element 11 | se = strel('disk',1,0); 12 | 13 | % matlab function imerode 14 | resimg1 = imerode(img,se); 15 | 16 | % matlab function imdilate 17 | resimg2 = imdilate(resimg1,se); 18 | 19 | % matlab function imdilate 20 | resimg3 = imdilate(resimg2,se); 21 | 22 | % matlab function imerode 23 | resimg = imerode(resimg3,se); 24 | 25 | % plot results 26 | subplot(1,5,1),imshow(img); 27 | title('Original Gray Image','FontSize',18); 28 | 29 | subplot(1,5,2),imshow(resimg1); 30 | title('Erosion on Previous Image','FontSize',18); 31 | 32 | subplot(1,5,3),imshow(resimg2); 33 | title('Dilation on Previous Image','FontSize',18); 34 | 35 | subplot(1,5,4),imshow(resimg3); 36 | title('Dilation on Previous Image','FontSize',18); 37 | 38 | subplot(1,5,5),imshow(resimg); 39 | title('Erosion on Previous Image','FontSize',18); 40 | 41 | endfunction -------------------------------------------------------------------------------- /Morphological Operations/region_filling.m: -------------------------------------------------------------------------------- 1 | function resimg = region_filling() 2 | 3 | % replace `PATH_TO_IMAGE` with actual image file 4 | impath = 'PATH_TO_IMAGE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % convert image to BW / Binary image 10 | imgbw = im2bw(img); 11 | 12 | % fill the holes present in the image 13 | resimg = imfill(imgbw,'holes'); 14 | 15 | % plot the reults 16 | subplot(1,2,1),imshow(imgbw); 17 | title('BW Image','FontSize',18); 18 | subplot(1,2,2),imshow(resimg); 19 | title('Image after region filling','FontSize',18); 20 | 21 | endfunction -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Digital Image Processing 2 | ------ 3 | 4 | ### What is Digital Image Processing? 5 | An image can be defined as a two demensional function f(x,y), where x and y are spatial coordinates, and amplitude of f at any pair of coordinates (x,y) is known as intensity or gray level of that point. When x,y and amplitude f are all finite, discrete quantities, we call the image as digital image. The field of digital image processing refers to processing of digital image using digitall computers. 6 | 7 | ------ 8 | ### Fundamental Steps in Digital Image Processing: 9 | - Image Aquisition 10 | - [Image Enhancement](https://github.com/KevinPatel04/digital-image-processing/tree/master/Image%20Enhancement) 11 | - [Image Restoration](https://github.com/KevinPatel04/digital-image-processing/tree/master/Image%20Restoration) 12 | - [Color Image Processing](https://github.com/KevinPatel04/digital-image-processing/tree/master/Color%20Image%20Processing) 13 | - Wavelets 14 | - [Compression](https://github.com/KevinPatel04/Digital-Image-Processing/tree/master/Image%20Compression) 15 | - [Morphological Operations](https://github.com/KevinPatel04/digital-image-processing/tree/master/Morphological%20Operations) 16 | - Segmentation 17 | - [Representation and Description](https://github.com/KevinPatel04/digital-image-processing/tree/master/Image%20Representation) 18 | - Recognition 19 | 20 | ------ 21 | 22 | #### VISIT => [MATLAB CHEATSHEETS FOR IMAGE PROCESSING](https://github.com/KevinPatel04/Digital-Image-Processing/wiki/MATLAB-CHEATSHEETS) 23 | 24 | ### Examples 25 | 26 | - Finding Grayscale image, Red Component, Green Component, Blue Component, Negative of given image. 27 | 28 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/1.jpg "RGB2GRAY.m") 29 | 30 | - Plot Histogram for given image. 31 | 32 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/histogram_plot_result.jpg "histogram_plot.m") 33 | 34 | - Perform histogram equalization to transform given low contrast image into high contrast image. 35 | 36 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/2.jpg "histogram_equalization.m") 37 | 38 | - Perform histogram matching: transformation of an image so that its histogram matches a specified output image's histogram. 39 | 40 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/histogram_matching_result.jpg "histogram_matching.m") 41 | 42 | - Gray Level Slicing 43 | 44 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/gray_level_slicing_result.jpg "gray_level_slicing.m") 45 | 46 | - Smoothing Filter 47 | 48 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/smoothing_filter_result.jpg "smoothing filters") 49 | 50 | - Logical and Arithmetic Operations 51 | 52 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/Q10_result.jpg "Arithmetic & Logical Operations") 53 | 54 | - Contrast Streching 55 | 56 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/contrast_streching_result.jpg "contrast_streching.m") 57 | 58 | - Erosion Operation 59 | 60 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/erosion_result.jpg "erosion.m") 61 | 62 | - Dilation Operation 63 | 64 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/dilation_result.jpg "dilation.m") 65 | 66 | - Opening Operation 67 | 68 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/opening_result.jpg "opening.m") 69 | 70 | - Closing Operation 71 | 72 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/closing_result.jpg "closing.m") 73 | 74 | - Fingerprint Enhancement using Opening & Closing Operations 75 | 76 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/opening_closing_result.jpg "opening_closing.m") 77 | 78 | - Boundary Extraction 79 | 80 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/boundary_extraction_result.jpg "boundary_extraction.m") 81 | 82 | - Image Noise 83 | 84 | ![image is not loaded](https://github.com/KevinPatel04/digital-image-processing/blob/master/images/noise_result.png "noise_detection_using_histogram.m") 85 | 86 | - Plotting Signature 87 | 88 | ![image is not loaded](https://github.com/KevinPatel04/Digital-Image-Processing/blob/master/images/signature_output.png "signature_plotting.m") 89 | -------------------------------------------------------------------------------- /getDimensions.m: -------------------------------------------------------------------------------- 1 | function [ nr, nc ] = getDimensions() 2 | 3 | % replace `PATH_TO_IMAGE_FILE` with actual image file path 4 | impath = 'PATH_TO_IMAGE_FILE'; 5 | 6 | % read image 7 | img = imread(impath); 8 | 9 | % get the dimensions of image 10 | % if img is colour image then dimension is vector with 3 elements 11 | % if img is grayscale image then dimension is vector wit 2 dimensions 12 | dimensions = size(img); 13 | 14 | % number of rows 15 | nr = dimensions(1); 16 | 17 | % number of columns 18 | nc = dimensions(2); 19 | 20 | % show image 21 | imshow(img); 22 | 23 | % give title to the image 24 | title(strcat({'This is image with '},num2str(nr),{' X '},num2str(nc))); 25 | 26 | endfunction 27 | -------------------------------------------------------------------------------- /images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/1.jpg -------------------------------------------------------------------------------- /images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/2.jpg -------------------------------------------------------------------------------- /images/Q10_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/Q10_result.jpg -------------------------------------------------------------------------------- /images/boundary_extraction_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/boundary_extraction_result.jpg -------------------------------------------------------------------------------- /images/circle_signature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/circle_signature.png -------------------------------------------------------------------------------- /images/closing_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/closing_result.jpg -------------------------------------------------------------------------------- /images/contrast_streching_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/contrast_streching_result.jpg -------------------------------------------------------------------------------- /images/dilation_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/dilation_result.jpg -------------------------------------------------------------------------------- /images/e7.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/e7.tif -------------------------------------------------------------------------------- /images/eg1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/eg1.jpg -------------------------------------------------------------------------------- /images/erosion_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/erosion_result.jpg -------------------------------------------------------------------------------- /images/gray_level_slicing_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/gray_level_slicing_result.jpg -------------------------------------------------------------------------------- /images/guassian_noise_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/guassian_noise_result.png -------------------------------------------------------------------------------- /images/histogram_matching_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/histogram_matching_result.jpg -------------------------------------------------------------------------------- /images/histogram_plot_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/histogram_plot_result.jpg -------------------------------------------------------------------------------- /images/input images/Fig0316(4)(bottom_left).tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/Fig0316(4)(bottom_left).tif -------------------------------------------------------------------------------- /images/input images/Low-contrast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/Low-contrast.png -------------------------------------------------------------------------------- /images/input images/circle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/circle.jpg -------------------------------------------------------------------------------- /images/input images/circles.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/circles.jpg -------------------------------------------------------------------------------- /images/input images/e14.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e14.tif -------------------------------------------------------------------------------- /images/input images/e15.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e15.tif -------------------------------------------------------------------------------- /images/input images/e16.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e16.tif -------------------------------------------------------------------------------- /images/input images/e17.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e17.tif -------------------------------------------------------------------------------- /images/input images/e18.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e18.tif -------------------------------------------------------------------------------- /images/input images/e19.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e19.tif -------------------------------------------------------------------------------- /images/input images/e20.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e20.tif -------------------------------------------------------------------------------- /images/input images/e21.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e21.tif -------------------------------------------------------------------------------- /images/input images/e22.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e22.tif -------------------------------------------------------------------------------- /images/input images/e23.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e23.tif -------------------------------------------------------------------------------- /images/input images/e24.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e24.tif -------------------------------------------------------------------------------- /images/input images/e25.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e25.tif -------------------------------------------------------------------------------- /images/input images/e26.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e26.tif -------------------------------------------------------------------------------- /images/input images/e27.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e27.tif -------------------------------------------------------------------------------- /images/input images/e28.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e28.tif -------------------------------------------------------------------------------- /images/input images/e29.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e29.tif -------------------------------------------------------------------------------- /images/input images/e3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e3.jpg -------------------------------------------------------------------------------- /images/input images/e30.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e30.tif -------------------------------------------------------------------------------- /images/input images/e7.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e7.tif -------------------------------------------------------------------------------- /images/input images/e8.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/e8.tif -------------------------------------------------------------------------------- /images/input images/eg1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/eg1.jpg -------------------------------------------------------------------------------- /images/input images/kevin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/kevin.jpg -------------------------------------------------------------------------------- /images/input images/letter-j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/letter-j.png -------------------------------------------------------------------------------- /images/input images/myImage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/input images/myImage.jpg -------------------------------------------------------------------------------- /images/log_transformation_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/log_transformation_result.jpg -------------------------------------------------------------------------------- /images/negative_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/negative_result.jpg -------------------------------------------------------------------------------- /images/noise_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/noise_result.png -------------------------------------------------------------------------------- /images/opening_closing_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/opening_closing_result.jpg -------------------------------------------------------------------------------- /images/opening_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/opening_result.jpg -------------------------------------------------------------------------------- /images/power_law_result (2).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/power_law_result (2).jpg -------------------------------------------------------------------------------- /images/region_filling_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/region_filling_result.png -------------------------------------------------------------------------------- /images/signature_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/signature_output.png -------------------------------------------------------------------------------- /images/smoothing_filter_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/smoothing_filter_result.jpg -------------------------------------------------------------------------------- /images/uniform_noise_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinPatel04/Digital-Image-Processing/6963cc237711a9190d22537f6d8b475ff2238ce9/images/uniform_noise_result.png --------------------------------------------------------------------------------