/// <summary> /// Get the histogram of a specific area of the image. /// The histogram is separate for each color channel /// </summary> /// <param name="image"></param> /// <param name="Min"></param> /// <param name="Max"></param> /// <param name="lines"></param> /// <returns></returns> public static FxVector<float>[] GetHistogram(FxImages image, FxVector2i Min, FxVector2i Max) { FxVector<float>[] hist = new FxVectorF[image.FXPixelFormat.Length]; for (int i = 0; i < image.FXPixelFormat.Length; i++) { hist[i] = new FxVectorF(256,0); } int pixelCount = 0; // lock the input memory //image.LockImage(); for (int i = Min.X; i < Max.X; i++) { for (int j = Min.Y; j < Max.Y; j++) { for (int g = 0; g < image.FXPixelFormat.Length; g++) { hist[g][image[i, j, (RGB)g]]++; } // count the pixels pixelCount++; } } // unlock the input and output image //image.UnLockImage(); // normalize the image for (int i = 0; i < image.FXPixelFormat.Length; i++) { hist[i].Divide(pixelCount); } return hist; }
/// <summary> /// Fill Circle /// </summary> /// <param name="Center"></param> /// <param name="Radius"></param> /// <param name="Value"></param> public void FillCircle(Vector.FxVector2f center, float radius, float Value) { // Create a rectangle that we are going to fill FxVector2i StartVect = new FxVector2i(center.x - radius, center.y - radius); FxVector2i EndVect = new FxVector2i(center.x + radius, center.y + radius); for (int x = StartVect.x; x < EndVect.x; x++) for (int y = StartVect.y; y < EndVect.y; y++) { if (x >= 0 && x < Width && y >= 0 && y < Height) { float dist = center.Distance(x, y); if (dist < radius) { float a = (radius - dist) / radius; this[x, y] = a * Value; } } } }