Нужно просканировать изображение и по RGB составляющим построить график, далее определить на графике(это и есть значение RGB) все локальные минимумы-это сделано, после этого надо работать с локальным минимумом, т. е. допустим по R значению у нас получилось 10, надо промежутки от одного до другого локального минимума окрашивать на картинки цветами получившимся именно в точке локального минимума. В прикрепленном файле общее задание. | Код | public partial class Form3 : Form { private int[] R = new int[256]; private int[] G = new int[256]; private int[] B = new int[256]; public Form3() { InitializeComponent(); CenterToScreen(); } public void GetValues(Bitmap image) { for (int i = 0; i < image.Width; i++) for (int j = 0; j < image.Height; j++) { R[image.GetPixel(i, j).R]++; G[image.GetPixel(i, j).G]++; B[image.GetPixel(i, j).B]++; } } private int[] Smoothing(int[] arr,int n) { int[] mas = new int[arr.Length]; //int n = 10; for (int i = 0; i < arr.Length; i++) { int sum = 0; for (int j = -n / 2; j < n / 2; j++) { if ((i + j) < 0 || (i + j) >= arr.Length) continue; sum += arr[i + j]; } mas[i] = sum / n; } return mas; } public List<int> LocalMin(int[] mas) { List<int> list = new List<int>(); for (int i = 2; i < mas.Length - 2; i++) { if (mas[i] < mas[i - 2] && mas[i] < mas[i + 2]) list.Add(i); } return list; } PointPairList Red = new PointPairList(); PointPairList Green = new PointPairList(); PointPairList Blue = new PointPairList(); PointPairList lst = new PointPairList(); List<int> lMinR = new List<int>(); List<int> lMinG = new List<int>(); List<int> lMinB = new List<int>(); int[] newR = new int[256]; int[] newG = new int[256]; int[] newB = new int[256]; public void BuildHisto(Bitmap image,int n) { GraphPane myPane = zedGraph.GraphPane; myPane.Title.Text = "Гистограмма изображения"; myPane.XAxis.Title.Text = "Значение RGB состовлющей"; myPane.YAxis.Title.Text = "Количество пикселей"; newR = Smoothing(R,n); newG = Smoothing(G,n); newB = Smoothing(B,n);
lMinR = LocalMin(newR); label5.Text = lMinR.Count.ToString(); //for (int i = 0; i < lMin.Count; i++) //{ // lst.Add(lMin[i], newR[lMin[i]] * 100); //} for (int x = 0; x < 255; x++) { Red.Add(x, newR[x]); //myPane.AddStick("", lst, Color.Red); }
lMinG = LocalMin(newG); label6.Text = lMinG.Count.ToString(); for (int x = 0; x < 255; x++) { Green.Add(x, newG[x]); }
lMinB = LocalMin(newB); label7.Text = lMinB.Count.ToString(); for (int x = 0; x < 255; x++) { Blue.Add(x, newB[x]); } LineItem lines = myPane.AddCurve("Red", Red, Color.Red,SymbolType.None); lines = myPane.AddCurve("Green", Green, Color.Green,SymbolType.None); lines = myPane.AddCurve("Blue", Blue, Color.Blue,SymbolType.None); myPane.XAxis.MajorGrid.IsVisible = true; myPane.XAxis.Scale.MinAuto = true; myPane.XAxis.Scale.MaxAuto = true; myPane.YAxis.MajorGrid.IsVisible = true; myPane.YAxis.Scale.MinAuto = true; myPane.YAxis.Scale.MaxAuto = true; myPane.XAxis.IsVisible = true; myPane.YAxis.IsVisible = true; myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); zedGraph.ZoomEvent += new ZedGraphControl.ZoomEventHandler(zedGraph_ZoomEvent); zedGraph.AxisChange(); zedGraph.Invalidate(); }
void zedGraph_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState) { //throw new Exception("The method or operation is not implemented."); }
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { GraphPane myPane = zedGraph.GraphPane; newR = Smoothing(R, (int)numericUpDown1.Value); newG = Smoothing(G, (int)numericUpDown1.Value); newB = Smoothing(B, (int)numericUpDown1.Value); Red.Clear(); lMinR.Clear(); lMinR = LocalMin(newR); label5.Text = lMinR.Count.ToString(); for (int x = 0; x < 255; x++) { Red.Add(x, newR[x]); }
Green.Clear(); lMinG.Clear(); lMinG = LocalMin(newG); label6.Text = lMinG.Count.ToString(); for (int x = 0; x < 255; x++) { Green.Add(x, newG[x]); } Blue.Clear(); lMinB.Clear(); lMinB = LocalMin(newB); label7.Text = lMinB.Count.ToString(); for (int x = 0; x < 255; x++) { Blue.Add(x, newB[x]); } myPane.CurveList.Clear(); LineItem lines = myPane.AddCurve("Red", Red, Color.Red, SymbolType.None); lines = myPane.AddCurve("Green", Green, Color.Green, SymbolType.None); lines = myPane.AddCurve("Blue", Blue, Color.Blue, SymbolType.None); zedGraph.AxisChange(); zedGraph.Invalidate(); }
}
|
Присоединённый файл ( Кол-во скачиваний: 17 )
DSP_Lab2.doc 20,00 Kb
|