public static List <Voxel> ApplyQuantization(List <Voxel> blocks, int colorLimit) { Quantizer.Quantizer quantizer = new Quantizer.Quantizer(); try { using (Bitmap bitmap = CreateBitmapFromColors(blocks)) { using (Image quantized = quantizer.QuantizeImage(bitmap, 10, 70, colorLimit)) { Bitmap reducedBitmap = (Bitmap)quantized; //Console.WriteLine(quantized.PixelFormat); //Bitmap reducedBitmap = new Bitmap(quantized); int width = reducedBitmap.Size.Width; for (int i = 0; i < blocks.Count; i++) { int x = i % width; int y = i / width; blocks[i] = new Voxel(blocks[i].X, blocks[i].Y, blocks[i].Z, reducedBitmap.GetPixel(x, y).ColorToUInt()); } } } } catch (Exception e) { Console.WriteLine(e); } return(blocks); }
public static Schematic WriteSchematicFromImage(Bitmap bitmap, Bitmap colorBitmap, HeightmapStep heightmapStep) { if (colorBitmap != null) { if (bitmap.Height != colorBitmap.Height || bitmap.Width != colorBitmap.Width) { throw new ArgumentException("[ERROR] Image color is not the same size of the original image"); } if (heightmapStep.ColorLimit != 256 || colorBitmap.CountColor() > 256) { Quantizer.Quantizer quantizer = new Quantizer.Quantizer(); colorBitmap = quantizer.QuantizeImage(colorBitmap, 10, 70, heightmapStep.ColorLimit); } } else if (heightmapStep.EnableColor) { if (heightmapStep.ColorLimit != 256 || bitmap.CountColor() > 256) { Quantizer.Quantizer quantizer = new Quantizer.Quantizer(); bitmap = quantizer.QuantizeImage(bitmap, 10, 70, heightmapStep.ColorLimit); } } Schematic schematic = WriteSchematicIntern(bitmap, colorBitmap, heightmapStep); return(schematic); }
private Schematic WriteSchematicFromImage() { Bitmap bitmap = ConvertTifToBitmap(_path); Bitmap clone = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format32bppArgb); using (Graphics gr = Graphics.FromImage(clone)) { gr.DrawImage(bitmap, new Rectangle(0, 0, clone.Width, clone.Height)); } Bitmap bitmapColor = new Bitmap(bitmap.Width, bitmap.Height); //default initialization Quantizer.Quantizer quantizer = new Quantizer.Quantizer(); if (_colorPath != null) { bitmapColor = ConvertTifToBitmap(_colorPath); if (bitmap.Height != bitmapColor.Height || bitmap.Width != bitmapColor.Width) { throw new ArgumentException("[ERROR] Image color is not the same size of the original image"); } clone = new Bitmap(bitmapColor.Width, bitmapColor.Height, PixelFormat.Format32bppArgb); using (Graphics gr = Graphics.FromImage(clone)) { gr.DrawImage(bitmapColor, new Rectangle(0, 0, clone.Width, clone.Height)); } if (_colorLimit != 256 || bitmapColor.CountColor() > 256) { System.Drawing.Image image = quantizer.QuantizeImage(clone, 10, 70, _colorLimit); bitmapColor = new Bitmap(image); } } else if (_color) { if (_colorLimit != 256 || clone.CountColor() > 256) { System.Drawing.Image image = quantizer.QuantizeImage(bitmap, 10, 70, _colorLimit); bitmap = new Bitmap(image); } } Schematic schematic = WriteSchematicIntern(bitmap, bitmapColor); return(schematic); }
public static List <Voxel> ApplyQuantization(List <Voxel> blocks, int colorLimit) { Quantizer.Quantizer quantizer = new Quantizer.Quantizer(); try { if (blocks.Count == 0) { Console.WriteLine("[WARNING] No voxels to quantize, skipping this part..."); return(blocks); } Console.WriteLine("[INFO] Started quantization of all colors ..."); using (ProgressBar progressBar = new ProgressBar()) { using (Bitmap bitmap = CreateBitmapFromColors(blocks)) { using (Bitmap quantized = quantizer.QuantizeImage(bitmap, 10, 70, colorLimit)) { //Console.WriteLine(quantized.PixelFormat); //Bitmap reducedBitmap = new Bitmap(quantized); int width = quantized.Size.Width; for (int i = 0; i < blocks.Count; i++) { int x = i % width; int y = i / width; blocks[i] = new Voxel(blocks[i].X, blocks[i].Y, blocks[i].Z, quantized.GetPixel(x, y).ColorToUInt()); progressBar.Report(i / (float)blocks.Count); } } } } Console.WriteLine("[INFO] Done."); } catch (Exception e) { Console.WriteLine(e); } return(blocks); }