• 大小: 8.66MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-06
  • 语言: 其他
  • 标签: Image  Quilting  

资源简介

纹理图像分割算法,即把一张纹理图像分割成许多样本,然后利用imagequilting算法,重新生成另一张纹理图像,这样可以求出样本的平均值进行排序,直接运行程序 imagequilt.m 即可看到效果

资源截图

代码片段和文件信息

%function Y = imagequilt(X tilesize n overlap err)
%Performs the Efros/Freeman Image quilting algorithm on the input
%
%Inputs
%   X:  The source image to be used in synthesis
%   tilesize:   the dimensions of each square tile.  Should divide size(X) evenly
%   n:  The number of tiles to be placed in the output image in each dimension
%   overlap: The amount of overlap to allow between pixels (def: 1/6 tilesize)
%   err: used when computing list of compatible tiles (def: 0.1)

function Y = imagequilt()

X = imread(‘bamboo.tif‘);X = double(X);
tilesize=10;
n=20;
overlap=3;
err=0.1;



if( length(size(X)) == 2 )
    X = repmat(X [1 1 3]);%make X into 3 channels
elseif( length(size(X)) ~= 3 )
    error(‘Input image must be 2 or 3 dimensional‘);
end;
    
simple = 0;

if( nargin < 5 )
    err = 0.002;
end;

if( nargin < 4 )
    overlap = round(tilesize / 4);
end;

% if( size(X1) ~= size(X2) )
%     error(‘Must be square‘);
% end;

if( overlap >= tilesize )
    error(‘Overlap must be less than tilesize‘);
end;

destsize = n * tilesize - (n-1) * overlap                        % the destination image‘s col number

Y = zeros(destsize destsize 3);

for i=1:n
     for j=1:n
         startI = (i-1)*tilesize - (i-1) * overlap + 1;
         startJ = (j-1)*tilesize - (j-1) * overlap + 1;                                        
         endI = startI + tilesize -1;
         endJ = startJ + tilesize -1;
         
         %Determine the distances from each tile to the overlap region
         %This will eventually be replaced with convolutions
         distances = zeros( size(X1)-tilesize size(X2)-tilesize );                         
         useconv = 0;                                                               
        
        if( useconv == 0 )
            
            %Compute the distances from the template to target for all ij
            for a = 1:size(distances1)
                v1 = Y(startI:endI startJ:endJ 1:3);
                for b = 1:size(distances2)                 
                    v2 = X(a:a+tilesize-1b:b+tilesize-1 1:3);
                    distances(ab) = myssd( double((v1(:) > 0)) .* (v1(:) - v2(:)) );
                    %distances(ab) = D;                
                end;
            end;            
        else
            
            %Compute the distances from the source to the left overlap region
            if( j > 1 )
                distances = ssd( X Y(startI:endI startJ:startJ+overlap-1 1:3) );    
                distances = distances(1:end 1:end-tilesize+overlap);                    
            end;
            
            %Compute the distance from the source to top overlap region
            if( i > 1 )
                Z = ssd( X Y(startI:startI+overlap-1 startJ:endJ 1:3) );
                Z = Z(1:end-tilesize+overlap 1:end);
                if( j > 1 ) distances = distances + Z;
                

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6466  2015-12-04 15:50  1.jpg

     文件      19254  2013-06-07 17:11  bamboo.tif

     文件       6796  2015-12-04 15:50  flower.jpg

     文件       6555  2016-04-08 16:21  imagequilt.m

     文件       1588  2013-06-07 17:11  mincut.m

     文件    9009131  2013-06-07 17:11  quilting.pdf

     文件      61830  2016-05-14 21:19  result.bmp

     文件        632  2013-06-07 17:11  ssd.m

     文件      45218  2016-05-14 21:19  Y.mat

     文件        105  2016-04-09 09:30  要求.txt

----------- ---------  ---------- -----  ----

              9157575                    10


评论

共有 条评论