Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private double Grayscale(Color c)
- {
- return (double)(c.R + c.G + c.B / 3;
- }
- private void button14_Click(object sender, EventArgs e)
- {
- int template_size = workImageCorelatie.Width * workImageCorelatie.Height;
- double sum = 0;
- double sqrsum = 0;
- workImage.Lock();
- workImageCorelatie.Lock();
- for (int i = 0; i < workImageCorelatie.Width; i++)
- {
- for (int j = 0; j < workImageCorelatie.Height; j++)
- {
- double template = Grayscale(workImageCorelatie.GetPixel(i, j));
- sum += template;
- sqrsum += template * template;
- }
- }
- double mean_template = sum / template_size;
- double var2template = sqrsum - (sum * sum) / template_size;
- double var2image = 0;
- double prodsum = 0;
- double[,] corr_coeff = new double[workImage.Width, workImage.Height];
- for (int i = 0; i < workImage.Width - workImageCorelatie.Width; i++)
- {
- for (int j = 0; j < workImage.Height - workImageCorelatie.Height; j++)
- {
- sum = 0;
- sqrsum = 0;
- prodsum = 0;
- for (int k = 0; k < workImageCorelatie.Width; k++)
- for (int m = 0; m < workImageCorelatie.Height; m++)
- {
- double img = Grayscale(workImage.GetPixel(i + k, j + m));
- double template = Grayscale(workImageCorelatie.GetPixel(k, m));
- sum += img;
- sqrsum += img * img;
- prodsum += img * template;
- }
- var2image = sqrsum - (sum * sum) / template_size;
- corr_coeff[i, j] = ((prodsum - (mean_template * sum)) / Math.Sqrt(var2image * var2template));
- }
- }
- //cauti maximul in matrice
- double max = Double.NegativeInfinity;
- int imax = 0, jmax = 0;
- for (int i = 0; i < workImage.Width - workImageCorelatie.Width; i++)
- for (int j = 0; j < workImage.Height - workImageCorelatie.Height; j++)
- if (max < corr_coeff[i, j])
- {
- max = corr_coeff[i, j];
- imax = i;
- jmax = j;
- }
- // desenezi liniile de pe poza mare
- for (int i = 0; i < workImageCorelatie.Width; i++)
- {
- workImage.SetPixel(imax + i, jmax, Color.Blue);
- workImage.SetPixel(imax + i, jmax + workImageCorelatie.Height, Color.Blue);
- }
- for (int j = 0; j < workImageCorelatie.Height; j++)
- {
- workImage.SetPixel( imax, jmax + j, Color.Blue);
- workImage.SetPixel( imax + workImageCorelatie.Width, jmax + j, Color.Blue);
- }
- panelDestination.BackgroundImage = null;
- panelDestination.BackgroundImage = workImage.GetBitMap();
- workImage.Unlock();
- workImageCorelatie.Unlock();
- }
- private void button15_Click(object sender, EventArgs e)
- {
- openFileDialog.ShowDialog();
- sSourceFileNameCorelatie = openFileDialog.FileName;
- imageCorelatie = new Bitmap(sSourceFileNameCorelatie);
- workImageCorelatie = new FastImage(imageCorelatie);
- panelDestination.BackgroundImage = workImageCorelatie.GetBitMap();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement