1
votes

I'm reading an article 'Deriving intrinsic images from image sequences'. I'm trying to get results from the article.

fnr is the reversed filter of fn:fn(x,y)=fnr(-x,-y). now I use fourier and pseudo-inverse to solve this equation and find

g : g*(sigma(fnr*fn)=delta

(sigma over n , '*' is convulotion everywhere),

%% fnt_fn_conv=sigma(fnr*fn)
fftr = fft2(fnr_fn_conv); 

 % find g
 fftrp = pinv(fftr);
 G = delta_fft x fftrp; (matrix mul)
 g = ifft2(G);

My problem is that g*(sigma(fnr*fn) **!=** delta, so g is wrong ! How should I build the fnr ? is fnr=rot90(fn, 2) sufficient, or I have to change the center of fnr with zero padding so fourier function will work correctly ?

Update :

The filtered images looks fine... I used 2 derivative filters ( horizental and vertical).

% given dx dy reconstruct image
% here we do the convolutions using FFT2


function [im,invKhat,k]=reconsEdge3(dx,dy,invKhat)



im=zeros(size(dx));
[sx,sy]=size(dx);
mxsize=max(sx,sy);

if ~exist('invKhat')
  [invK,k]=invDel2(2*mxsize);
  invKhat=fft2(invK);   %fourier for convolotion  G
end

%%
%% sigma fnr*r_n for 2 filters
imX=conv2(dx,fliplr([0 1 -1]),'same');
imY=conv2(dy,flipud([0;1;-1]),'same');

imS=imX+imY;  sigma

%%

imShat=fft2(imS,2*mxsize,2*mxsize);
im=real(ifft2(invKhat.*imShat));       %r
im=im(mxsize+1:mxsize+sx,mxsize+1:mxsize+sy);




function [invK,K]=invDel2(isize)

 %sigma(7) fnr*fn 
 K=zeros(isize);
 K(isize/2,isize/2)=-4;
 K(isize/2+1,isize/2)=1;
 K(isize/2,isize/2+1)=1;
 K(isize/2-1,isize/2)=1;
 K(isize/2,isize/2-1)=1;

 Khat=fft2(K);  %fourier for sigma(7)

 %add 1 to inverse without zeros
 I=find(Khat==0);   % find all zeros in Khat
 Khat(I)=1;     % put 1 where all zeros 
 invKhat=1./Khat;   % inverse
 invKhat(I)=0;  %dec the 1 added
 invK=ifft2(invKhat);
 invK=-real(invK);
 % invK and delta are not in the same dim, so we convolve
 % and then use transform fourier for invK in reconsEdge3
 invK=conv2(invK,[1 0 0;0 0 0;0 0 0],'same');

Note: conv2(invKhat,K)!=delta why ?!

1
look into flipud, fliplr, fftshiftbla
@natan I used flipud fliplr and posted the functions, I still have problems with outputs...Maroun Sassine

1 Answers

0
votes

https://imgproc2014.github.io/shadow_removal/

Implemented the article and finished the project !

Thanks anyways...