change imref2d so that image is in center

조회 수: 9(최근 30일)
Katharina Heitger
Katharina Heitger 2021년 12월 5일
댓글: Katharina Heitger 2021년 12월 8일
I have asked in a previous question how I can change the origin of a transformationmatrix for application. The initial situation was that it seemed that the transformationmatrix was apllied onto a simulated image with the wrong origin. For information the simulated image contains a plane as an object. So the image after tranfomration should be a square beginning at matrix indeces approx. (26;26). And the image is the size of 2049x2049px. The previous question can be found here:
Now with the help of these answers and additional research I applied different parameters of imwarp() and got this far:
pixelExtendInWorldX=(203.53*2)/2049; %I know that the image plane in real world is in x-direction 203.53*2 mm long.
pixelExtendInWorldY=(1390-984.41)/2049; %the distancce in y-direction is 1390-984.41
outputimref2d=imref2d(size(origimage), pixelExtendInWorldX, pixelExtendInWorldY);
realdectcorroutputview2 = imwarp(origimage,tmatrix, 'nearest','OutputView', outputimref2d);
With this I get an result which begins at matrix indeces (93,92) and is then cut off. So it appears that the center is too much in the lower right direction. But the result seems to be a square (the desired shape) as the visible edges are straight lines. As the image is cut off only two of four edges are visible.
I tried the answers from my first question as well, which I wrote as
xWorldLimits2=[-203.54 203.54];
yWorldLimits2=[984.41 1390];
outputimref2dwl=imref2d(size(origimage) ,xWorldLimits2,yWorldLimits2);
realdectcorroutputview2wl = imwarp(origimage,tmatrix, 'nearest', 'OutputView', outputimref2dwl);
This resulted in an image, beginning at indeces of (1117/1118), going straight downwards, but having a protruding edge at the end in the right direction from this image.
I also tried
xWorldLimits2=[-203.54 203.54];
yWorldLimits2=[984.41 1390];
outputimref2dwl=imref2d(size(origimage) ,xWorldLimits2,yWorldLimits2);
realdectcorroutputview2wl = imwarp(origimage,tmatrix, 'nearest', 'OutputView', outputimref2dwl);
which did not really change the result.
realdectcorrRin = imwarp(origimage,Rin, tmatrix, 'nearest');
did not work at all.
So the first attempt seems to yield the best results yet, but how can I additionally change (supposably) the imref2d-object, that the final image is not cut off anymore, but more centered?
Any help is appreciated.
  댓글 수: 5
Katharina Heitger
Katharina Heitger 2021년 12월 6일
Here are some simple sketches, how the matrices look like. idealdect200 is the desired result and realdect200 is the image to be tranformed. The other are named like in the code. Ending at (2049/2049) indicates that there is a cut off. realdectcorroutputview2v2 is not sketched, as it only contains 0.

댓글을 달려면 로그인하십시오.


yanqi liu
yanqi liu 2021년 12월 6일
yes,sir,which tmatrix used in your code,may be upload the file and do some analysis,such as
clear all;clc;close all;
origimage = imread('football.jpg');
Rin=imref2d([size(origimage,1) size(origimage,2)]);
tmatrix = affine2d([1 0 0; .5 1 0; 0 0 1]);
realdectcorrRin = imwarp(origimage,Rin, tmatrix, 'nearest');
figure; montage({origimage,realdectcorrRin}, 'Size', [1 2], 'BackgroundColor', 'w', 'BorderSize', [2 2]);

Matt J
Matt J 2021년 12월 6일
편집: Matt J 2021년 12월 6일
The reason the output doesn't look like a square is because your tmatrix is wrong, not because of anything else:
load 'SimulationDataMathworks0612.mat';
origimage=realdect200; %or realdet1802028
mp=fliplr( [19,19; 19 2031; 2034 2034; 2034 16] );
fp=fliplr( [26,26; 26 2024; 2024 2024; 2024 26] );
realdectcorrRin = imwarp(origimage, tform, 'nearest');
  댓글 수: 3
Katharina Heitger
Katharina Heitger 2021년 12월 8일
I read that, but I completly forgot about that. But my input data for fitgeotrans() are world coordinates as you described. So at least that is correct.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by