public void Harris(Bitmap bmp, Bitmap bmp2) { HarrisInfo hi = new HarrisInfo(); Bitmap temp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); //Laplace(bmp, temp); Laplace(bmp, temp); //double [,] temp = new double[bmp.Height,bmp.Width]; double[] dx2 = new double[bmp.Width * bmp.Height]; double[] dy2 = new double[bmp.Width * bmp.Height]; double[] dxy = new double[bmp.Width * bmp.Height]; double [] harrMap = new double[bmp.Width * bmp.Height]; Rectangle rect = new Rectangle(0, 0, temp.Width, temp.Height); System.Drawing.Imaging.BitmapData data = temp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, temp.PixelFormat); Rectangle rect2 = new Rectangle(0, 0, bmp2.Width, bmp2.Height); System.Drawing.Imaging.BitmapData data2 = bmp2.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp2.PixelFormat); //double max = -0000000.1; SortedList <double, double> sList = new SortedList <double, double>(); unsafe { byte *imgPtr = (byte *)(data.Scan0); byte *imgPtr2 = (byte *)(data2.Scan0); fixed(double *fpdx2 = dx2) fixed(double *fpdy2 = dy2) fixed(double *fpdxy = dxy) fixed(double *fharrMap = harrMap) { double *pdx2 = fpdx2; double *pdy2 = fpdy2; double *pdxy = fpdxy; double *ph = fharrMap; double tx, ty; for (int y = 0; y < data.Height - 2; y++) { for (int x = 0; x < data.Width - 2; x++) { tx = *(imgPtr + 2); tx += *(imgPtr + data.Width + 2); tx += *(imgPtr + data.Width * 2 + 2); tx = *(imgPtr); tx -= *(imgPtr + data.Width); tx -= *(imgPtr + data.Width * 2); tx /= 6; ty = *(imgPtr + data.Width * 2); ty += *(imgPtr + data.Width * 2 + 1); ty += *(imgPtr + data.Width * 2 + 2); ty -= *(imgPtr); ty -= *(imgPtr + 1); ty -= *(imgPtr + 2); ty /= 6; *(pdx2 + data.Width + 1) = tx * tx; *(pdy2 + data.Width + 1) = ty * ty; *(pdxy + data.Width + 1) = tx * ty; pdx2++; pdy2++; pdxy++; imgPtr++; } imgPtr += data.Stride - data.Width + 2; pdx2 += 2; pdy2 += 2; pdxy += 2; } pdx2 = fpdx2; pdy2 = fpdy2; pdxy = fpdxy; pdx2 += data.Width; pdy2 += data.Width; pdxy += data.Width; ph += data.Width; for (int y = 1; y < data.Height - 1; y++) { pdx2++; pdy2++; pdxy++; ph++; for (int x = 1; x < data.Width - 1; x++) { double d = (*pdx2 * *pdy2 - 2 * *pdxy) - 0.04 * (*pdx2 + *pdy2) * (*pdx2 + *pdy2); if (d < hi._Min) { hi._Min = d; } if (hi._Max < d) { hi._Max = d; } *ph = d; pdx2++; pdy2++; pdxy++; ph++; } pdx2++; pdy2++; pdxy++; ph++; } double scale = (255 - 0) / (hi._Max - hi._Min); double shift = -hi._Min * scale + 0; ph = fharrMap; ph += data.Width; imgPtr2 += data2.Stride; for (int y = 1; y < data.Height - 1; y++) { imgPtr2++; ph++; for (int x = 1; x < data.Width - 1; x++) { *imgPtr2 = (byte)((*ph) * scale + shift); imgPtr2++; ph++; } imgPtr2 += data2.Stride - data.Width + 1; ph++; } } } // Unlock the bits. temp.UnlockBits(data); bmp2.UnlockBits(data); // Draw the modified image. }
public void Harris(Bitmap bmp, Bitmap bmp2) { HarrisInfo hi = new HarrisInfo(); Bitmap temp = new Bitmap(bmp.Width,bmp.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); //Laplace(bmp, temp); Laplace(bmp, temp); //double [,] temp = new double[bmp.Height,bmp.Width]; double[] dx2 = new double[bmp.Width * bmp.Height]; double[] dy2 = new double[bmp.Width * bmp.Height]; double[] dxy = new double[bmp.Width * bmp.Height]; double [] harrMap = new double[bmp.Width * bmp.Height]; Rectangle rect = new Rectangle(0, 0, temp.Width, temp.Height); System.Drawing.Imaging.BitmapData data = temp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, temp.PixelFormat); Rectangle rect2 = new Rectangle(0, 0, bmp2.Width, bmp2.Height); System.Drawing.Imaging.BitmapData data2 = bmp2.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp2.PixelFormat); //double max = -0000000.1; SortedList<double, double> sList = new SortedList<double, double>(); unsafe { byte* imgPtr = (byte*)(data.Scan0); byte* imgPtr2 = (byte*)(data2.Scan0); fixed (double* fpdx2 = dx2) fixed (double* fpdy2 = dy2) fixed (double* fpdxy = dxy) fixed (double* fharrMap = harrMap) { double* pdx2 = fpdx2; double* pdy2 = fpdy2; double* pdxy = fpdxy; double* ph = fharrMap; double tx ,ty; for (int y = 0; y < data.Height - 2; y++) { for (int x = 0; x < data.Width - 2; x++) { tx = *(imgPtr +2); tx += *(imgPtr + data.Width + 2); tx += *(imgPtr + data.Width*2 + 2); tx = *(imgPtr ); tx -= *(imgPtr + data.Width ); tx -= *(imgPtr + data.Width *2); tx /= 6; ty = *(imgPtr + data.Width*2 ); ty += *(imgPtr + data.Width*2 +1 ); ty += *(imgPtr + data.Width *2+ 2); ty -= *(imgPtr ); ty -= *(imgPtr + 1); ty -= *(imgPtr + 2); ty /= 6; *(pdx2 + data.Width +1) = tx * tx; *(pdy2 + data.Width +1)= ty * ty; *(pdxy + data.Width +1)= tx * ty; pdx2++; pdy2++; pdxy++; imgPtr++; } imgPtr += data.Stride - data.Width + 2; pdx2 +=2; pdy2 +=2; pdxy +=2; } pdx2 = fpdx2; pdy2 = fpdy2; pdxy = fpdxy; pdx2 += data.Width; pdy2 += data.Width; pdxy += data.Width; ph += data.Width; for (int y = 1; y < data.Height - 1; y++) { pdx2++; pdy2++; pdxy++; ph++; for (int x = 1; x < data.Width - 1; x++) { double d = (*pdx2 * *pdy2 - 2 * *pdxy) - 0.04 * (*pdx2 + *pdy2) * (*pdx2 + *pdy2); if( d < hi._Min ) hi._Min = d ; if (hi._Max < d) hi._Max = d ; *ph = d; pdx2++; pdy2++; pdxy++; ph++; } pdx2++; pdy2++; pdxy++; ph++; } double scale = (255 - 0)/(hi._Max-hi._Min); double shift = -hi._Min * scale + 0; ph = fharrMap; ph += data.Width; imgPtr2 += data2.Stride; for (int y = 1; y < data.Height - 1; y++) { imgPtr2++; ph++; for (int x = 1; x < data.Width - 1; x++) { *imgPtr2 = (byte)((*ph )* scale + shift); imgPtr2++; ph++; } imgPtr2 += data2.Stride - data.Width + 1; ph++; } } } // Unlock the bits. temp.UnlockBits(data); bmp2.UnlockBits(data); // Draw the modified image. }