質問

I am trying to transform an image representing a grid (with known number of rows and columns) to more-or-less match a picture that represents a grid-like pattern.

I am using imregtform function to obtain an affine transformation:

[ a b 0 ;
  c d 0 ;
  e f 1 ] 

and apply the obtained tform to my grid. It does not work very well.

Please consider the following simplified:

base=im2uint8(zeros(16)); base([3:5 10:12],[3:5 10:12])=255;
target=im2uint8(zeros(16)); target([4:8 11:15],[4:8 11:15])=255;
[optimizer, metric] = imregconfig('monomodal');
    optimizer.MaximumStepLength = 0.591;
    optimizer.MaximumIterations = 100;
tform = imregtform(base,target,'affine',optimizer,metric,'PyramidLevels',2);
transformedBase = imwarp(base,tform,'OutputView',imref2d(size(target)));

Please refer to the following link.

that presents results of using above functions on simplified images. I calculate the tform and apply it to the "base" image to see if it will match the "target". This strategy works fine for a simple translated "target" image, but as shown, not for an image that is translated and scaled. After a lot of fiddling with the optimiser parameters, this was the closest I could get.

Decreasing the optimizer.MaximumStepLength further leads to the point where the tform becomes an identity matrix [100;010;001].

Why is this simple transformation so hard to achieve? Am I going a wrong way around it?

I know that the image is NOT rotated, would it help to obtain a transformation matrix without rotation? I have been pursuing this idea but haven't figured out how to do that; is there perhaps a way to calculate scaling matrix on its own? Then I could create a tform based on imregtform with 'translation' setting.

役に立ちましたか?

解決

The base and target images in your example are not related by a simple affine transformation. The spacing between the blocks doesn't scale by the same amount as the blocks themselves.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top