├── Detection_and_correction_of_specular_reflections_Charles_Auguste_2007 ├── imgs │ ├── 1.bmp │ ├── 2.bmp │ ├── 3.bmp │ ├── figure8_1.bmp │ ├── figure8_2.bmp │ ├── figure8_3.bmp │ ├── figure9_1.bmp │ ├── figure9_2.bmp │ ├── figure9_3.bmp │ └── image-0001615.png ├── results │ ├── figure8_1.jpg │ ├── figure9_3.jpg │ ├── figure8_2_theshold150.jpg │ ├── figure8_3_threshold150.jpg │ ├── figure9_1_threshold170.jpg │ └── figure9_2_threshold190.jpg ├── main.m ├── InpaintingCharlesAuguste2007.m └── SpecularDetectionCharlesAuguste2007.m ├── Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010 ├── imgs │ ├── 235.bmp │ ├── fig1_a.bmp │ ├── fig1_c.bmp │ ├── fig3.bmp │ ├── fig4_a.bmp │ ├── fig5.bmp │ ├── fig5_a.bmp │ ├── fig6.bmp │ ├── fig6_a.bmp │ ├── fig6_b.bmp │ ├── fig7_a.bmp │ └── fig7_b.bmp ├── results │ ├── fig5_a.png │ ├── fig6_a.png │ ├── fig6_b.png │ ├── fig7_a.png │ └── fig7_b.png ├── SpecularDetectionArnold2010.m ├── InpainttingArnold2010.m ├── main.m └── filling_image_using_centroid_color.m ├── Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011 ├── imgs │ ├── 1.bmp │ ├── 1.png │ ├── 2.bmp │ ├── 3.bmp │ ├── fig10_a.bmp │ ├── fig10_b.bmp │ └── image-0001615.png ├── results │ ├── fig10_a.jpg │ └── fig10_b.jpg ├── main.m ├── SpecularDetectionMeslouhi2011.m └── lib │ ├── create_image_and_mask.m │ ├── inpainting_harmonic.m │ ├── inpainting_cahn_hilliard.m │ ├── inpainting_amle.m │ ├── inpainting_mumford_shah.m │ └── inpainting_transport.m └── README.md /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/1.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/2.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/3.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/235.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/235.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/1.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/1.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/2.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/3.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig1_a.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig1_a.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig1_c.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig1_c.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig3.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig4_a.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig4_a.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig5.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig5_a.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig5_a.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig6.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig6_a.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig6_a.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig6_b.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig6_b.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig7_a.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig7_a.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig7_b.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/imgs/fig7_b.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig5_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig5_a.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig6_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig6_a.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig6_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig6_b.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig7_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig7_a.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig7_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/results/fig7_b.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/fig10_a.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/fig10_a.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/fig10_b.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/fig10_b.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure8_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure8_1.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure8_2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure8_2.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure8_3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure8_3.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure9_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure9_1.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure9_2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure9_2.bmp -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure9_3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/figure9_3.bmp -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/results/fig10_a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/results/fig10_a.jpg -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/results/fig10_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/results/fig10_b.jpg -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/image-0001615.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/imgs/image-0001615.png -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure8_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure8_1.jpg -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure9_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure9_3.jpg -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/image-0001615.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/imgs/image-0001615.png -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/SpecularDetectionArnold2010.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/SpecularDetectionArnold2010.m -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure8_2_theshold150.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure8_2_theshold150.jpg -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure8_3_threshold150.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure8_3_threshold150.jpg -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure9_1_threshold170.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure9_1_threshold170.jpg -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure9_2_threshold190.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiemojiemo/some_specular_detection_and_inpainting_methods_for_endoscope_image/HEAD/Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/results/figure9_2_threshold190.jpg -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/main.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all; 3 | close all; 4 | 5 | %% Detection 6 | img_path = 'imgs/figure8_1.bmp'; 7 | img = imread(img_path); 8 | specular_mask = SpecularDetectionCharlesAuguste2007(img); 9 | figure;imshow(specular_mask); 10 | 11 | %% Inpaiting 12 | inpaited_img = InpaintingCharlesAuguste2007(img, specular_mask, 0.05); -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/main.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all; 3 | close all; 4 | dbstop if error 5 | 6 | addpath ./lib 7 | 8 | %% Detection 9 | img_path = 'imgs/fig10_b.bmp'; 10 | %img_path = 'imgs/image-0001615.png'; 11 | img = imread(img_path); 12 | specular_mask = SpecularDetectionMeslouhi2011(img); 13 | %dilated_mask = imdilate(specular_mask, strel("diamond", 1)); 14 | imshowpair(img, specular_mask, 'montage'); 15 | 16 | %% Inpaiting 17 | %result = inpainting(img, specular_mask, 0.05); 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | **Unofficial implementation** Run in MATLAB2018b 3 | 4 | + Arnold M, Ghosh A, Ameling S, et al. Automatic segmentation and inpainting of specular highlights for endoscopic imaging[J]. Journal on Image and Video Processing, 2010, 2010: 9. 5 | + Saint-Pierre C A, Boisvert J, Grimard G, et al. Detection and correction of specular reflections for automatic surgical tool segmentation in thoracoscopic images[J]. Machine Vision and Applications, 2011, 22(1): 171-180. 6 | + Meslouhi O, Kardouchi M, Allali H, et al. Automatic detection and inpainting of specular reflections for colposcopic images[J]. Open Computer Science, 2011, 1(3): 341-354. 7 | -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/InpainttingArnold2010.m: -------------------------------------------------------------------------------- 1 | function [inpainted_img] = InpainttingArnold2010(specular_mask,img, decay_win_size, decay_cof) 2 | filled_img = filling_image_using_centroid_color(specular_mask, img); 3 | % gaussian filter 4 | sig = 8; 5 | gaussian_filtered_img = imgaussfilt(filled_img, sig); 6 | 7 | % mask decay (not the paper solution but very similar to it) 8 | mx = imfilter(double(specular_mask), ones(decay_win_size)/decay_cof); 9 | mx = mx + specular_mask; 10 | mx(mx > 1) = 1.0; 11 | inpainted_img = mx.*double(gaussian_filtered_img) + (1-mx).*double(img); 12 | inpainted_img = uint8(inpainted_img); 13 | end 14 | 15 | -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_highlights_Arnold_2010/main.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all; 3 | close all; 4 | 5 | %% detection 6 | img_path = 'imgs/fig6_b.bmp'; 7 | img = imread(img_path); 8 | thresh = graythresh(img); 9 | I2 = im2bw(img, thresh); 10 | 11 | T1 = 240; 12 | T2_abs = 190; 13 | T2_rel = 1.2; 14 | N_min = 3000; 15 | T3 = 5; 16 | specular_mask = SpecularDetectionArnold2010(img, T1, T2_abs, T2_rel, N_min, T3); 17 | specular_mask = specular_mask & I2; % filter the background 18 | figure;imshowpair(img,specular_mask,'montage'); 19 | 20 | %% inpainting 21 | decay_win_size = 10; 22 | decay_cof = 20; 23 | inpainted_img = InpainttingArnold2010(specular_mask, img, decay_win_size, decay_cof); 24 | figure;imshowpair(img,inpainted_img,'montage'); 25 | -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/SpecularDetectionMeslouhi2011.m: -------------------------------------------------------------------------------- 1 | function [specular_mask] = SpecularDetectionMeslouhi2011(img) 2 | 3 | % Step 1 Imange Enhancement 4 | enhanced = ReflectionEnhance(im2double(img)); 5 | % enhanced = im2uint8(enhanced); 6 | % imshow([img enhanced]); 7 | 8 | % Step 2 Convertion to CIE-XYZ and then getting the lunminace(Y) 9 | enhanced_xyz = rgb2xyz(enhanced); 10 | Y = enhanced_xyz(:,:,2); 11 | 12 | % Step 3 Getting chromatic luminance(y) 13 | y = enhanced_xyz(:,:,2)./(enhanced_xyz(:,:,1) + enhanced_xyz(:,:,2) + enhanced_xyz(:,:,3)); 14 | 15 | % Step 3 Getting Mask 16 | specular_mask = Y >= y; 17 | %dilated_mask = imdilate(specular_mask, strel("diamond", 1)); 18 | end 19 | 20 | function [enhanced] = ReflectionEnhance(img) 21 | min_rgb = min(img, [], [3]); 22 | max_rgb = max(img, [], [3]); 23 | s = min_rgb ./ max_rgb; 24 | enhanced = s.*img; 25 | end 26 | 27 | -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/lib/create_image_and_mask.m: -------------------------------------------------------------------------------- 1 | %% Create data to be inpainted 2 | % part of "MATLAB Codes for the Image Inpainting Problem" 3 | % 4 | % Usage: 5 | % [u,mask,input] = create_image_and_mask(imagefilename,maskfilename) 6 | % 7 | % Authors: 8 | % Simone Parisotto (email: sp751 at cam dot ac dot uk) 9 | % Carola-Bibiane Schoenlieb (email: cbs31 at cam dot ac dot uk) 10 | % 11 | % Address: 12 | % Cambridge Image Analysis 13 | % Centre for Mathematical Sciences 14 | % Wilberforce Road 15 | % CB3 0WA, Cambridge, United Kingdom 16 | % 17 | % Date: 18 | % September, 2016 19 | % 20 | % Licence: BSD-3-Clause (https://opensource.org/licenses/BSD-3-Clause) 21 | % 22 | 23 | 24 | function [u,mask,input] = create_image_and_mask(imagefilename,maskfilename) 25 | 26 | % import a clean input to be corrupted with the mask 27 | input = im2double(imread(imagefilename)); 28 | 29 | % import the mask of the inpainting domain 30 | % mask = 1 intact part 31 | % mask = 0 missing domain 32 | mask = double( mat2gray( im2double(imread(maskfilename)) ) == 1 ); 33 | if size(mask,3)==1 && size(input,3)>1 34 | mask = repmat(mask,[1,1,size(input,3)]); 35 | end 36 | 37 | % create the image with the missin domain: 38 | noise = rand(size(input)); 39 | u = mask.*input + (1-mask).*noise; -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/InpaintingCharlesAuguste2007.m: -------------------------------------------------------------------------------- 1 | function [out] = InpaintingCharlesAuguste2007(img, mask, tol,show_inpainting) 2 | if nargin <= 2 3 | tol = 0.05; 4 | show_inpainting = true; 5 | end 6 | 7 | if nargin <= 3 8 | show_inpainting = true; 9 | end 10 | 11 | [nrows ncols nch] = size(img); 12 | % Checking if the image and the mask have the same size. 13 | assert(isequal([nrows ncols], size(mask)),"The image and mask must have the same size"); 14 | % Diffusion kernels. 15 | a = .073235; 16 | b = .176765; 17 | c = .125; 18 | kernel1 = [a b a; b 0 b; a b a]; 19 | kernel2 = [c c c; c 0 c; c c c]; 20 | % Eventual multiple dimensional mask to help some operations with the image's 21 | % roi. 22 | mmask = repmat(mask, [1 1 nch]); 23 | mmask = uint8(mmask); 24 | mmaskIdxs = find(mmask); 25 | % Removing color information of the mask pixels from the image. 26 | out = img .* (1 - mmask); 27 | % Diffusion iteration. 28 | maskDiff = Inf; 29 | 30 | if show_inpainting 31 | figure; 32 | end 33 | 34 | while maskDiff > tol 35 | tempImg = imfilter(out, kernel1, "conv"); 36 | 37 | % Calculating the roi's difference between 2 successive iterations. 38 | % We need to use something bigger than the int8 of the images 39 | % because we need to handle possible negative numbers here. 40 | maskDiff = mean(abs(int16(out(mmaskIdxs)) - int16(tempImg(mmaskIdxs)))); 41 | out(mmaskIdxs) = tempImg(mmaskIdxs); 42 | 43 | if show_inpainting 44 | imshow(out); 45 | end 46 | 47 | end 48 | end -------------------------------------------------------------------------------- /Detection_and_correction_of_specular_reflections_Charles_Auguste_2007/SpecularDetectionCharlesAuguste2007.m: -------------------------------------------------------------------------------- 1 | function [specular_mask] = SpecularDetectionCharlesAuguste2007(img) 2 | 3 | % Step 1: reflection enhancemnt 4 | enhanced = reflection_enhance(im2double(img)); 5 | enhanced = im2uint8(enhanced); 6 | enhanced_gray = rgb2gray(enhanced); 7 | figure;imshow([img enhanced]); 8 | 9 | % Step 2: histogram denoising 10 | denoised_hist = histogram_denoise(enhanced_gray); 11 | 12 | % Step 3: Specular bump thresholding 13 | threshold = find_specular_bump_threshold(denoised_hist); 14 | 15 | % Step 4: Specular lobe detection 16 | specular_mask_rgb = (enhanced_gray >= (threshold)); 17 | %specular_spike_mask = specular_mask_rgb(:,:,1) | specular_mask_rgb(:,:,2) | specular_mask_rgb(:,:,3); 18 | specular_spike_mask = specular_mask_rgb; 19 | 20 | specular_mask = imdilate(specular_spike_mask, strel("diamond", 1)); 21 | 22 | end 23 | 24 | function [enhanced] = reflection_enhance(img) 25 | hsv = rgb2hsv(img); 26 | s = hsv(:,:,2); 27 | enhanced = (1-s).*img; 28 | end 29 | 30 | function [denoised_hist] = histogram_denoise(enhanced) 31 | % enhanced is a RGB image and it is double type 32 | 33 | [p, x] = imhist(enhanced); 34 | 35 | lev = 8; 36 | denoised_hist = wdenoise(p, lev, 'DenoisingMethod', 'UniversalThreshold'); 37 | 38 | % figure; 39 | % plot(x, p);hold on; 40 | % plot(x, denoised_hist); 41 | end 42 | 43 | function [threshold] = find_specular_bump_threshold(w) 44 | 45 | w2 = gradient(w); 46 | w2 = thresholding(w2); % gradient of the histgram 47 | 48 | w3 = gradient(w2); 49 | w3 = thresholding(w3); 50 | threshold = find(w3 > 0, 1, 'last'); % threshod is the last positive value 51 | 52 | end 53 | 54 | function [w] = thresholding(w) 55 | w( w <= 0 ) = 0; 56 | w( w > 0 ) = 1; 57 | end 58 | -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/lib/inpainting_harmonic.m: -------------------------------------------------------------------------------- 1 | %% HARMONIC Inpainting 2 | % part of "MATLAB Codes for the Image Inpainting Problem" 3 | % 4 | % Usage: 5 | % u = inpainting_harmonic(u,mask,lambda,tol,maxiter,dt) 6 | % 7 | % Authors: 8 | % Simone Parisotto (email: sp751 at cam dot ac dot uk) 9 | % Carola-Bibiane Schoenlieb (email: cbs31 at cam dot ac dot uk) 10 | % 11 | % Address: 12 | % Cambridge Image Analysis 13 | % Centre for Mathematical Sciences 14 | % Wilberforce Road 15 | % CB3 0WA, Cambridge, United Kingdom 16 | % 17 | % Date: 18 | % September, 2016 19 | % 20 | % Licence: BSD-3-Clause (https://opensource.org/licenses/BSD-3-Clause) 21 | % 22 | 23 | function u = inpainting_harmonic(input,mask,lambda,tol,maxiter,dt) 24 | 25 | [M,N,C] = size(input); 26 | 27 | %% LAPLACIAN 28 | % GRID INTERVAL FOR AXIS ij 29 | h1 = 1; h2 = 1; 30 | 31 | d2i = toeplitz(sparse([1,1],[1,2],[-2,1]/h1^2,1,M)); 32 | d2j = toeplitz(sparse([1,1],[1,2],[-2,1]/h2^2,1,N)); 33 | % NEUMANN BOUNDARY CONDITIONS 34 | d2i(1,[1 2]) = [-1 1]/h1; 35 | d2i(end,[end-1 end]) = [1 -1]/h1; 36 | d2j(1,[1 2]) = [-1 1]/h2; 37 | d2j(end,[end-1 end]) = [1 -1]/h2; 38 | % 2D domain LAPLACIAN 39 | L = kron(speye(N),d2i)+kron(d2j,speye(M)); 40 | 41 | %% ------------------------------------------------------------ FREE MEMORY 42 | clear d2i d2j 43 | 44 | %% INPAINTINH ALGORITHM 45 | 46 | % INITIALIZATION 47 | u = input; 48 | f = input; 49 | 50 | % FOR EACH COLOR CHANNEL 51 | for c = 1:C 52 | 53 | for iter = 1:maxiter 54 | 55 | % COMPUTE NEW SOLUTION 56 | laplacian = reshape( L*reshape(u(:,:,c),[],1) ,M,N); 57 | unew = u(:,:,c) + dt*( laplacian + lambda*mask(:,:,c).*(f(:,:,c)-u(:,:,c)) ); 58 | 59 | % COMPUTE EXIT CONDITION 60 | diff = norm(unew(:)-reshape(u(:,:,c),[],1))/norm(unew(:)); 61 | 62 | % UPDATE 63 | u(:,:,c) = unew; 64 | 65 | % TEST EXIT CONDITION 66 | if diff D QuQ + QuQ D, where 60 | % Q is nonsingular, the matrix of eigenvectors of L and D is a diagonal matrix. 61 | % We have to compute QuQ. This we can do in a fast way by using the fft-transform: 62 | 63 | Lambda1 = spdiags(2*(cos(2*(0:M-1)'*pi/M)-1),0,M,M)/h1^2; 64 | Lambda2 = spdiags(2*(cos(2*(0:N-1)'*pi/N)-1),0,N,N)/h2^2; 65 | 66 | Denominator = Lambda1*ones(M,N) + ones(M,N)*Lambda2; 67 | 68 | % Now we can write the above equation in much simpler way and compute the 69 | % solution u_hat 70 | 71 | for c = 1:C 72 | 73 | % Initialization of Fourier transform: 74 | u_hat = fft2(u(:,:,c)); 75 | lu0_hat = fft2(lambda(:,:,c).*u(:,:,c)); 76 | 77 | for it = 1:maxiter 78 | 79 | lu_hat = fft2(lambda(:,:,c).*u(:,:,c)); 80 | Fprime_hat = fft2(2*(2*u(:,:,c).^3-3*u(:,:,c).^2+u(:,:,c))); 81 | 82 | % CH-inpainting 83 | u_hat = (dt*(1+lambda(:,:,c)-Denominator/param.epsilon(2)).*u_hat... 84 | + dt/ep(it)*Denominator.*Fprime_hat... 85 | + dt*(lu0_hat-lu_hat))./(1+lambda(:,:,c)*dt+ep(it)*dt*Denominator.^2-dt*Denominator/param.epsilon(2)); 86 | 87 | u(:,:,c) = real(ifft2(u_hat)); 88 | 89 | end 90 | 91 | end 92 | 93 | %% WRITE IMAGE OUTPUTS 94 | imwrite(u,'./results/cahn_hilliard_output.png') 95 | -------------------------------------------------------------------------------- /Automatic_detection_and_Inpainting_of_specular_reflections_Othmane_2011/lib/inpainting_amle.m: -------------------------------------------------------------------------------- 1 | %% AMLE Inpainting 2 | % part of "MATLAB Codes for the Image Inpainting Problem" 3 | % 4 | % Usage: 5 | % u = inpainting_amle(u,mask,lambda,tol,maxiter,dt) 6 | % 7 | % Authors: 8 | % Simone Parisotto (email: sp751 at cam dot ac dot uk) 9 | % Carola-Bibiane Schoenlieb (email: cbs31 at cam dot ac dot uk) 10 | % 11 | % Address: 12 | % Cambridge Image Analysis 13 | % Centre for Mathematical Sciences 14 | % Wilberforce Road 15 | % CB3 0WA, Cambridge, United Kingdom 16 | % 17 | % Date: 18 | % September, 2016 19 | % 20 | % Licence: BSD-3-Clause (https://opensource.org/licenses/BSD-3-Clause) 21 | % 22 | 23 | function u = inpainting_amle(input,mask,lambda,tol,maxiter,dt) 24 | 25 | [M,N,C] = size(input); 26 | 27 | %% INITIALIZATION OF u with random data in the missed domain 28 | u = input; 29 | 30 | %% GRADIENT 31 | % GRID INTERVAL FOR AXIS ij 32 | h1 = 1; h2 = 1; 33 | 34 | % average upper (u_{i+1,j} - u_{ij})/hx and lower (u_{ij}-u_{i-1,j})/hx 35 | d1i_forward = spdiags([-ones(M,1),ones(M,1)],[0,1],M,M)/h1; 36 | d1i_backward = spdiags([-ones(M,1),ones(M,1)],[-1,0],M,M)/h1; 37 | % average upper (u_{i,j+1} - u_{ij})/hy and lower (u_{ij}-u_{i,j-1})/hy 38 | d1j_forward = spdiags([-ones(N,1),ones(N,1)],[0,1],N,N)/h2; 39 | d1j_backward = spdiags([-ones(N,1),ones(N,1)],[-1,0],N,N)/h2; 40 | 41 | % BACKWARD WITHOUT BOUNDARY CONDITIONS (FORWARD NOT OF INTEREST HERE) 42 | % DD1i_forward = kron(speye(N),d1i_forward); 43 | DD1i_backward = kron(speye(N),d1i_backward); 44 | % DD1j_forward = kron(d1j_forward,speye(M)); 45 | DD1j_backward = kron(d1j_backward,speye(M)); 46 | 47 | % NEUMANN BOUNDARY CONDITION 48 | d1i_forward(end,:) = 0; d1i_backward(1,:) = 0; 49 | d1j_forward(end,:) = 0; d1j_backward(1,:) = 0; 50 | 51 | % FORWARD AND BACKWARD WITH BOUNDARY CONDITIONS 52 | D1i_forward = kron(speye(N),d1i_forward); 53 | D1i_backward = kron(speye(N),d1i_backward); 54 | D1j_forward = kron(d1j_forward,speye(M)); 55 | D1j_backward = kron(d1j_backward,speye(M)); 56 | 57 | % CENTERED WITH BOUNDARY CONDITIONS 58 | D1i_centered = (D1i_forward+D1i_backward)/2; 59 | D1j_centered = (D1j_forward+D1j_backward)/2; 60 | 61 | %% FREE MEMORY 62 | clear d1i_forward d1i_backward d1j_forward d1j_backward 63 | 64 | %% INPAINTING ALGORITHM 65 | % INITIALIZATION 66 | u = u(:); 67 | input = input(:); 68 | mask = mask(:); 69 | v = zeros(M*N,2); 70 | 71 | % ITERATION 72 | for iter = 1:maxiter 73 | ux = D1i_forward*u; % forward differences along i 74 | uy = D1j_forward*u; % forward differences along j 75 | 76 | % second derivatives 77 | uxx = DD1i_backward*ux; 78 | uxy = DD1j_backward*ux; 79 | uyx = DD1i_backward*uy; 80 | uyy = DD1j_backward*uy; 81 | 82 | % create direction field Du/|Du| with central differences 83 | v(:,1) = D1i_centered*u; 84 | v(:,2) = D1j_centered*u; 85 | % normalize the direction field 86 | v = bsxfun(@rdivide,v,sqrt(sum(v.^2,2))); 87 | v(isnan(v)) = 0; 88 | 89 | % CORE ITERATION 90 | unew = u + dt*(uxx.*v(:,1).^2+uyy.*v(:,2).^2 + (uxy+uyx) .* (v(:,1).*v(:,2)) + lambda*mask.*(input-u)); 91 | 92 | % COMPUTE EXIT CONDITION 93 | if ~mod(iter-1,1000) 94 | diff = norm(unew-u)/norm(unew); 95 | end 96 | 97 | % UPDATE 98 | u = unew; 99 | 100 | % TEST EXIT CONDITION 101 | if diff0); 126 | 127 | uxf = matrices.Dif*u(:,c); 128 | uxb = matrices.Dib*u(:,c); 129 | uyf = matrices.Djf*u(:,c); 130 | uyb = matrices.Djb*u(:,c); 131 | 132 | slopelim = betapos .* sqrt(min(uxb,0).^2 + max(uxf,0).^2 + min(uyb,0).^2 + max(uyf,0).^2)... 133 | + (~betapos) .* sqrt(max(uxb,0).^2 + min(uxf,0).^2 + max(uyb,0).^2 + min(uyf,0).^2); 134 | 135 | update = beta .* slopelim; 136 | 137 | % OPTIONAL: 138 | % Nonlinear scaling of the equation proposed by Bertalmio in 139 | % his thesis. It might cause instabilities when choosing dt 140 | % too large. 141 | % signo = sign(update); 142 | % update = signo.*sqrt(sqrt(signo.*update)); 143 | 144 | % UPADTE ONLY PIXELS INSIDE THE INPAINTING DOMAIN (BY MASK) 145 | u(:,c) = u(:,c) + dt * ~channel_mask(:,c).*update; 146 | end 147 | 148 | % param.N steps of anisotropic diffusion 149 | un = anisodiff(u(:,c),dt,param.eps,geps(:,c),param.N,matrices); 150 | 151 | diff = norm(un-u(:,c))/norm(un); 152 | 153 | % UPDATE 154 | u(:,c) = ~channel_mask(:,c).*un + channel_mask(:,c).*u(:,c); 155 | 156 | % TEST EXIT CONDITION 157 | if diff