从笛卡尔坐标系转换为极坐标系的图像转换

3
我想知道如何将顶部图片转换为底部图片。这些图片可以在以下链接中找到。顶部图片是笛卡尔坐标系下的,底部图片是极坐标系下的转换后的图片。
1个回答

3
这是一个基本的矩形到极坐标转换。为了进行转换,扫描输出图像并将x和y视为r和theta。然后将它们用作r和theta来查找输入图像中相应的像素。因此,类似于以下内容:
int x, y;
for (y = 0; y < outputHeight; y++)
{
    Pixel* outputPixel = outputRowStart (y); // <- get a pointer to the start of the output row
    for (x = 0; x < outputWidth; x++)
    {
        float r = y;
        float theta = 2.0 * M_PI * x / outputWidth;
        float newX = r * cos (theta);
        float newY = r * sin (theta);
        *outputPixel = getInputPixel ( newX, newY ); // <- Should probably do at least bilinear resampling in this function
        outputPixel++;
    }
}

请注意,根据您想要实现的目标,您可能需要处理换行。theta值在2pi处换行。

你能帮我一个大忙,用MATLAB写代码吗?我不熟悉C++。 - John
+1 @John,当你提出问题时,最好指定语言。无论如何,如果你删除float这个词,剩下的基本上就是你需要的公式了。 - user1693593
1
@rep_movsd 我搞砸了。那些应该传递给 getInputPixel()。谢谢你发现了这个问题!我已经更新了代码。 - user1118321

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接