├── Code ├── Resizing_Bilinear_Interpolation.py └── readme.md ├── LICENSE ├── README.md └── Sample Images └── readme.md /Code/Resizing_Bilinear_Interpolation.py: -------------------------------------------------------------------------------- 1 | function [out] = bilinearInterpolation(im, out_dims) 2 | 3 | %// Get some necessary variables first 4 | in_rows = size(im,1); 5 | in_cols = size(im,2); 6 | out_rows = out_dims(1); 7 | out_cols = out_dims(2); 8 | 9 | %// Let S_R = R / R' 10 | S_R = in_rows / out_rows; 11 | %// Let S_C = C / C' 12 | S_C = in_cols / out_cols; 13 | 14 | %// Define grid of co-ordinates in our image 15 | %// Generate (x,y) pairs for each point in our image 16 | [cf, rf] = meshgrid(1 : out_cols, 1 : out_rows); 17 | 18 | %// Let r_f = r'*S_R for r = 1,...,R' 19 | %// Let c_f = c'*S_C for c = 1,...,C' 20 | rf = rf * S_R; 21 | cf = cf * S_C; 22 | 23 | %// Let r = floor(rf) and c = floor(cf) 24 | r = floor(rf); 25 | c = floor(cf); 26 | 27 | %// Any values out of range, cap 28 | r(r < 1) = 1; 29 | c(c < 1) = 1; 30 | r(r > in_rows - 1) = in_rows - 1; 31 | c(c > in_cols - 1) = in_cols - 1; 32 | 33 | %// Let delta_R = rf - r and delta_C = cf - c 34 | delta_R = rf - r; 35 | delta_C = cf - c; 36 | 37 | %// Final line of algorithm 38 | %// Get column major indices for each point we wish 39 | %// to access 40 | in1_ind = sub2ind([in_rows, in_cols], r, c); 41 | in2_ind = sub2ind([in_rows, in_cols], r+1,c); 42 | in3_ind = sub2ind([in_rows, in_cols], r, c+1); 43 | in4_ind = sub2ind([in_rows, in_cols], r+1, c+1); 44 | 45 | %// Now interpolate 46 | %// Go through each channel for the case of colour 47 | %// Create output image that is the same class as input 48 | out = zeros(out_rows, out_cols, size(im, 3)); 49 | out = cast(out, class(im)); 50 | 51 | for idx = 1 : size(im, 3) 52 | chan = double(im(:,:,idx)); %// Get i'th channel 53 | %// Interpolate the channel 54 | tmp = chan(in1_ind).*(1 - delta_R).*(1 - delta_C) + ... 55 | chan(in2_ind).*(delta_R).*(1 - delta_C) + ... 56 | chan(in3_ind).*(1 - delta_R).*(delta_C) + ... 57 | chan(in4_ind).*(delta_R).*(delta_C); 58 | out(:,:,idx) = cast(tmp, class(im)); 59 | end 60 | -------------------------------------------------------------------------------- /Code/readme.md: -------------------------------------------------------------------------------- 1 | ### Jupyter files for all of the code snippets created under this project. 2 | #### The snippets use opencv (cv2), numpy, scipy, matpoltlib for basic operations such as loading and saving the image. 3 | 4 | ## 1. Resizing
5 | There are three ways to resize an image 6 | * Nearest Neighbours 7 | * Bilinear Interpolation 8 | * Bicubic Interpolation 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Avik Jain 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Digital-Image-Processing 2 | Implementations and Notes for Digital Image Processing 3 | 4 | ### 1. Resizing 5 | - Using Bilinear Interpolation 6 | -------------------------------------------------------------------------------- /Sample Images/readme.md: -------------------------------------------------------------------------------- 1 | ### List of all the sample images that are being used in code along with the attributions to the original author 2 | --------------------------------------------------------------------------------