Анализ яркостного и цветового профиля строк - C#
Формулировка задачи:
подскажите плиз скрипт как извлечь из целого изображения строку с показателями яркости и цветности.
Решение задачи: «Анализ яркостного и цветового профиля строк»
textual
Листинг программы
using System;
using System.Drawing;
using System.Net;
using System.Windows.Forms;
namespace WindowsFormsApplication327
{
public partial class Form1 : Form
{
private Image img;
private Cells cells;
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
img = Image.FromStream(new WebClient {Proxy = null}.OpenRead("https://upload.wikimedia.org/wikipedia/ru/2/24/Lenna.png"));
cells = new Cells();
Application.Idle += delegate{ cells.Update(); Invalidate();};
}
protected override void OnPaint(PaintEventArgs e)
{
var dx = img.Width/cells.ColCount;
var dy = img.Height/cells.RowCount;
var di = Width/cells.ColCount;
var dj = Height/cells.RowCount;
for (int i = 0; i < cells.ColCount; i++)
for (int j = 0; j < cells.RowCount; j++)
e.Graphics.DrawImage(img,
new Rectangle(i * di, j * dj, di, dj),
new Rectangle(cells[i, j].X * dx, cells[i, j].Y * dy, dx, dy),
GraphicsUnit.Pixel);
}
}
class Cells
{
private Point[,] Items;
private static Random rnd = new Random();
public int ColCount { get { return Items.GetLength(0); } }
public int RowCount { get { return Items.GetLength(1); } }
public Cells(int cols = 50, int rows = 50)
{
Items = new Point[cols, rows];
Update();
}
public Point this[int col, int row]
{
get { return Items[col, row]; }
}
public void Update()
{
for (int i = 0; i < ColCount; i++)
for (int j = 0; j < RowCount; j++)
{
if (Items[i, j].X != i) Items[i, j].X = rnd.Next(ColCount);
if (Items[i, j].Y != j) Items[i, j].Y = rnd.Next(RowCount);
}
}
}
}