void im_Click(object sender, EventArgs e) { ImageMagnifier.ImageMagnifier im = (ImageMagnifier.ImageMagnifier)sender; this.nnState.ImageToMagnify = im.ImageToMagnify; Form2 form2 = new Form2(); form2.ShowDialog(); Random rng = new Random(); int j = 0, k = 0; for (int i = 0; i < form2.scrambleLevel; i++) { j = rng.Next(imageSize); k = rng.Next(imageSize); if (nnState.pixels[j, k] == Color.Black.ToArgb()) { nnState.pixels[j, k] = Color.White.ToArgb(); } else if (nnState.pixels[j, k] == Color.White.ToArgb()) { nnState.pixels[j, k] = Color.Black.ToArgb(); } } selectedAPattern = true; nnState.Invalidate(); }
void im_Click(object sender, EventArgs e) { ImageMagnifier.ImageMagnifier im = (ImageMagnifier.ImageMagnifier)sender; this.imNNState.ImageToMagnify = im.ImageToMagnify; frmAddDistortion frmaddDistortion = new frmAddDistortion(); frmaddDistortion.ShowDialog(); Random r = new Random(); int p = 0; int k = 0; for (int i = 0; i < frmaddDistortion.DistortionLevel; i++) { p = r.Next(imageDim); k = r.Next(imageDim); if (imNNState.pixels[k, p] == Color.Black.ToArgb()) { imNNState.pixels[k, p] = Color.White.ToArgb(); } else if (imNNState.pixels[k, p] == Color.White.ToArgb()) { imNNState.pixels[k, p] = Color.Black.ToArgb(); } } lblEnergy.Text = "0"; patternSelected = true; imNNState.Invalidate(); }
private void AddPatternBut_Click(object sender, EventArgs e) { Image imgPattern; if (ofd.ShowDialog() == DialogResult.OK) { imgPattern = Image.FromFile(ofd.FileName); if (imgPattern.Width != imageDim || imgPattern.Height != imageDim) { MessageBox.Show("Image size must be " + imageDim.ToString() + "x" + imageDim.ToString() + " pixels", "Wrong image size", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int[,] patternPixels; int p = 0; int midColor = Math.Abs((int)(Color.Black.ToArgb() / 2)); Bitmap b = new Bitmap(imgPattern); patternPixels = new int[imageDim, imageDim]; List <Neuron> pattern = new List <Neuron>(imageDim * imageDim); for (int i = 0; i < imageDim; i++) { for (int j = 0; j < imageDim; j++) { Neuron n = new Neuron(); p = Math.Abs(b.GetPixel(i, j).ToArgb()); if (p < midColor) { b.SetPixel(i, j, Color.White); n.State = NeuronStates.AlongField; } else { b.SetPixel(i, j, Color.Black); n.State = NeuronStates.AgainstField; } pattern.Add(n); } } NN.AddPattern(pattern); ImageMagnifier.ImageMagnifier im = new ImageMagnifier.ImageMagnifier(); im.ImageToMagnify = b; im.MagnificationCoefficient = 8; im.Location = new System.Drawing.Point(1, ((NN.M - 1) * (imageDim + 2) * im.MagnificationCoefficient)); im.Size = new System.Drawing.Size(imageDim * im.MagnificationCoefficient, imageDim * im.MagnificationCoefficient); im.TabIndex = 0; im.Click += new EventHandler(im_Click); panelStoredImages.Controls.Add(im); butRunDynamics.Enabled = true; UpdatePropertiesPB(); } } }
private void AddPatternBut_Click(object sender, EventArgs e) { Image imgPattern; if (ofd.ShowDialog() == DialogResult.OK) { imgPattern = Image.FromFile(ofd.FileName); if (imgPattern.Width != imageDim || imgPattern.Height != imageDim) { MessageBox.Show("Image size must be " + imageDim.ToString() + "x" + imageDim.ToString() + " pixels", "Wrong image size", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int[,] patternPixels; int p = 0; int midColor = Math.Abs((int)(Color.Black.ToArgb() / 2)); Bitmap b = new Bitmap(imgPattern); patternPixels = new int[imageDim, imageDim]; List<Neuron> pattern = new List<Neuron>(imageDim * imageDim); for (int i = 0; i < imageDim; i++) for (int j = 0; j < imageDim; j++) { Neuron n = new Neuron(); p = Math.Abs(b.GetPixel(i, j).ToArgb()); if (p < midColor) { b.SetPixel(i, j, Color.White); n.State = NeuronStates.AlongField; } else { b.SetPixel(i, j, Color.Black); n.State = NeuronStates.AgainstField; } pattern.Add(n); } NN.AddPattern(pattern); ImageMagnifier.ImageMagnifier im = new ImageMagnifier.ImageMagnifier(); im.ImageToMagnify = b; im.MagnificationCoefficient = 8; im.Location = new System.Drawing.Point(1, ((NN.M - 1) * (imageDim + 2) * im.MagnificationCoefficient)); im.Size = new System.Drawing.Size(imageDim * im.MagnificationCoefficient, imageDim * im.MagnificationCoefficient); im.TabIndex = 0; im.Click += new EventHandler(im_Click); panelStoredImages.Controls.Add(im); butRunDynamics.Enabled = true; UpdatePropertiesPB(); } } }
private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { Bitmap b = new Bitmap(openFileDialog1.FileName); int p = 0; int divider = Math.Abs((int)(Color.Black.ToArgb() / 2)); List <Neuron> neuralnet = new List <Neuron>(imageSize * imageSize); for (int i = 0; i < imageSize; i++) { for (int j = 0; j < imageSize; j++) { Neuron n = new Neuron(); p = Math.Abs(b.GetPixel(i, j).ToArgb()); if (p < divider) { b.SetPixel(i, j, Color.White); n.State = NeuronStates.AlongField; } else { b.SetPixel(i, j, Color.Black); n.State = NeuronStates.AgainstField; } neuralnet.Add(n); } } NN.AddPattern(neuralnet); ImageMagnifier.ImageMagnifier im = new ImageMagnifier.ImageMagnifier(); im.MagnificationCoefficient = 6; im.ImageToMagnify = b; im.Location = new System.Drawing.Point(13, ((NN.M - 1) * (imageSize + 2) * im.MagnificationCoefficient)); im.Size = new System.Drawing.Size(10 * im.MagnificationCoefficient, imageSize * im.MagnificationCoefficient); im.TabIndex = 0; im.Click += new EventHandler(im_Click); patternspanel.Controls.Add(im); runbtn.Enabled = true; }