Frame Alignment --infer the geometric transformation at a lower sampling rate and apply this to imagery at a bigger sampling rate

StackOverflow https://stackoverflow.com/questions/16805454

Part 1: Alignment Code on 128*128 Images -- This part works fine

             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

Part 2: Modified code to remap transformation onto 1024*104 images --cannot remap successfully

        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

Examples of Successfull Alignment of 128*128 frames using code from Part 1 here

Examples of Unsuccessfull remapping onto 1024*104 frames using code from Part 2 here

有帮助吗?

解决方案

You can think of the resizing as applying another scaling matrix to your image

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

And re-sizing back is like applying

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

So what you need is

Hcumulative = HupScale * HsRt * Hcumulative * HdowScale;

Now you can apply Hcumulative to the original size images.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top