Purpose: Image noise reduction (image repair, restoration),TVloss is an effective regular term to maintain the smoothness of the image

The denoising effect of TVloss is good, but it will lead to the image becoming too smooth. If so, it may be better to add TVloss.

The total variational model is a model that mainly relies on gradient descent to smooth the image. It hopes to smooth the image inside the image so that the difference between adjacent pixels is smaller and the contour (edge) of the image is not smoothed as much as possible. The mathematical definition is as follows:

But this function is non-differentiable, non-convex, so there is another definition for total variation in two dimensions:

This is a convex function.. So the total variation comes out to be a number.

If the denoising of one-dimensional signal is imitated, the image denoising based on total variation can be regarded as solving the optimization problem:

The function image = bldconv a1 (g) = 0.1; A2 = 0.01; PQ=paddedsize(size(g)); G=fft2(g,PQ(1),PQ(2)); [y x]=size(G); htemp=ones(3); h0=freqz2(htemp,PQ(1),PQ(2)); R=Rcreat(y,x); H=h0; For k = 1:10% calculation IMG and PSF IMG = (conj (H). * G))/((conj (H) * H) + a1 * R); H=conj(iMG).*G./((conj(iMG).*iMG)+a2*R); end IMG=mat2gray(real(ifft2(iMG))); image=IMG(1:size(g,1),1:size(g,2)); imwrite(image,'testfile.tif'); imshow(image,[]); hold on; End % = = = = = = = = = = = = = = = = = = = = = = = = = = = % calculation R matrix function Rcreat % = = = = = = = = = = = = = = = = = = = = = = = = = = = function R = Rcreat (y, x) % % R matrix generation function by Realasking % for bdeconv.m I =1:y; j=1:x; RI=zeros(y,x); RJ=zeros(y,x); R=zeros(y,x); For k = 1: to quantify the matrix of code generation R y % RI (k, I) = 2 * cos (2 * PI * i. / y); end for k=1:x RJ(j,k)=-2*cos(2*pi*j'./x); end Img=imread('Baboon1.bmp'); PSF= fSpecial ('motion',3); Gb =imfilter(Img,PSF,'circular'); Img=imnoise(gb,'gaussian',0,0.01); Figure,imshow(Img) Img=double(Img); Img0=Img; PQ=paddedsize(size(Img)); IMG=fft2(Img,PQ(1),PQ(2)); IMG0=fft2(Img0,PQ(1),PQ(2)); [nrow,ncol]=size(Img); % Image size lamda1=0.02; Lamda2 = 0.02; Dt = 0.28; % 0.25-0.35 G=gauss(Img,7,3); Ix = 0.5 * (G (: [2: ncol, ncol]), G (:,] [1, 1: ncol - 1)); Iy = 0.5 * % x direction gradient (G ([2: nrow, nrow], :) - G ([1, 1: nrow - 1), :)); % y gradG = Ix.^2+Iy.^2; P=1+1./(1+gradG); % adaptive filter deltax=Img0; %zeros(nrow,ncol); % produces a matrix the same size as the image deltay=Img0; %zeros(nrow,ncol); htemp=ones(3); h0=freqz2(htemp,PQ(1),PQ(2)); R=Rcreat(PQ(1),PQ(2)); H=h0; For I =2:(nrow-1) for j=2:(ncol-1) Deltax (I, j) = (Img (I + 1, j) - Img (I, j)))/(((Img (I + 1, j) - Img (I, j))) ^ 2 + (Img (I, j + 1) - Img (I, j - 1)). ^ 2/4 + 1)) ^ (1-0.5. * P (I, j))) - (Img (I, j ) - Img (I - 1, j))/(((Img (I, j) - Img (I - 1, j))) ^ 2 + (Img (I - 1, j + 1) - Img (j - I - 1, 1)). ^ 2/4 + 1)) ^ (1-0.5. * P (I - 1, j))); Deltay (I, j) = (Img (I, j + 1) - Img (I, j)))/(((Img (I + 1, j) - Img (I - 1, j)). ^ + 2/4 (Img (I, j + 1) - Img (I, j))) ^ 2 + 1)) ^ (1-0.5. * P (I, j))) - (Img (I, j ) - Img (I, j - 1))/(((Img) (I + 1, j - 1 - Img (j - I - 1, 1)). ^ + 2/4 (Img (I, j) - Img (I, j - 1)). ^ 2 + 1)) ^ (1-0.5. * P (I, j - 1))); end end div=deltax+deltay; DIV=fft2(div,PQ(1),PQ(2)); IMG=IMG+dt*(-conj(H).*H.*IMG+conj(H).*IMG0+lamda1.*DIV); H=conj(IMG).*IMG0./(conj(IMG).*IMG+lamda2.*R); Img1=real(ifft2(IMG)); Img = Img1 (1: size (Img0, 1), 1: size (Img0, 2)); endCopy the code

3. Operation results