C# 使用c语言将鱼眼图像转换为风景并将其分为四个部分#
我有一个鱼眼图像,我想做的是把它转换成风景。 我编写的代码将其转换为横向,但当涉及到将其划分为不同的部分时,会添加黑色部分 有人能帮忙吗C# 使用c语言将鱼眼图像转换为风景并将其分为四个部分#,c#,image-processing,C#,Image Processing,我有一个鱼眼图像,我想做的是把它转换成风景。 我编写的代码将其转换为横向,但当涉及到将其划分为不同的部分时,会添加黑色部分 有人能帮忙吗 using System; using System.Drawing; namespace fisheye_image { class Program { static void Main() { // assume the source image is square, and its
using System;
using System.Drawing;
namespace fisheye_image
{
class Program
{
static void Main()
{
// assume the source image is square, and its width has even number of pixels
Bitmap bm = (Bitmap)Image.FromFile(@"C:\Users\abc\Desktop\lillestromfisheye.jpg");
int l = bm.Width / 2;
int i, j;
int x, y;
double radius, theta;
// calculated indices in Cartesian coordinates with trailing decimals
double fTrueX, fTrueY;
int iSourceWidth = (2 * l);
int run = 0, lastWidth = 1;
while (run<4)
{
Bitmap bmDestination = new Bitmap(lastWidth*l, l);
for (i = 0; i < bmDestination.Height; ++i)
{
radius = (double)(l - i);
for (j = run*l; j < lastWidth*l ; ++j)
{
// theta = 2.0 * Math.PI * (double)(4.0 * l - j) / (double)(4.0 * l);
theta = 2.0 * Math.PI * (double)(-j) / (double)(4.0 * l);
fTrueX = radius * Math.Cos(theta);
fTrueY = radius * Math.Sin(theta);
// "normal" mode
x = (int)(Math.Round(fTrueX)) + l;
y = l - (int)(Math.Round(fTrueY));
// check bounds
if (x >= 0 && x < iSourceWidth && y >= 0 && y < iSourceWidth)
{
bmDestination.SetPixel(j, i, bm.GetPixel(x, y));
}
}
}
bmDestination.Save(@"C:\Users\abc\Desktop\fisheyelandscape"+run.ToString()+".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
run++;
lastWidth++;
}
}
}
}
使用系统;
使用系统图;
名称空间鱼眼图像
{
班级计划
{
静态void Main()
{
//假设源图像是正方形的,其宽度有偶数个像素
位图bm=(位图)Image.FromFile(@“C:\Users\abc\Desktop\lillestromfisheye.jpg”);
int l=bm.宽度/2;
int i,j;
int x,y;
双半径θ;
//笛卡尔坐标系下带尾随小数的计算指数
双fTrueX,fTrueY;
int iSourceWidth=(2*l);
int run=0,lastWidth=1;
而(运行=0&&x=0&&y
以下是原始图像和处理后的图像
我们只需要在第二个for循环中添加另一个变量“k”,该变量从零到目标图像的宽度
while (run<4)
{
Bitmap bmDestination = new Bitmap(l, l);
for (i = 0; i < bmDestination.Height; ++i)
{
radius = (double)(l - i);
for (j = run * l, k = 0; j < lastWidth * l||k < bmDestination.Width; ++j, ++k)
{
// theta = 2.0 * Math.PI * (double)(4.0 * l - j) / (double)(4.0 * l);
theta = 2.0 * Math.PI * (double)(-j) / (double)(4.0 * l);
fTrueX = radius * Math.Cos(theta);
fTrueY = radius * Math.Sin(theta);
// "normal" mode
x = (int)(Math.Round(fTrueX)) + l;
y = l - (int)(Math.Round(fTrueY));
// check bounds
if (x >= 0 && x < iSourceWidth && y >= 0 && y < iSourceWidth)
{
bmDestination.SetPixel(k, i, bm.GetPixel(x, y));
}
}
while(run=0&&x=0&&y