RenYurui / StructureFlow

Code for paper "StructureFlow: Image Inpainting via Structure-aware Appearance Flow"
Other
222 stars 42 forks source link

get reconstructed structure images #17

Closed leeqiaogithub closed 4 years ago

leeqiaogithub commented 4 years ago

hello.I wonder how tu obtain the corresponding reconstructed structure images from the damaged image.

RenYurui commented 4 years ago
  1. You can directly smooth the damaged images using RTV smooth method. But please remember to expand the mask to remove the affected edge.
  2. If you need to evaluate the results, you may need to use a more accurate way. You can modify the RTV smooth method to remove the effect of masked regions. You need to send the mask images to tsmooth.m. Then, replace the Function "computeTextureWeights" in tsmooth.m as follows:
function [retx, rety] = computeTextureWeights(fin, mask, sigma,sharpness)

   fx = diff(fin,1,2);
   fx = padarray(fx, [0 1 0], 'post');
   fy = diff(fin,1,1);
   fy = padarray(fy, [1 0 0], 'post');

   mask(mask>0)=1;
   fx=fx.*(1-mask);
   fy=fy.*(1-mask);

   vareps_s = sharpness;
   vareps = 0.001;

   wto = max(sum(sqrt(fx.^2+fy.^2),3)/size(fin,3),vareps_s).^(-1); 
   fbin = lpfilter(fin, sigma);
   gfx = diff(fbin,1,2);
   gfx = padarray(gfx, [0 1], 'post');
   gfy = diff(fbin,1,1);
   gfy = padarray(gfy, [1 0], 'post');     
   wtbx = max(sum(abs(gfx),3)/size(fin,3),vareps).^(-1); 
   wtby = max(sum(abs(gfy),3)/size(fin,3),vareps).^(-1);   
   retx = wtbx.*wto;
   rety = wtby.*wto;

   retx(:,end) = 0;
   rety(end,:) = 0;

end
leeqiaogithub commented 4 years ago
  1. You can directly smooth the damaged images using RTV smooth method. But please remember to expand the mask to remove the affected edge.
  2. If you need to evaluate the results, you may need to use a more accurate way. You can modify the RTV smooth method to remove the effect of masked regions. You need to send the mask images to tsmooth.m. Then, replace the Function "computeTextureWeights" in tsmooth.m as follows:
function [retx, rety] = computeTextureWeights(fin, mask, sigma,sharpness)

   fx = diff(fin,1,2);
   fx = padarray(fx, [0 1 0], 'post');
   fy = diff(fin,1,1);
   fy = padarray(fy, [1 0 0], 'post');

   mask(mask>0)=1;
   fx=fx.*(1-mask);
   fy=fy.*(1-mask);

   vareps_s = sharpness;
   vareps = 0.001;

   wto = max(sum(sqrt(fx.^2+fy.^2),3)/size(fin,3),vareps_s).^(-1); 
   fbin = lpfilter(fin, sigma);
   gfx = diff(fbin,1,2);
   gfx = padarray(gfx, [0 1], 'post');
   gfy = diff(fbin,1,1);
   gfy = padarray(gfy, [1 0], 'post');     
   wtbx = max(sum(abs(gfx),3)/size(fin,3),vareps).^(-1); 
   wtby = max(sum(abs(gfy),3)/size(fin,3),vareps).^(-1);   
   retx = wtbx.*wto;
   rety = wtby.*wto;

   retx(:,end) = 0;
   rety(end,:) = 0;

end

thanks for you reply.i will try this way.but i also wonder why did not you open the structure reconstructor network directly?

RenYurui commented 4 years ago

Sorry, I may not explain clearly. The method provided above is used to obtain the input smooth images from corrupted input images. You need to send the obtained smooth images along with the corrupted input images and their masks to the structure reconstructor to obtain the reconstructed structure images.

leeqiaogithub commented 4 years ago

Sorry, I may not explain clearly. The method provided above is used to obtain the input smooth images from corrupted input images. You need to send the obtained smooth images along with the corrupted input images and their masks to the structure reconstructor to obtain the reconstructed structure images.

你好,最后还想跟您确认一下,进行测试时的输入。1/mask 2/“input”,请问这里指代的是原图还是需要将mask对应区域标记出来之后的“原图” 3/“Input Structure” 是针对2中提到的哪个图进行您上述提到的“RTV smooth method”得到的呢? 因为按照论文figure2的输入测试得到的结果不好,没有我直接输入【mask+原图+由原图直接计算得到的平滑图像】得到的结果好。

RenYurui commented 4 years ago

--mask The mask of the corrupted image. --input The corrupted image. --structure The structure (RTV smooth result) of the corrupted image.

To obtain the structure results (RTV smooth result) of the corrupted images you need to use the Matlab code provided above. It can avoid the effect of masked regions. (The RTV smooth the inputs using local windows. The "wrong" pixel value inside the corrupted regions will lead to incorrect smooth results.)

However, you can also directly use the ground-truth images and their structures as the "input" and "structure". Our model will apply the mask to them.