在MATLAB中解开半圆柱的图片 [英] unwrap picture of a half cylinder in MATLAB

查看:50
本文介绍了在MATLAB中解开半圆柱的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题如下:

我从水平角度拍摄了一个半圆柱体的图片,上面有方形网格线,所以我想知道如何在MATLAB中实现以解开该半圆柱体,使我所有的网格单元都变成相同的大小?我知道我会在边缘单元中失去很多分辨率,并且可以通过简单的线性插值来解决问题,但是我不知道如何告诉MATLAB做到这一点.我也知道圆柱体的几何特性,半径和高度.任何帮助,我们将不胜感激.

I have the picture of a half cylinder taken from a horizontal perspective and it has square grid lines on it, so I was wondering how can I implement in MATLAB to unwrap this half cylinder so all my grid cells become the same size? I know I will loose lots of resolution in the edge cells and a simple linear interpolation should do the trick, but I do not know how to tell MATLAB to do this. Also I know the geometrical properties of the cylinder, radius and height. Any help is greatly appreciated.

这是我正在使用的方法,但是我试图找到一种可以使边缘与内部单元格大小相同的变换.

This is the approach I am using, but I am trying to find the transformation that will make the edges be same size as inner cells.

im=imread('Capture.png');
imshow(im);
impixelinfo

r = @(x) sqrt(x(:,1).^2 + x(:,2).^2);
w = @(x) atan2(x(:,2), x(:,1));
f = @(x) [sqrt(r(x)) .* cos(w(x)), sqrt(r(x)) .* sin(w(x))];
g = @(x, unused) f(x);

tform2 = maketform('custom', 2, 2, [], g, []);
im3 = imtransform(im, tform2, 'UData', [-1 1], 'VData', [-1 1], ...
'XData', [-1 1], 'YData', [-1 1]);

figure,
imshow(im3)

推荐答案

我认为转换比您要尝试的转换要简单得多.看一下(正向)转换,以获取一个平坦的网格并将其包裹在圆柱体上.沿圆柱轴的坐标(在这种情况下, y 坐标)保持不变.如果我们沿 x 方向的网格坐标范围为[-1,1],则圆柱体上的坐标将为:

I think the transformation is much simpler than what you're trying to do. Take a look at the (forward) transformation to take a flat grid and wrap it around a cylinder. The coordinates along the axis of the cylinder (the y coordinates, in this case) are unchanged. If we take the range of the grid coordinates in the x direction to be [-1,1], the coordinates on the cylinder will be:

sin(x×π/2)

sin(x × π/2)

因为这是从网格到圆柱的正向转换,所以它也是从圆柱到网格的转换.

Since this is the forward transformation going from a grid to the cylinder, it is also the inverse transformation going from the cylinder to the grid.

f = @(x, unused) [sin(x (:, 1) * pi / 2), x(:, 2)]
tform2 = maketform('custom', 2, 2, [], f, []);
im3=imtransform(img, tform2, 'UData', [-1 1], 'VData', [-1 1], ...
                             'XData', [-1 1], 'YData', [-1 1]);

结果:

这仍然不是完美的,主要是因为原始图像周围有边框,我们正在与其他图像一起进行转换.这可以通过将图像裁剪为仅包含圆柱部分来改善.

This still isn't perfect, primarily because the original image has borders around it that we're transforming along with the rest of the image. This could be improved by cropping the image to contain only the cylinder portion.

这篇关于在MATLAB中解开半圆柱的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆