【问题标题】:Crop borders after image transformation using MATLAB使用 MATLAB 进行图像转换后裁剪边框
【发布时间】:2015-09-14 08:30:44
【问题描述】:

如何在转换(旋转、平移、缩放和剪切)图像后自动裁剪黑色边框?

我正在使用基于强度的自动图像配准(imregtform、优化器、imregister....)来旋转一张图像以适应另一张图像。 现在旋转后,我需要将两个图像裁剪成相同的大小,并且仍然对齐。

旋转后图像的最简单表示是a white square to which the transformation matrix was applied.

一组the actual images I am using would look like can be seen here.的例子

我假设图像边缘可能有零值像素可能会使操作复杂化,尽管我假设由于噪声,整个图像将非零。

也许我可以使用转换矩阵来实际计算需要裁剪的边框。在上面的例子中,矩阵是:

 0,999428374496743      0,00888472048904662   0
-0,00888472048904659    0,999428374496743     0
 3,79626401832983      -0,493066986575474     1

矩阵列在工作区中的“1x1 仿射 2d”对象中。我无法从那里找到使用它的语法。

【问题讨论】:

  • 你不是在“旋转”,而是在使用所示的变换,对吗?
  • 是的,正确。旋转是其中的一部分,也可能是平移、缩放和剪切。

标签: image matlab image-registration


【解决方案1】:

我已经找到了一种方法,虽然它不是很优雅,因此我仍然对解决这个问题的好方法感兴趣。

可以将变换矩阵应用于图像的四个角点,并将这些新点用作裁剪限制。应确保裁剪角在原始图像内或需要固定到边缘。

% width and length of the input image
width = size(img_fixed,1);
height = size(img_fixed,2);

% transform the four corners of the image to find crop area
[x1,y1] = transformPointsForward(T,0,0);
[x2,y2] = transformPointsForward(T,width,0);
[x3,y3] = transformPointsForward(T,width,height);
[x4,y4] = transformPointsForward(T,0,height);

% find inner most borders for a rectangular crop
if max([x1,x4]) < 0
    x_left = 0;      
else
    x_left = ceil(max([x1,x4]));
end

if min([x2,x3]) > width
    x_right = width;     
else
    x_right = floor(min([x2,x3]));
end

if max([y1,y2]) < 0
    y_top = 0;   
else
    y_top = ceil(max([y1,y2])); 
end

if min([y3,y4]) > height
    y_bottom = height;      
else
    y_bottom = floor(min([y3,y4]));
end

img_fixed_crop = imcrop(img_fixed,[x_left y_top x_right-x_left y_bottom-y_top]);
img_moving_crop = imcrop(img_moving,[x_left y_top x_right-x_left y_bottom-y_top]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 2013-03-06
    • 2013-05-18
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    相关资源
    最近更新 更多