public static ImageData GetImageData(Bitmap img) { ImageData imgData = new ImageData(); using (Bitmap resized = Resize(img)) { float[] cedd = Features.calculateCEDD(img); // size 144 float[] fcth = Features.calculateFCTH(img); // size 192 float[] jcd = Features.calculateJCD(cedd, fcth); // size 168 imgData.CEDD = cedd; imgData.FCTH = fcth; imgData.JCD = jcd; // Change the feature to be used in SOM here. // Important!!! Also need to adject SOM constants in SOMSetting.cs (especially NUM_WEIGHTS) imgData.inputVector.weights = jcd; } return imgData; }
public static ImageData GetImageData_Old(Bitmap img) { ImageData result = new ImageData(); BitmapData imgData = img.LockBits( new Rectangle( 0, 0, img.Width, img.Height ), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb ); Features.rgbColor[,] imgArray = new Features.rgbColor[imgData.Height, imgData.Width]; unsafe { byte* imgPtr = (byte*)(imgData.Scan0); for (int i = 0; i < imgData.Height; ++i) { for (int j = 0; j < imgData.Width; ++j) { imgArray[i, j].b = (float)*imgPtr; ++imgPtr; imgArray[i, j].g = (int)*imgPtr; ++imgPtr; imgArray[i, j].r = (int)*imgPtr; ++imgPtr; } imgPtr += imgData.Stride - imgData.Width * 3; } } // End unsafe code. // Needed or else RELEASE build will crash! eep! img.UnlockBits(imgData); float[] histogramVector, areaVector; histogramVector = result.m_vectorHistogram = Features.calculateInputVector_Histogram(imgArray, imgData.Height, imgData.Width); areaVector = result.m_vectorArea = Features.calculateInputVector_Area(imgArray, imgData.Height, imgData.Width); System.Diagnostics.Debug.Assert(histogramVector.Length + areaVector.Length == SOMConstants.NUM_WEIGHTS); // Pack all vectors into the single vector. for (int i = 0, j = 0; i < SOMConstants.NUM_WEIGHTS; ++i) { if (i < histogramVector.Length) { result.inputVector.weights[i] = histogramVector[i]; } else if (j < areaVector.Length) { result.inputVector.weights[i] = areaVector[j]; ++j; } } return result; }
public void AddImage(ImageData imageData) { _imageDataList.Add(imageData); }