帧对齐 - 以较低的采样率推断几何变换,并以更大的采样率将其应用于图像

时间:2013-05-29 04:21:49

标签: matlab alignment computer-vision affinetransform

第1部分:128 * 128图像上的对齐代码 - 此部分正常工作

             images = dir('*.jpg');

             [cs,index] = sort_nat({images.name});

             frame_number = 1;

             movMean = imresize(imread(cs{frame_number}),[128,128]);
             imgB = movMean;
             imgBp = imgB;
             correctedMean = imgBp;
             ii = 2;
             Hcumulative = eye(3);

             movMean2 = imresize(imread(cs{frame_number}),[1024,1024]);
             imgB2 = movMean2;
             imgBp2 = imgB2;
             correctedMean2 = imgBp2;

      while ii < length(images)

            % Read in new frame
            imgA = imgB; % 
            imgAp = imgBp; % 
            imgB = imresize(imread(cs{ii}),[128,128]); 
            imgB2 = imresize(imread(cs{ii}),[1024,1024]);

            % Estimate transform from frame A to frame B, and fit as an s-R-t
            H = cvexEstStabilizationTform(imgA,imgB);

            if isempty(H)

                break
            end

            HsRt = cvexTformToSRT(H);
            Hcumulative = HsRt * Hcumulative;
           imgBp = imwarp(imgB,affine2d(Hcumulative),'OutputView',imref2d(size(imgB)));


           imwrite(imgBp,[cs{ii},'_aligned.jpg'])
           ii = ii+1;

       end

第2部分:将转换重新映射到1024 * 104图像的修改代码 - 无法成功重映射

        images = dir('*.jpg');
        [cs,index] = sort_nat({images.name});
        frame_number = 1;

        movMean = imresize(imread(cs{frame_number}),[128,128]); 
        imgB = movMean;
        imgBp = imgB;
        correctedMean = imgBp;
        ii = 2;
       Hcumulative = eye(3);

       movMean2 = imresize(imread(cs{frame_number}),[1024,1024]); 
       imgB2 = movMean2;
       imgBp2 = imgB2;
       correctedMean2 = imgBp2;


       HdownScale = [ 128/1024        0 0; ...
                             0 128/1024 0; ...
                             0        0 1];


      HupScale   = [ 1024/128        0 0; ...
                            0 1024/128 0; ...
                            0        0 1];


       while ii < length(images)

            % Read in new frame
            imgA = imgB; 
            imgAp = imgBp; 
            imgB = imresize(imread(cs{ii}),[128,128]); 
            imgB2 = imresize(imread(cs{ii}),[1024,1024]);

            % Estimate transform from frame A to frame B, and fit as an s-R-t
            H = cvexEstStabilizationTform(imgA,imgB);

            HsRt = cvexTformToSRT(H);
            Hcumulative = HupScale * HsRt * Hcumulative * HdownScale;


         imgBp2 =imwarp(imgB2,affine2d(Hcumulative),'OutputView',imref2d(size(imgB2)));

         % Write Aligned images in given folder
         imwrite(imgBp2,[cs{ii},'_aligned.jpg'])

         ii = ii+1;

- Ash

使用第1部分中的代码成功对齐128 * 128帧的示例here

使用第2部分中的代码here无法成功重新映射到1024 * 104帧

1 个答案:

答案 0 :(得分:1)

您可以将调整大小视为将另一个缩放矩阵应用于图像

HdownScale = [ 512/4096        0 0; ...
                      0 512/4096 0; ...
                      0        0 1];

重新调整大小就像应用

一样
HupScale   = [ 4096/512        0 0; ...
                      0 4096/512 0; ...
                      0        0 1];

所以你需要的是

Hcumulative = HupScale * HsRt * Hcumulative * HdowScale;

现在,您可以将Hcumulative应用于原始尺寸的图像。