Вопрос

I tried to apply a geometric transformation to a video using MATLAB Function block in Simulink. I connected a 'From Multimedia File' block to MATLAB Function block ant its output to a 'To Video Display' block. Inside MATLAB Function Block this code:

function outputImage = fcn(inputImage,theta)


coder.extrinsic('affine2d')
coder.extrinsic('imwarp')
outputImage = coder.nullcopy(inputImage);


tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]);

outputImage = imwarp(inputImage,tform);

where angle theta is a constant block of 10. The code above is an example from 'affine2d' function examples. It returns me following error:

Size mismatch for MATLAB expression 'imwarp'. Expected = 120x160x3 Actual = 146x179x3 Block MATLAB Function (#108) While executing: State During Action 

but I don't understand where is the error (why Actual=146x179x3). The input video is a RGB video file ('vipmen.avi') from CV toolbox demos.

EDIT: I solved it: I used Apply Geometric Transformation block for translation and a Rotate block for rotation with:

H = [1 0; 0 1; Ox-X  Oy-Y] %where Ox,Oy are image framework origin coordinates and X,Y are offset coordinates. 

Indeed after translation, the "new" image framework origin is the (X,Y) point and the Rotate block rotates it about (X,Y).

Это было полезно?

Решение

The Computer Vision System Toolbox includes a block called Apply Geometric Transformation, which will do what you need and save you the trouble of using MATLAB function block.

Edit: The Apply Geometric Transformation block has been deprecated as of R2015b release. Please use the Warp block instead.

Другие советы

As an image is warped/rotated the number of rows and/or columns in it will change.

You'll need to modify your code so that outputImage is variable sized. To do this open the code (for the MATLAB Function Block) in the editor and open up the "Edit Data" dialog. Select outputImage in the left hand column, then

  1. check the "variable size" check box
  2. enter something like [400 400 3] as the size

You have to make a best guess for the maximum row and column size that you expect.

Note also that the Matlab function block must have a discrete sample time for it to use variable sized signals. To set this, right click on the block and select Block Parameters, then set a sample time.

I solved trying to understand what happens. The deformed image has a dimension different from Output=coder.nullcopy(X) so I calculated the dimension of the new deformed image, create a blank image with Output=coder.nullcopy(ones(new_row,new_colomn,3)) and that works

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top