private void Preparation1_Click(object sender, RoutedEventArgs e) { double coeff = (_settings.Gmax - _settings.Gmin) / 255; int height = _sourceBitmapImage.PixelHeight; int width = _sourceBitmapImage.PixelWidth; Bitmap bitmap = BitmapImage2Bitmap(_sourceBitmapImage); for (int i = 0; i < height; i++) { for(int j = 0; j < width; j++) { var hsv = new HSV(bitmap.GetPixel(j, i)); hsv.Value = hsv.Value * coeff + _settings.Gmin / 255; bitmap.SetPixel(j, i, hsv.HSVToColor()); } } bitmap.Save(@"D:\123.jpg"); Image2.Source = Bitmap2BitmapImage(bitmap); AddValuesToChart(ProcessedChartValues, Image2.Source as BitmapImage); }
private unsafe void DrawColorRange() { HSV hSV = new HSV(0.0, 1.0, 1.0); BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); int num = Image.GetPixelFormatSize(bmp.PixelFormat) / 8; int height = bitmapData.Height; int num2 = bitmapData.Width * num; byte * ptr = (byte *)(void *)bitmapData.Scan0; for (int i = 0; i < height; i++) { byte *ptr2 = ptr + i * bitmapData.Stride; for (int j = 0; j < num2; j += num) { hSV.SetHue((double)(j / num)); Color color = hSV.ToRGB(); ptr2[j] = color.B; ptr2[j + 1] = color.G; ptr2[j + 2] = color.R; } } bmp.UnlockBits(bitmapData); }
private void AddValuesToChart(ObservableCollection <ChartValue> chartValues, BitmapImage bitmapImage) { Bitmap bitmap = BitmapImage2Bitmap(bitmapImage); var mas = new int[256]; int width = bitmapImage.PixelWidth; int height = bitmapImage.PixelHeight; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { double val = new HSV(bitmap.GetPixel(j, i)).Value; int idx = (int)(val * 255); mas[idx]++; } } chartValues.Clear(); for (int i = 0; i < mas.Length; i++) { chartValues.Add(new ChartValue(i, mas[i])); } }
private void Preparation1_Click(object sender, RoutedEventArgs e) { double coeff = (_settings.Gmax - _settings.Gmin) / 255; int height = _sourceBitmapImage.PixelHeight; int width = _sourceBitmapImage.PixelWidth; Bitmap bitmap = BitmapImage2Bitmap(_sourceBitmapImage); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { var hsv = new HSV(bitmap.GetPixel(j, i)); hsv.Value = hsv.Value * coeff + _settings.Gmin / 255; bitmap.SetPixel(j, i, hsv.HSVToColor()); } } bitmap.Save(@"D:\123.jpg"); Image2.Source = Bitmap2BitmapImage(bitmap); AddValuesToChart(ProcessedChartValues, Image2.Source as BitmapImage); }
private void OpRoberts_Click(object sender, RoutedEventArgs e) { int height = _sourceBitmapImage.PixelHeight; int width = _sourceBitmapImage.PixelWidth; Bitmap bitmap = BitmapImage2Bitmap(_sourceBitmapImage); Bitmap newBitmap = BitmapImage2Bitmap(_sourceBitmapImage); for (int i = 0; i < height - 1; i++) { for (int j = 0; j < width - 1; j++) { HSV hsv = GetRobertsPixel(new HSV(bitmap.GetPixel(j, i)), new HSV(bitmap.GetPixel(j + 1, i)), new HSV(bitmap.GetPixel(j, i + 1)), new HSV(bitmap.GetPixel(j + 1, i + 1))); newBitmap.SetPixel(j, i, hsv.HSVToColor()); } } newBitmap.Save(@"D:\123.jpg"); Image2.Source = Bitmap2BitmapImage(newBitmap); AddValuesToChart(ProcessedChartValues, Image2.Source as BitmapImage); }
/// <summary> /// Draws all degrees of hue to the bitmap. /// </summary> private void DrawColorRange() { HSV colorHSV = new HSV(0, 1, 1); Color colorRGB; unsafe { BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(bmp.PixelFormat) / 8; int heightInPixels = bitmapData.Height; int widthInBytes = bitmapData.Width * bytesPerPixel; byte *PtrFirstPixel = (byte *)bitmapData.Scan0; for (int y = 0; y < heightInPixels; y++) { byte *currentLine = PtrFirstPixel + (y * bitmapData.Stride); for (int x = 0; x < widthInBytes; x = x + bytesPerPixel) { //int oldBlue = currentLine[x]; //int oldGreen = currentLine[x + 1]; //int oldRed = currentLine[x + 2]; colorHSV.SetHue(x / bytesPerPixel); //colorHSV.SetValue(y/360.0); //colorHSV.SetSaturation(y / 360.0); colorRGB = colorHSV.ToRGB(); currentLine[x] = (byte)colorRGB.B; currentLine[x + 1] = (byte)colorRGB.G; currentLine[x + 2] = (byte)colorRGB.R; } } bmp.UnlockBits(bitmapData); } }
public int CompareHue(HSV color) { int delta = (int)Math.Abs(H - color.GetHue()); return((delta >= 180) ? 360 - delta : delta); }
private void AddValuesToChart(ObservableCollection<ChartValue> chartValues, BitmapImage bitmapImage) { Bitmap bitmap = BitmapImage2Bitmap(bitmapImage); var mas = new int[256]; int width = bitmapImage.PixelWidth; int height = bitmapImage.PixelHeight; for(int i = 0; i < height; i++) { for(int j = 0; j < width; j++) { double val = new HSV(bitmap.GetPixel(j, i)).Value; int idx = (int)(val*255); mas[idx]++; } } chartValues.Clear(); for (int i = 0; i < mas.Length; i++) { chartValues.Add(new ChartValue(i, mas[i])); } }
private HSV GetRobertsPixel(HSV hsv0, HSV hsv1, HSV hsv2, HSV hsv3) { hsv0.Value = RobertsOperator(hsv0.Value, hsv1.Value, hsv2.Value, hsv3.Value); return hsv0; }
private HSV GetRobertsPixel(HSV hsv0, HSV hsv1, HSV hsv2, HSV hsv3) { hsv0.Value = RobertsOperator(hsv0.Value, hsv1.Value, hsv2.Value, hsv3.Value); return(hsv0); }
public int CompareHue(HSV color) { int num = (int)Math.Abs(H - color.GetHue()); return((num >= 180) ? (360 - num) : num); }
public bool Equals(HSV hsv) { return((this.H == hsv.H) && (this.S == hsv.S) && (this.V == hsv.V)); }