├── LANCZOS.m ├── LICENSE ├── README.md ├── _config.yml ├── downsc1.asv ├── downsc1.m ├── images ├── per1_orig.png ├── per1_our.png ├── per1_their.png ├── per2_orig.png ├── per2_our.png ├── per2_their.png ├── per3_orig.png ├── per3_our.png ├── per3_their.png ├── per4_orig.png ├── per4_our.png ├── per4_their.png ├── per5_orig.png ├── per5_our.png ├── per5_their.png ├── per6_orig.png ├── per6_our.png ├── per6_their.png ├── result.md └── result_table.html ├── imresample.m ├── lanczosfilter.m ├── new_test.m ├── perceptual.m └── subsampling.m /LANCZOS.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | Img1=imread('mountain.jpeg'); 6 | figure,imshow(Img1),title('Original') 7 | [Height, Width, Depth]=size(Img1); 8 | 9 | if Depth==1 10 | Img2=Img1 11 | else 12 | Img2=Img1(:,:,:); 13 | end 14 | 15 | M=4; 16 | Img3=Img2(1:M:Height,1:M:Width,1:Depth); 17 | % figure,imshow(Img3),title('No prefiltering') 18 | Img4=imresize(Img3,[Height,Width],'bicubic'); 19 | % figure,imshow(Img4),title('Downsample, no prefiltering') 20 | 21 | % APPLYING GAUSSIAN FILTERING 22 | 23 | Img5=imfilter(Img2,fspecial('gaussian',[4,4],1),'symmetric','replicate','conv'); 24 | Img6=Img5(1:M:Height,1:M:Width,1:Depth); 25 | % figure, imshow(Img6),title('After prefiltering') 26 | Img7=imresize(Img6,[Height,Width],'bicubic'); 27 | % figure, imshow(Img7),title('After prefiltering-Upscaled') 28 | 29 | % USING LANCZOS FILTERING 30 | 31 | 32 | Img8=imresize(Img3,1,'lanczos3'); 33 | % figure, imshow(Img8),title('After LANCZOS-Upscaled') 34 | 35 | % RESAMPLING AFTER LANCZOS USING SPLINE 36 | 37 | nimg = imresample([4,4],Im2double(Img8),[1,1],'spline'); 38 | figure, imshow(nimg),title('After LANCZOS-Upscaled-Spline') 39 | 40 | % RESAMPLING USING BICIBIC 41 | 42 | 43 | Img9=imresize(Img8,[Height,Width],'bicubic'); 44 | figure, imshow(Img9),title('After lanczos-bicubic-Upscaled') 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, NAMAN DEEP SINGH 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README # 2 | 3 | This repository has MATLAB implementation of the perceptual based downscaling algorithm. And a fast implementation of the same. Run perceptual.m and tester.m(fast) to see the algorithm in action. 4 | For results open ./images/result.md 5 | ### What is this repository for? ### 6 | 7 | Code for faster Perceptual Based Image downscaling algorithm given by Oztireli et al. { https://graphics.ethz.ch/~cengizo/imageDownscaling.htm } 8 | 9 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /downsc1.asv: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | Img1=imread('barbara.bmp'); 6 | figure,imshow(Img1),title('Original') 7 | [Height, Width, Depth]=size(Img1); 8 | 9 | if Depth==1 10 | Img2=Img1 11 | else 12 | Img2=Img1(:,:,:); 13 | end 14 | 15 | M=4; 16 | Img3=Img2(1:M:Height,1:M:Width,1:Depth); 17 | figure,imshow(Img3),title('No prefiltering') 18 | Img4=imresize(Img3,[Height,Width],'bicubic'); 19 | figure,imshow(Img4),title('Downsample, no prefiltering') 20 | 21 | 22 | Img5=imfilter(Img2,fspecial('gaussian',[16,16],1),'symmetric','replicate','conv'); 23 | Img6=Img5(1:M:Height,1:M:Width,1:Depth); 24 | figure, imshow(Img6),title('After prefiltering') 25 | Img7=imresize(Img6,[Height,Width],'bicubic'); 26 | figure, imshow(Img7),title('After prefiltering-Upscaled') 27 | Img8=imresize(Img3,1:M:Height,1:M:Width,1:Depth,); 28 | figure, imshow(Img8),title('After prefiltering-Upscaled') 29 | % Img8=imadd(Img3,Img6); 30 | % Img9=imresize(Img8,[Height,Width],'bicubic'); 31 | % figure, imshow(Img9),title('After fghghg-Upscaled') -------------------------------------------------------------------------------- /downsc1.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | Img1=imread('barbara.bmp'); 6 | figure,imshow(Img1),title('Original') 7 | [Height, Width, Depth]=size(Img1); 8 | 9 | if Depth==1 10 | Img2=Img1 11 | else 12 | Img2=Img1(:,:,:); 13 | end 14 | 15 | M=4; 16 | Img3=Img2(1:M:Height,1:M:Width,1:Depth); 17 | % figure,imshow(Img3),title('No prefiltering') 18 | Img4=imresize(Img3,[Height,Width],'bicubic'); 19 | % figure,imshow(Img4),title('Downsample, no prefiltering') 20 | 21 | % APPLYING GAUSSIAN FILTERING 22 | 23 | Img5=imfilter(Img2,fspecial('gaussian',[4,4],1),'symmetric','replicate','conv'); 24 | Img6=Img5(1:M:Height,1:M:Width,1:Depth); 25 | % figure, imshow(Img6),title('After prefiltering') 26 | Img7=imresize(Img6,[Height,Width],'bicubic'); 27 | % figure, imshow(Img7),title('After prefiltering-Upscaled') 28 | 29 | % USING LANCZOS FILTERING 30 | 31 | 32 | Img8=imresize(Img3,1,'lanczos3'); 33 | % figure, imshow(Img8),title('After LANCZOS-Upscaled') 34 | 35 | % RESAMPLING AFTER LANCZOS USING SPLINE 36 | 37 | nimg = imresample([4,4],Im2double(Img8),[1,1],'spline'); 38 | figure, imshow(nimg),title('After LANCZOS-Upscaled') 39 | 40 | % RESAMPLING USING BICIBIC 41 | 42 | 43 | Img9=imresize(Img8,[Height,Width],'bicubic'); 44 | figure, imshow(Img9),title('After lanczos-bicubic-Upscaled') 45 | 46 | -------------------------------------------------------------------------------- /images/per1_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per1_orig.png -------------------------------------------------------------------------------- /images/per1_our.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per1_our.png -------------------------------------------------------------------------------- /images/per1_their.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per1_their.png -------------------------------------------------------------------------------- /images/per2_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per2_orig.png -------------------------------------------------------------------------------- /images/per2_our.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per2_our.png -------------------------------------------------------------------------------- /images/per2_their.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per2_their.png -------------------------------------------------------------------------------- /images/per3_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per3_orig.png -------------------------------------------------------------------------------- /images/per3_our.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per3_our.png -------------------------------------------------------------------------------- /images/per3_their.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per3_their.png -------------------------------------------------------------------------------- /images/per4_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per4_orig.png -------------------------------------------------------------------------------- /images/per4_our.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per4_our.png -------------------------------------------------------------------------------- /images/per4_their.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per4_their.png -------------------------------------------------------------------------------- /images/per5_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per5_orig.png -------------------------------------------------------------------------------- /images/per5_our.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per5_our.png -------------------------------------------------------------------------------- /images/per5_their.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per5_their.png -------------------------------------------------------------------------------- /images/per6_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per6_orig.png -------------------------------------------------------------------------------- /images/per6_our.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per6_our.png -------------------------------------------------------------------------------- /images/per6_their.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/per6_their.png -------------------------------------------------------------------------------- /images/result.md: -------------------------------------------------------------------------------- 1 | | Original Image | Perceptual based result | Our code's result | | 2 | | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---- | 3 | | ![Alt text](https://bytebucket.org/nmndeep/downscaling/raw/2ba85d6c07fdb2f4a9a09241b173d7abc07c5fcb/images/per1_orig.png?token=57073ba531d222b69a497c81817ebc5bff43258c) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per1_their.png?token=e1cf1fd37a9c7bf2ff0e6466ba5737ea7185f8c1) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per1_our.png?token=e6391fa9a1f438ec7beea2eb8cd16cf485395323) | | 4 | | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per2_orig.png?token=825239bf50a4890887da382a45035ea1f6cf37ca) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per2_their.png?token=4823d0e96fc47cf22e54f0b4e939bfe536a0c58d) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per2_our.png?token=152ba908c0694eaabceb5dd5eca6ce857148f347) | | 5 | | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per3_orig.png?token=fb549bd4d25e0cd04e5aee1151fa4a6c77c329ce) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per3_their.png?token=335d8b993a8cea09b8dd696f4dee7e8d5c779c2e) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per3_our.png?token=6104e8e78126671177662f120fbc590bae62643a) | | 6 | | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per4_orig.png?token=0e6a1ab93a2955a7862cfa5c863353462cd119b7) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per4_their.png?token=a4b1c5b29507b819ad61d79ee9a512888776293c) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per4_our.png?token=abf4779ed890b5b9b21b30974305e481c5c179b5) | | 7 | | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per5_orig.png?token=fa57266c23bd22c967df26a128890236698479df) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per5_their.png?token=95f3e21a8b3cf818a3aa05bf86de3a351655b71e) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per5_our.png?token=c76e086e8e4557565b0476ece390746a59a30896) | | 8 | | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per6_orig.png?token=5c928106f74a9570868392066e3bcde2e2746375) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per6_their.png?token=7e02f2447ba4da78f1df6de9c4f7849d4148a6b0) | ![alt text](https://bytebucket.org/nmndeep/downscaling/raw/8f1fcdefd4a8e85c00516019bdb7b6638049e771/images/per6_our.png?token=d48f2438d774ea2fdf63171e6e7f82eab1213882) | | -------------------------------------------------------------------------------- /images/result_table.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/images/result_table.html -------------------------------------------------------------------------------- /imresample.m: -------------------------------------------------------------------------------- 1 | function nimg = imresample(oldpixsize,img,newpixsize,intmethod) 2 | % nimg = imresample(oldpixsize,img,newpixsize,intmethod) 3 | % This function resamples the images at the new grid points 4 | % defined by the new pixel sizes. It assumes that intensities are 5 | % defined at the pixel centers 6 | % 7 | % img : original image to be resampled 8 | % nimg : newly sampled image 9 | % oldpixsize : a vector of the form [xpixsize ypixsize] 10 | % for the original image, e.g., [0.5,0.5] 11 | % newpixsize : is a vector of the form [xpixsize ypixsize] 12 | % for the new image, e.g., [0.2,0.2] 13 | % intmethod: same as interp2 14 | % 'nearest' - nearest neighbor 15 | % 'linear' - bilinear 16 | % 'cubic' - bicubic 17 | % 'spline' - spline 18 | % 19 | % Example: 20 | % 21 | % % Create a 2D gaussian function 22 | % H = fspecial('gaussian',[31,31],5); 23 | % Resample it at a smaller pixel size 24 | % NH = imresample([1,1],H,[0.2,0.2],'spline'); 25 | % figure;subplot(211);imshow(H,[]);title('Original'); 26 | % subplot(212);imshow(NH,[]); 27 | % title('Resampled using spline interplolation'); 28 | 29 | % Omer Demirkaya 12/14/2008 30 | 31 | % Find the dimesions of the image 32 | [r,c,z] = size(img); 33 | r = r-1; 34 | c = c-1; 35 | % smaller variable names 36 | ops = oldpixsize; 37 | nps = newpixsize; 38 | ss = ops/2; 39 | nn = nps/2; 40 | % create the meshes for old and new image 41 | [Ox,Oy] = meshgrid(ss(1):ops(1):c*ops(1)+ss(1),... 42 | ss(2):ops(2):r*ops(2)+ss(2)); 43 | 44 | [Nx,Ny] = meshgrid(nn(1):nps(1):c*ops(1)+nn(1),... 45 | nn(2):nps(2):r*ops(2)+nn(2)); 46 | 47 | % create the new image z > 1 for multispectral images (e.g. z = 3 RGB color images) 48 | for i=1:z 49 | nimg(:,:,i) = interp2(Ox,Oy,img(:,:,i),Nx,Ny,intmethod); 50 | end -------------------------------------------------------------------------------- /lanczosfilter.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmndeep/Image-Downscaling/028559fd9d125cd1791d656963145842c02100b9/lanczosfilter.m -------------------------------------------------------------------------------- /new_test.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%% CODE FOR OZITERLII ET AL. [2015] %% 2 | 3 | clc 4 | clear all 5 | close all 6 | 7 | s=4; 8 | Img1=imread('horse.jpg'); 9 | figure,imshow(Img1),title('Original') 10 | [Height, Width, Depth]=size(Img1); 11 | np=4; 12 | 13 | 14 | % % % % % % % % % % % % % % % % % % % % % RED BAND SINGLE CHANNEL %%%% 15 | 16 | I =(Img1(:,:,1)); 17 | avg4 = fspecial('average',[4 4]); 18 | red = conv(I,avg4); 19 | 20 | % display(Result) 21 | L=red(1:s:Height,1:s:Width); 22 | % figure,imshow(L),title('subsample'); 23 | 24 | %%%%%%%%%%%%%%%%%% L2 %%%%%%%%%%%%%% 25 | K1=I.^2; 26 | 27 | red1 = conv(K1,avg4); 28 | L2=red1(1:s:Height,1:s:Width); 29 | % figure,imshow(L),title('L2'); 30 | 31 | %%%%%%%%%%%%%%%%%%%%%%%% M %%%%%%%%%%%%%%%%%% 32 | avnp =fspecial('average',[round(sqrt(np)) round(sqrt(np))]); 33 | M=conv(L,avnp); 34 | % figure,imshow(M),title('M'); 35 | 36 | % % % % % % % % % % % % % % % % % % SL 37 | M2=L.^2; 38 | S4=conv(M2,avnp); 39 | 40 | MM=M.^2; 41 | Sl=S4-(MM); 42 | % figure,imshow(S4),title('Sl'); 43 | 44 | % % % % % % % % % % SH %%%%%%%%%%%%%%%%%%%%%%%%%% 45 | 46 | S7=conv(L2,avnp); 47 | 48 | Sh=S7-(MM); 49 | % figure,imshow(Sh),title('Sh'); 50 | R=(sqrt(double(Sh./Sl))); 51 | e= 0.000001; 52 | for idx = 1:numel(R) 53 | element = R(idx); 54 | if isnan(element) 55 | R(idx)=0; 56 | elseif isreal(element) 57 | R(idx)=element; 58 | elseif element < e 59 | R(idx)=0; 60 | else 61 | R(idx)=0; 62 | end 63 | end 64 | sz=size(M); 65 | I=ones(sz); 66 | I=padarray(I,2); 67 | N=conv(I,avnp); 68 | 69 | P=R.*double(M); 70 | P=padarray(P,2); 71 | 72 | T=conv(P,avnp); 73 | % figure,imshow(T),title('T'); 74 | M=padarray(M,2); 75 | 76 | M=conv(M,avnp); 77 | % figure,imshow(M),title('M'); 78 | R=padarray(R,2); 79 | 80 | R=conv(R,avnp); 81 | % figure,imshow(R),title('R'); 82 | size(R); 83 | L=padarray(L,2); 84 | K=R.*double(L); 85 | % figure,imshow(K),title('K'); 86 | 87 | J=double(M)+double(K)-double(T); 88 | J=uint8(J); 89 | % figure,imshow(J),title('J'); 90 | 91 | D1=double(J)./N; 92 | D1=uint8(D1); 93 | % figure,imshow(D1),title('D1'); 94 | 95 | 96 | % % % % % % % % % % % % % % % % % GREEN BAND SINGLE CHANNEL %%%%%%%%% 97 | 98 | I =(Img1(:,:,2)); 99 | avg4 = fspecial('average',[4 4]); 100 | red = conv(I,avg4); 101 | 102 | % display(Result) 103 | L=red(1:s:Height,1:s:Width); 104 | % figure,imshow(L),title('subsample'); 105 | 106 | %%%%%%%%%%%%%%%%%% L2 %%%%%%%%%%%%%% 107 | K1=I.^2; 108 | 109 | red1 = conv(K1,avg4); 110 | L2=red1(1:s:Height,1:s:Width); 111 | % figure,imshow(L),title('L2'); 112 | 113 | %%%%%%%%%%%%%%%%%%%%%%%% M %%%%%%%%%%%%%%%%%% 114 | avnp =fspecial('average',[2 2]); 115 | M=conv(L,avnp); 116 | % figure,imshow(M),title('M'); 117 | 118 | % % % % % % % % % % % % % % % % % % SL 119 | M2=L.^2; 120 | S4=conv(M2,avnp); 121 | 122 | MM=M.^2; 123 | Sl=S4-(MM); 124 | % figure,imshow(S4),title('Sl'); 125 | 126 | % % % % % % % % % % SH %%%%%%%%%%%%%%%%%%%%%%%%%% 127 | 128 | S7=conv(L2,avnp); 129 | 130 | Sh=S7-(MM); 131 | % figure,imshow(Sh),title('Sh'); 132 | R=(sqrt(double(Sh./Sl))); 133 | e=0.000001; 134 | for idx = 1:numel(R) 135 | element = R(idx); 136 | if isnan(element) 137 | R(idx)=0; 138 | elseif isreal(element) 139 | R(idx)=element; 140 | elseif element < e 141 | R(idx)=0; 142 | else 143 | R(idx)=0; 144 | end 145 | end 146 | sz=size(M); 147 | I=ones(sz); 148 | I=padarray(I,2); 149 | N=conv(I,avnp); 150 | 151 | P=R.*double(M); 152 | P=padarray(P,2); 153 | T=conv(P,avnp); 154 | % figure,imshow(T),title('T'); 155 | M=padarray(M,2); 156 | M=conv(M,avnp); 157 | % figure,imshow(M),title('M'); 158 | 159 | R=padarray(R,2); 160 | R=conv(R,avnp); 161 | % figure,imshow(R),title('R'); 162 | L=padarray(L,2); 163 | K=R.*double(L); 164 | % figure,imshow(K),title('K'); 165 | 166 | J=double(M)+double(K)-double(T); 167 | J=uint8(J); 168 | % figure,imshow(J),title('J'); 169 | 170 | D2=double(J)./N; 171 | D2=uint8(D2); 172 | % figure,imshow(D2),title('D2'); 173 | 174 | 175 | % % % % % % % % % % % BLUE BAND SINGLE CHANNEL %%%%%%%%%% 176 | 177 | I =(Img1(:,:,3)); 178 | avg4 = fspecial('average',[4 4]); 179 | red = conv(I,avg4); 180 | 181 | % display(Result) 182 | L=red(1:s:Height,1:s:Width); 183 | % figure,imshow(L),title('subsample'); 184 | 185 | %%%%%%%%%%%%%%%%%% L2 %%%%%%%%%%%%%% 186 | K1=I.^2; 187 | 188 | red1 = conv(K1,avg4); 189 | L2=red1(1:s:Height,1:s:Width); 190 | % figure,imshow(L),title('L2'); 191 | 192 | %%%%%%%%%%%%%%%%%%%%%%%% M %%%%%%%%%%%%%%%%%% 193 | avnp =fspecial('average',[2 2]); 194 | M=conv(L,avnp); 195 | % figure,imshow(M),title('M'); 196 | 197 | % % % % % % % % % % % % % % % % % % SL 198 | M2=L.^2; 199 | S4=conv(M2,avnp); 200 | 201 | MM=M.^2; 202 | Sl=S4-(MM); 203 | % figure,imshow(S4),title('Sl'); 204 | 205 | % % % % % % % % % % SH %%%%%%%%%%%%%%%%%%%%%%%%%% 206 | 207 | S7=conv(L2,avnp); 208 | 209 | Sh=S7-(MM); 210 | % figure,imshow(Sh),title('Sh'); 211 | R=(sqrt(double(Sh./Sl))); 212 | e=0.000001; 213 | for idx = 1:numel(R) 214 | element = R(idx); 215 | if isnan(element) 216 | R(idx)=0; 217 | elseif isreal(element) 218 | R(idx)=element; 219 | elseif element < e 220 | R(idx)=0; 221 | else 222 | R(idx)=0; 223 | end 224 | end 225 | sk=size(R); 226 | sz=size(M); 227 | I=ones(sz); 228 | I=padarray(I,2); 229 | N=conv(I,avnp); 230 | 231 | P=R.*double(M); 232 | P=padarray(P,2); 233 | T=conv(P,avnp); 234 | % figure,imshow(T),title('T'); 235 | M=padarray(M,2); 236 | M=conv(M,avnp); 237 | % figure,imshow(M),title('M'); 238 | R=padarray(R,2); 239 | 240 | R=conv(R,avnp); 241 | % figure,imshow(R),title('R'); 242 | L=padarray(L,2); 243 | K=R.*double(L); 244 | % figure,imshow(K),title('K'); 245 | 246 | J=double(M)+double(K)-double(T); 247 | J=uint8(J); 248 | % figure,imshow(J),title('J'); 249 | 250 | D3=double(J)./N; 251 | D3=uint8(D3); 252 | % figure,imshow(D3),title('D3'); 253 | DD=cat(3,D1,D2,D3); 254 | figure,imshow(DD),title('Perceptual-Downscaled'); 255 | 256 | -------------------------------------------------------------------------------- /perceptual.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%% CODE FOR OZITERLII ET AL. [2015] %% 2 | 3 | clc 4 | clear all 5 | close all 6 | 7 | s=4; 8 | Img1=imread('per6_orig.png'); 9 | figure,imshow(Img1),title('Original') 10 | [Height, Width, Depth]=size(Img1); 11 | np=2; 12 | 13 | 14 | % % % % % % % % % % % % % % % % % % % % % RED BAND SINGLE CHANNEL %%%% 15 | 16 | I =(Img1(:,:,1)); 17 | avg4 = fspecial('average',[1 1]); 18 | red = imfilter(I,avg4,'conv'); 19 | 20 | % display(Result) 21 | L=subsampling(red,s); 22 | % figure,imshow(L),title('subsample'); 23 | 24 | %%%%%%%%%%%%%%%%%% L2 %%%%%%%%%%%%%% 25 | K1=I.^2; 26 | red1 = imfilter(K1,avg4,'conv'); 27 | L2=subsampling(red1,s); 28 | % figure,imshow(L),title('L2'); 29 | 30 | %%%%%%%%%%%%%%%%%%%%%%%% M %%%%%%%%%%%%%%%%%% 31 | avnp =fspecial('average',[round(sqrt(np)) round(sqrt(np))]); 32 | M=imfilter(L,avnp,'conv'); 33 | % figure,imshow(M),title('M'); 34 | 35 | % % % % % % % % % % % % % % % % % % SL 36 | M2=L.^2; 37 | S4=imfilter(M2,avnp,'conv'); 38 | 39 | MM=M.^2; 40 | Sl=S4-(MM); 41 | % figure,imshow(S4),title('Sl'); 42 | 43 | % % % % % % % % % % SH %%%%%%%%%%%%%%%%%%%%%%%%%% 44 | 45 | S7=imfilter(L2,avnp,'conv'); 46 | 47 | Sh=S7-(MM); 48 | % figure,imshow(Sh),title('Sh'); 49 | R=(sqrt(double(Sh./Sl))); 50 | e= 0.000001; 51 | for idx = 1:numel(R) 52 | element = R(idx); 53 | if isnan(element) 54 | R(idx)=0; 55 | elseif isreal(element) 56 | R(idx)=element; 57 | elseif element < e 58 | R(idx)=0; 59 | else 60 | R(idx)=0; 61 | end 62 | end 63 | sz=size(M); 64 | I=ones(sz); 65 | % I=padarray(I,[1 1],'both'); 66 | N=imfilter(I,avnp,'conv'); 67 | 68 | P=R.*double(M); 69 | % P=padarray(P,[1 1],'both'); 70 | 71 | T=imfilter(P,avnp,'conv'); 72 | % figure,imshow(T),title('T'); 73 | % M=padarray(M,[1 1],'both'); 74 | 75 | M=imfilter(M,avnp,'conv'); 76 | % figure,imshow(M),title('M'); 77 | % R=padarray(R,[1 1],'both'); 78 | 79 | R=imfilter(R,avnp,'conv'); 80 | % figure,imshow(R),title('R'); 81 | size(R); 82 | % L=padarray(L,[1 1],'both'); 83 | K=R.*double(L); 84 | % figure,imshow(K),title('K'); 85 | 86 | J=double(M)+double(K)-double(T); 87 | J=uint8(J); 88 | % figure,imshow(J),title('J'); 89 | 90 | D1=double(J)./N; 91 | D1=uint8(D1); 92 | % figure,imshow(D1),title('D1'); 93 | 94 | 95 | % % % % % % % % % % % % % % % % % GREEN BAND SINGLE CHANNEL %%%%%%%%% 96 | 97 | I =(Img1(:,:,2)); 98 | avg4 = fspecial('average',[1 1]); 99 | red = imfilter(I,avg4,'conv'); 100 | 101 | % display(Result) 102 | L=subsampling(red,s); 103 | % figure,imshow(L),title('subsample'); 104 | 105 | %%%%%%%%%%%%%%%%%% L2 %%%%%%%%%%%%%% 106 | K1=I.^2; 107 | 108 | red1 = imfilter(K1,avg4,'conv'); 109 | L2=subsampling(red1,s); 110 | % figure,imshow(L),title('L2'); 111 | 112 | %%%%%%%%%%%%%%%%%%%%%%%% M %%%%%%%%%%%%%%%%%% 113 | avnp =fspecial('average',[1 1]); 114 | M=imfilter(L,avnp,'conv'); 115 | % figure,imshow(M),title('M'); 116 | 117 | % % % % % % % % % % % % % % % % % % SL 118 | M2=L.^2; 119 | S4=imfilter(M2,avnp,'conv'); 120 | 121 | MM=M.^2; 122 | Sl=S4-(MM); 123 | % figure,imshow(S4),title('Sl'); 124 | 125 | % % % % % % % % % % SH %%%%%%%%%%%%%%%%%%%%%%%%%% 126 | 127 | S7=imfilter(L2,avnp,'conv'); 128 | 129 | Sh=S7-(MM); 130 | % figure,imshow(Sh),title('Sh'); 131 | R=(sqrt(double(Sh./Sl))); 132 | e=0.000001; 133 | for idx = 1:numel(R) 134 | element = R(idx); 135 | if isnan(element) 136 | R(idx)=0; 137 | elseif isreal(element) 138 | R(idx)=element; 139 | elseif element < e 140 | R(idx)=0; 141 | else 142 | R(idx)=0; 143 | end 144 | end 145 | sz=size(M); 146 | I=ones(sz); 147 | % I=padarray(I,[1 1],'both'); 148 | N=imfilter(I,avnp,'conv'); 149 | 150 | P=R.*double(M); 151 | % P=padarray(P,[1 1],'both'); 152 | T=imfilter(P,avnp,'conv'); 153 | % figure,imshow(T),title('T'); 154 | % M=padarray(M,[1 1],'both'); 155 | M=imfilter(M,avnp,'conv'); 156 | % figure,imshow(M),title('M'); 157 | 158 | % R=padarray(R,[1 1],'both'); 159 | R=imfilter(R,avnp,'conv'); 160 | % figure,imshow(R),title('R'); 161 | % L=padarray(L,[1 1],'both'); 162 | K=R.*double(L); 163 | % figure,imshow(K),title('K'); 164 | 165 | J=double(M)+double(K)-double(T); 166 | J=uint8(J); 167 | % figure,imshow(J),title('J'); 168 | 169 | D2=double(J)./N; 170 | D2=uint8(D2); 171 | % figure,imshow(D2),title('D2'); 172 | 173 | 174 | % % % % % % % % % % % BLUE BAND SINGLE CHANNEL %%%%%%%%%% 175 | 176 | I =(Img1(:,:,3)); 177 | avg4 = fspecial('average',[1 1]); 178 | red = imfilter(I,avg4,'conv'); 179 | 180 | % display(Result) 181 | L=subsampling(red,s); 182 | % figure,imshow(L),title('subsample'); 183 | 184 | %%%%%%%%%%%%%%%%%% L2 %%%%%%%%%%%%%% 185 | K1=I.^2; 186 | 187 | red1 = imfilter(K1,avg4,'conv'); 188 | L2=subsampling(red1,s); 189 | % figure,imshow(L),title('L2'); 190 | 191 | %%%%%%%%%%%%%%%%%%%%%%%% M %%%%%%%%%%%%%%%%%% 192 | avnp =fspecial('average',[1 1]); 193 | M=imfilter(L,avnp,'conv'); 194 | % figure,imshow(M),title('M'); 195 | 196 | % % % % % % % % % % % % % % % % % % SL 197 | M2=L.^2; 198 | S4=imfilter(M2,avnp,'conv'); 199 | 200 | MM=M.^2; 201 | Sl=S4-(MM); 202 | % figure,imshow(S4),title('Sl'); 203 | 204 | % % % % % % % % % % SH %%%%%%%%%%%%%%%%%%%%%%%%%% 205 | 206 | S7=imfilter(L2,avnp,'conv'); 207 | 208 | Sh=S7-(MM); 209 | % figure,imshow(Sh),title('Sh'); 210 | R=(sqrt(double(Sh./Sl))); 211 | e=0.000001; 212 | for idx = 1:numel(R) 213 | element = R(idx); 214 | if isnan(element) 215 | R(idx)=0; 216 | elseif isreal(element) 217 | R(idx)=element; 218 | elseif element < e 219 | R(idx)=0; 220 | else 221 | R(idx)=0; 222 | end 223 | end 224 | sk=size(R); 225 | sz=size(M); 226 | I=ones(sz); 227 | % I=padarray(I,[1 1],'both'); 228 | N=imfilter(I,avnp,'conv'); 229 | 230 | P=R.*double(M); 231 | % P=padarray(P,[1 1],'both'); 232 | T=imfilter(P,avnp,'conv'); 233 | % figure,imshow(T),title('T'); 234 | % M=padarray(M,[1 1],'both'); 235 | M=imfilter(M,avnp,'conv'); 236 | % figure,imshow(M),title('M'); 237 | % R=padarray(R,[1 1],'both'); 238 | 239 | R=imfilter(R,avnp,'conv'); 240 | % figure,imshow(R),title('R'); 241 | % L=padarray(L,[1 1],'both'); 242 | K=R.*double(L); 243 | % figure,imshow(K),title('K'); 244 | 245 | J=double(M)+double(K)-double(T); 246 | J=uint8(J); 247 | % figure,imshow(J),title('J'); 248 | 249 | D3=double(J)./N; 250 | D3=uint8(D3); 251 | % figure,imshow(D3),title('D3'); 252 | DD=cat(3,D1,D2,D3); 253 | % folder='\images'; 254 | % imwrite(DD,fullfile(folder,'per6_our.png')); 255 | figure,imshow(DD),title('Perceptual-Downscaled'); 256 | 257 | -------------------------------------------------------------------------------- /subsampling.m: -------------------------------------------------------------------------------- 1 | function output = subsampling(input, n) 2 | % Subsample an image, the image is subsampled 3 | % to avoid distortion due to the subsampling 4 | % Inputs 5 | % input image 6 | % n subsampling 7 | 8 | 9 | % number of arguments check and error msg 10 | error(nargchk(2,2,nargin)); 11 | 12 | input = double(input); 13 | 14 | % create a FIR filter 15 | Hd = zeros(13,13); 16 | Hd(4:10,4:10) = 1; 17 | h = fwind1(Hd, hamming(13), hamming(13)); 18 | 19 | % freq. response of the filter 20 | %figure; freqz2(h); 21 | 22 | % filter the image 23 | im_f = imfilter(input, h, 'symmetric'); 24 | 25 | % subsample the filtered image 26 | output = im_f(1:n:end, 1:n:end); 27 | 28 | --------------------------------------------------------------------------------