Перевод из C в C#. Операция математической морфологии «Расширение» (Dilation)
Формулировка задачи:
Доброго времени суток! Пожалуйста помогите перевести из C в C#. Подчеркнутое, это то что вызывает затруднение. Буду рад любой помощи. Спасибо!
Решение задачи: «Перевод из C в C#. Операция математической морфологии «Расширение» (Dilation)»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net;
using System.Windows.Forms;
namespace WindowsFormsApplication344
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var img = (Bitmap)Image.FromStream(new WebClient { Proxy = null }.OpenRead("http://homepages.inf.ed.ac.uk/rbf/HIPR2/images/art2ldv1.gif"));
img.SetResolution(96, 96);
var res = Delation(img, 1);
new PictureBox { Parent = this, Image = img, SizeMode = PictureBoxSizeMode.AutoSize};
new PictureBox { Parent = this, Image = res, SizeMode = PictureBoxSizeMode.AutoSize, Left = img.Width + 15 };
}
Image Delation(Image bmp, int N)
{
var result = new Bitmap(bmp.Width, bmp.Height);
using (var g = Graphics.FromImage(result))
g.DrawImage(bmp, Point.Empty);
using (var wr = new ImageWrapper(result))
foreach(var p in wr)
{
var max = 0;
for(int i = -N;i<=N;i++)
for(int j = -N;j<=N;j++)
{
var v = wr[p.X + i, p.Y + j].G;
if (v > max)
max = v;
}
wr.SetPixel(p, max, max, max);
}
return result;
}
}
}