在Matlab中,如何扫描与实际坐标系旋转45度的二维坐标系中的二值图像?
我有一个二进制图像,如下图所示,
xy 坐标系是默认坐标MATLAB 自带的系统。我能够获得 xy 坐标系中每行和每列的像素总和。
但我想要通过 uv 坐标系步进来求像素总和。我怎样才能得到它?
我的想法是
1)将xy坐标系转换为连续(实值)坐标系 2)找到uv坐标系中每个点对应的xy坐标中的点。就像uv中的(1,1)对应于xy中的(1.26,1.45)。 3)获取uv坐标中的行和列的总和。
对此, 1)创建空间坐标系以及将像素坐标系转换为空间坐标系有哪些方法? 2)如何获取空间坐标系中分数像素的值?
谢谢。
I have a binary image as in figure below,
the x-y co-ordinate system is the default co-ordinate system that comes with MATLAB. I am able to get the sum of pixels across each row and column in x-y co-ordinate system.
But I want the sum of pixels by stepping through u-v co-ordinate system. How can i get it?
My idea is to
1) Convert the x-y co-ordinate system to a continuous (real valued) co-ordinate system
2) Find the points in x-y coordinates corresponding to each point in u-v co-ordinate system. like (1,1) in u-v corresponds to (1.26,1.45) in x-y.
3) Get sum of rows and columns in u-v co-ordinate.
In this regard,
1) what are the methods to create a spatial co-ordinate system and convert pixel coordinate system to spatial coordinate system?
2) how to get the values of fractional pixels in the spatial co-ordinate system?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你真的只想要对角线恰好为 45 度,并且你的像素是方形的(对于大多数标准相机来说是安全的假设),那么你真的不需要做任何我认为不进行的坐标转换。您可以使用以下事实:沿对角线的所有点都具有以下形式,例如
I(ix, ix), I(1 + ix, ix)
。计算极限有点棘手。尝试对“列”(从左上角到右下角的对角线)求和,从左下角开始,向上移动左边缘,然后穿过顶部:请注意,如果距离很重要对你来说(听起来好像不是),那么沿着这些对角线的距离会长
sqrt(2)/2
。If you really only want the diagonals at exactly 45 degrees, and your pixels are square (safe assumption with most standard cameras), then you don't really need to do any coordinate transformation I don't think. You can use the fact that all of the points along the diagonals have the form e.g.
I(ix, ix), I(1 + ix, ix)
. Working out the limits is a bit tricky. Try this for the "column" (diagonal from the top left to the bottom right) sums, starting at the bottom left, moving up the left edge, then across the top:Note that if the distance matters to you (kind of sounds like it doesn't), then the distances along these diagonals are
sqrt(2)/2
longer.只需对角度 45,135 使用氡变换即可。
它将为您准确提供您所需要的东西。
特定角度的像素总和。
http://en.wikipedia.org/wiki/Radon_transform
以下是一些解释氡气的图片变换
Just use the radon transform for the angles 45,135.
It will give you exactly what you need.
The sum of pixels in a specific angle.
http://en.wikipedia.org/wiki/Radon_transform
Here are some images that explain Radon transform
我将使用 meshgrid 来生成图像的坐标系。您可以通过与旋转矩阵进行矩阵乘法来旋转此坐标系。这应该给你转换后的坐标,但你需要它们的值,正如你所说,它们将是分数像素。由您决定最佳的插值方法。一种方法是仅使用最近像素(也称为最近邻居)的值。线性插值通常会给出更好的结果 - 获取相邻像素并将它们相加,并根据它们与目标坐标的接近程度进行加权。如果结果不令人满意,我只会使用高阶插值方法。
您提出的方法的替代方法是使用
imrotate
将图像旋转 45 度进行变换,然后计算您感兴趣的列中垂直像素的线积分(总和)。I would use
meshgrid
to produce a coordinate system for the image. You can rotate this coordinate system by matrix-multiplication with a rotation matrix. This should give you transformed coordinates, but you need values from them and as you said they will be fractional pixels. It's up to you to determine the best way to interpolate. One method is to just use the value of the nearest pixel (aka nearest neighbor). Linear interpolation will typically give a better result - take the neighboring pixels and sum them up, weighted by how close they are to your target coordinate. I would only bother with higher-order interpolation methods if the results are unsatisfactory.An alternative to your proposed method would be to use
imrotate
to transform the image with a 45-degree rotation, then calculate the line integral (sum) of the vertical pixels in the column you are interested in.