Cody

# Problem 667. Image Processing 01: Vignetting Correction

Solution 3369013

Submitted on 25 Oct 2020 by Rafael S.T. Vieira
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% High Image Signal : Vignetted Image Appears Normal load penny.mat; Timg=double(P); % P is Matlab demo file upon load Timg=Timg+200; [nr nc]=size(Timg); % rmin=min(Timg(:)); % rmax=max(Timg(:)); % figure(1);imagesc(Timg,[rmin rmax]);colormap gray;axis equal offset=zeros(1,nc); obscuration=offset; widthL=20; widthR=15; maxobsL=.20; maxobsR=.15; % ObscurationLinear obscuration(1:1+widthL)=maxobsL*(widthL-(0:widthL))/widthL; obscuration(end:-1:end-widthR)=maxobsR*(widthR-(0:widthR))/widthR; % Create a Low Signal NF only LowSig=30; VignetteSig=200; NF_V=VignetteSig*obscuration; LCal=NF_V+LowSig; % figure(2),plot(LCal) Cimg=Timg.*repmat((1-obscuration),nr,1)+repmat(NF_V,nr,1); % figure(3);imagesc(Cimg,[rmin rmax]);colormap gray;axis equal Fimg=Vignette_fix(Cimg,LCal); %Perform Tolerance Check tolerance=[0.01 1]; Pass=1; % Hi check tcheck=(Timg*(1+tolerance(1))+tolerance(2))-Fimg; if min(tcheck(:))<0,Pass=0;end % Lo check tcheck=Fimg-(Timg*(1-tolerance(1))-tolerance(2)); if min(tcheck(:))<0,Pass=0;end assert(isequal(Pass,1))

2   Pass
% Low Image Signal : Typical Vignette Positive Edges load penny.mat; Timg=double(P); Timg=Timg+50; [nr nc]=size(Timg); % rmin=min(Timg(:)); % rmax=max(Timg(:)); % figure(1);imagesc(Timg,[rmin rmax]);colormap gray;axis equal offset=zeros(1,nc); obscuration=offset; widthL=24; widthR=16; maxobsL=.16; maxobsR=.20; % ObscurationLinear obscuration(1:1+widthL)=maxobsL*(widthL-(0:widthL))/widthL; obscuration(end:-1:end-widthR)=maxobsR*(widthR-(0:widthR))/widthR; % Create a Low Signal NF only LowSig=30; VignetteSig=600; NF_V=VignetteSig*obscuration; LCal=NF_V+LowSig; % figure(2),plot(LCal) Cimg=Timg.*repmat((1-obscuration),nr,1)+repmat(NF_V,nr,1); % figure(3);imagesc(Cimg,[rmin rmax]);colormap gray;axis equal % Execute Fimg=Vignette_fix(Cimg,LCal); %Perform Tolerance Check tolerance=[0.01 1]; Pass=1; % Hi check tcheck=(Timg*(1+tolerance(1))+tolerance(2))-Fimg; if min(tcheck(:))<0,Pass=0;end % Lo check tcheck=Fimg-(Timg*(1-tolerance(1))-tolerance(2)); if min(tcheck(:))<0,Pass=0;end assert(isequal(Pass,1))

3   Pass
% Low Image Signal : Typical Vignette Positive Edges load penny.mat; Timg=double(P); Timg=Timg+50; [nr nc]=size(Timg); % rmin=min(Timg(:)); % rmax=max(Timg(:)); % figure(1);imagesc(Timg,[rmin rmax]);colormap gray;axis equal offset=zeros(1,nc); obscuration=offset; widthL=16; widthR=12; maxobsL=.08; maxobsR=.12; % ObscurationLinear obscuration(1:1+widthL)=maxobsL*(widthL-(0:widthL))/widthL; obscuration(end:-1:end-widthR)=maxobsR*(widthR-(0:widthR))/widthR; % Create a Low Signal NF only LowSig=30; VignetteSig=600; NF_V=VignetteSig*obscuration; LCal=NF_V+LowSig; % figure(2),plot(LCal) Cimg=Timg.*repmat((1-obscuration),nr,1)+repmat(NF_V,nr,1); % figure(3);imagesc(Cimg,[rmin rmax]);colormap gray;axis equal % Execute Fimg=Vignette_fix(Cimg,LCal); %Perform Tolerance Check tolerance=[0.01 1]; Pass=1; % Hi check tcheck=(Timg*(1+tolerance(1))+tolerance(2))-Fimg; if min(tcheck(:))<0,Pass=0;end % Lo check tcheck=Fimg-(Timg*(1-tolerance(1))-tolerance(2)); if min(tcheck(:))<0,Pass=0;end assert(isequal(Pass,1))

4   Pass
% High Signal : Negative Edge Appearance load penny.mat; Timg=double(P); Timg=Timg+800; [nr nc]=size(Timg); % rmin=min(Timg(:)); % rmax=max(Timg(:)); % figure(1);imagesc(Timg,[rmin rmax]);colormap gray;axis equal offset=zeros(1,nc); obscuration=offset; widthL=16; widthR=14; maxobsL=.08; maxobsR=.18; % ObscurationLinear obscuration(1:1+widthL)=maxobsL*(widthL-(0:widthL))/widthL; obscuration(end:-1:end-widthR)=maxobsR*(widthR-(0:widthR))/widthR; % Create a Low Signal NF only LowSig=30; VignetteSig=600; NF_V=VignetteSig*obscuration; LCal=NF_V+LowSig; % figure(2),plot(LCal) Cimg=Timg.*repmat((1-obscuration),nr,1)+repmat(NF_V,nr,1); % figure(3);imagesc(Cimg,[rmin rmax]);colormap gray;axis equal % Execute Fimg=Vignette_fix(Cimg,LCal); %Perform Tolerance Check tolerance=[0.01 1]; Pass=1; % Hi check tcheck=(Timg*(1+tolerance(1))+tolerance(2))-Fimg; if min(tcheck(:))<0,Pass=0;end % Lo check tcheck=Fimg-(Timg*(1-tolerance(1))-tolerance(2)); if min(tcheck(:))<0,Pass=0;end assert(isequal(Pass,1))

5   Pass
Timg = double(imread('concordorthophoto.png')); % Matlab full image Timg=Timg(1:512,1:512); Timg=Timg+400; % Nominal 20 [nr nc]=size(Timg); % rmin=min(Timg(:)); % rmax=max(Timg(:)); % figure(1);imagesc(Timg,[rmin rmax]);colormap gray;axis equal offset=zeros(1,nc); obscuration=offset; widthL=48; widthR=40; maxobsL=.2; % chan 1 Vig = 0.1842 maxobsR=.15; % Chan 512 Vig = 0.1359 % Obscuration 4th order obscuration(1:1+widthL)=maxobsL*(((1:1+widthL)-(1+widthL)).^4/(widthL+1)^4); obscuration(end-widthR:end)=maxobsR*(((widthR+1:-1:1)-(1+widthR)).^4/(widthR+1)^4); % Create a Low Signal NF only LowSig=30; VignetteSig=1500; NF_V=VignetteSig*obscuration; LCal=NF_V+LowSig; % figure(2),plot(LCal) Cimg=Timg.*repmat((1-obscuration),nr,1)+repmat(NF_V,nr,1); % figure(3);imagesc(Cimg,[rmin rmax]);colormap gray;axis equal % Execute Fimg=Vignette_fix(Cimg,LCal); %Perform Tolerance Check tolerance=[0.01 1]; Pass=1; % Hi check tcheck=(Timg*(1+tolerance(1))+tolerance(2))-Fimg; if min(tcheck(:))<0,Pass=0;end % Lo check tcheck=Fimg-(Timg*(1-tolerance(1))-tolerance(2)); if min(tcheck(:))<0,Pass=0;end assert(isequal(Pass,1))

6   Pass
Timg = double(imread('concordorthophoto.png')); % Matlab full image Timg=Timg(1600:2111,900:1411); Timg=Timg+300; [nr nc]=size(Timg); % rmin=min(Timg(:)); % rmax=max(Timg(:)); % figure(1);imagesc(Timg,[rmin rmax]);colormap gray;axis equal offset=zeros(1,nc); obscuration=offset; widthL=42; widthR=36; maxobsL=.18; % maxobsR=.23; % % Obscuration Linear obscuration(1:1+widthL)=maxobsL*(widthL-(0:widthL))/widthL; obscuration(end:-1:end-widthR)=maxobsR*(widthR-(0:widthR))/widthR; % Create a Low Signal NF only LowSig=50; VignetteSig=1200; NF_V=VignetteSig*obscuration; LCal=NF_V+LowSig; %figure(2),plot(LCal) Cimg=Timg.*repmat((1-obscuration),nr,1)+repmat(NF_V,nr,1); %figure(3);imagesc(Cimg,[rmin rmax]);colormap gray;axis equal % Execute Fimg=Vignette_fix(Cimg,LCal); %Perform Tolerance Check tolerance=[0.01 1]; Pass=1; % Hi check tcheck=(Timg*(1+tolerance(1))+tolerance(2))-Fimg; if min(tcheck(:))<0,Pass=0;end % Lo check tcheck=Fimg-(Timg*(1-tolerance(1))-tolerance(2)); if min(tcheck(:))<0,Pass=0;end assert(isequal(Pass,1))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!