public void ColorizeBlock(int blockID, byte regionID) { regions[blockID] = regionID; if (Colored == null) { Colored = new Bitmap(originalMap); } Rectangle rect = CalculateRectangle(blockID); int huetransform; if (regionID < regionHUE.Length) { huetransform = regionID == 0xFF ? 0 : regionHUE[regionID]; } else { huetransform = 0; } if (regionID == 255) { return; } HueModifier hue = new HueModifier(huetransform); hue.ApplyInPlace(Colored, rect); }
private void hueModificationToolStripMenuItem_Click(object sender, EventArgs e) { HueModifier hm = new HueModifier(180); hueImage = hm.Apply(originalImage); pictureBox5.Image = hueImage; }
private void hueToolStripMenuItem_Click(object sender, EventArgs e) { HueModifier gb = new HueModifier(); newImg = gb.Apply(orgImg); pictureBox5.Image = newImg; }
public Bitmap ToHueModifier(Bitmap Im) { AForge.Imaging.Filters.HueModifier Img = new HueModifier(); Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb); return(Img.Apply(bmImage)); }
public mAdjustHue(int hue) { Hue = hue; BitmapType = BitmapTypes.None; filter = new HueModifier(Hue); }
public void ColorizeBlock(Rectangle rect) { if (Colored == null) { Colored = new Bitmap(originalMap); } HueModifier hue = new HueModifier(huetransformator); hue.ApplyInPlace(Colored, rect); pictureBox3.Image = Colored; }
private void ImgHSLC(string type) { if (this.tb_Contrast.Value == 50 && this.tb_Hue.Value == 0 && this.tb_Light.Value == 0 && this.tb_Saturation.Value == 0) { this.drawArea.Image = this.sourceImage; return; } Bitmap bt = this.filteredImage; switch (type) { case "Hue": if (huemodifierFilter == null) { huemodifierFilter = new HueModifier(); } huemodifierFilter.Hue = this.tb_Hue.Value; bt = ApplyFilter(huemodifierFilter, bt); xml += this.SaveImageToXml.SaveImgProcess(this.drawArea, this.lb_ImageName.Text, "HueModifier", huemodifierFilter); break; case "Saturation": if (saturationcorrFilter == null) { saturationcorrFilter = new SaturationCorrection(); } saturationcorrFilter.AdjustValue = Convert.ToDouble(this.tb_Saturation.Value) / Convert.ToDouble(255); bt = ApplyFilter(saturationcorrFilter, bt); xml += this.SaveImageToXml.SaveImgProcess(this.drawArea, this.lb_ImageName.Text, "Saturation", saturationcorrFilter); break; case "Light": if (brightnesscorr == null) { brightnesscorr = new BrightnessCorrection(); } brightnesscorr.AdjustValue = Convert.ToDouble(tb_Light.Value) / Convert.ToDouble(255); bt = ApplyFilter(brightnesscorr, bt); xml += this.SaveImageToXml.SaveImgProcess(this.drawArea, this.lb_ImageName.Text, "BrightnessCorrection", brightnesscorr); break; case "Contrast": if (contrastCorr == null) { contrastCorr = new ContrastCorrection(); } contrastCorr.Factor = Convert.ToDouble(tb_Contrast.Value) / Convert.ToDouble(40); bt = ApplyFilter(contrastCorr, bt); xml += this.SaveImageToXml.SaveImgProcess(this.drawArea, this.lb_ImageName.Text, "ContrastCorrection", contrastCorr); break; } this.drawArea.Image = bt; }
public Tuple <Bitmap, Json> CreateImage() { if (_leftEyes.Count == 0 || _rightEyes.Count == 0 || _noses.Count == 0 || _mouths.Count == 0) { return(null); } Random rnd = new Random(); Json json = new Json(); json.angle = 270; json.type = "Pop face mix"; var leftEyePath = _leftEyes.ElementAt(rnd.Next(0, _leftEyes.Count() - 1)); json.addItem(leftEyePath, "Oeil gauche"); var leftEye = FastLoad(leftEyePath); var rightEyePath = _rightEyes.ElementAt(rnd.Next(0, _rightEyes.Count() - 1)); json.addItem(rightEyePath, "Oeil droit"); var rightEye = FastLoad(rightEyePath); var nosePath = _noses.ElementAt(rnd.Next(0, _noses.Count() - 1)); json.addItem(nosePath, "Nez"); var nose = FastLoad(nosePath); var mouthPath = _mouths.ElementAt(rnd.Next(0, _mouths.Count() - 1)); json.addItem(mouthPath, "Bouche"); var mouth = FastLoad(mouthPath); var target = new Bitmap(mouth.Width, mouth.Height, mouth.PixelFormat); target.SetResolution(mouth.HorizontalResolution, mouth.VerticalResolution); var graphics = Graphics.FromImage(target); graphics.CompositingMode = CompositingMode.SourceOver; pop(graphics, mouth); pop(graphics, nose); pop(graphics, leftEye); pop(graphics, rightEye); var filterHueModifier = new HueModifier(rnd.Next(0, 359)); filterHueModifier.ApplyInPlace(target); return(new Tuple <Bitmap, Json>(target, json)); }
public Hue() { InitializeComponent(); this.l_track1_L.Text = "-180"; this.l_track1_R.Text = "180"; this.trackBar_1.Maximum = 180; this.trackBar_1.Minimum = -180; this.trackBar_1.SmallChange = 1; this.trackBar_1.TickFrequency = 10; huemodifierFilter = new HueModifier(); drawArea.Image = (Bitmap)frmImgProcess.imgProcess.drawArea.Image; drawArea.Filter = huemodifierFilter; saveImgToXml = new SaveBackImageToXml(); }
private void Hue_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { HueLabel.Content = Hue.Value; hue = (int)Hue.Value; if (mainPhoto != null) { hm = new HueModifier(hue); System.Drawing.Bitmap tmp = hm.Apply((System.Drawing.Bitmap)mainPhoto.Clone()); //BitmapImage tmpBmpIs = ToBitmapImage(tmp); Photography.Source = ToBitmapImage(tmp); UpdateHistograms(tmp); UpdateChannelPreviews(tmp); } }
private void DisplayCapturedPicture(object sender, NewFrameEventArgs eventArgs) { Bitmap bitmap = new Bitmap(eventArgs.Frame, new Size(cameraPictureBox.Width, cameraPictureBox.Height)); BrightnessCorrection brightnessCorrection = new BrightnessCorrection(Brightness); ContrastCorrection contrastCorrection = new ContrastCorrection(Contrast); SaturationCorrection saturationCorrection = new SaturationCorrection(Saturation * 0.1f); HueModifier hueModifier = new HueModifier(Hue); bitmap = brightnessCorrection.Apply((Bitmap)bitmap.Clone()); bitmap = contrastCorrection.Apply((Bitmap)bitmap.Clone()); bitmap = saturationCorrection.Apply((Bitmap)bitmap.Clone()); bitmap = hueModifier.Apply((Bitmap)bitmap.Clone()); if (connectedCameraIsRecording) { videoWriter.WriteVideoFrame(bitmap); } cameraPictureBox.Image = bitmap; }
public Tuple <Bitmap, Json> CreateImage(double factor) { var target = new Bitmap(_screenWidth, _screenHeight, _pixelFormat); target.SetResolution(_horizontalResolution, _verticalResolution); var graphics = Graphics.FromImage(target); graphics.CompositingMode = CompositingMode.SourceOver; Json json = new Json(); json.angle = 0; json.type = "Collection pop"; for (var i = 0; i < _nbX; i++) { for (var j = 0; j < _nbY; j++) { var path = _faces.ElementAt(_rndCreateImage.Next(0, _faces.Count() - 1)); json.addItem(path, "Tête " + (i + 1) + "-" + (j + 1)); var face = FastLoad(path); if (face != null) { try { var filter = new HueModifier(_rndCreateImage.Next(0, 359)); float width = (float)(face.Width / factor); float height = (float)(face.Height / factor); graphics.DrawImage(filter.Apply(new Bitmap(face)), _posX + i * width, _posY + j * height, width, height); } catch { } } } } return(new Tuple <Bitmap, Json>(target, json)); }
public void GetImageProcess()//显示图片时读取 { XmlNode node = xmlDoc.SelectSingleNode("PatientBackImage/Image[@Name='" + ImageName + "'] "); if (node != null) { if (node.HasChildNodes) { XmlNodeList xmlNolist = node.ChildNodes; foreach (XmlNode xn in xmlNolist) { XmlElement xmlE = (XmlElement)xn; switch (xmlE.Name) { case "DrawLine": DrawLine dl = new DrawLine(Convert.ToInt32(xmlE.GetAttribute("StartPointX")), Convert.ToInt32(xmlE.GetAttribute("StartPointY")), Convert.ToInt32(xmlE.GetAttribute("EndPointX")), Convert.ToInt32(xmlE.GetAttribute("EndPointY"))); dl.ID = Convert.ToInt32(xmlE.GetAttribute("ID")); frmImgProcess.imgProcess.drawArea.GraphicsList.UnselectAll(); frmImgProcess.imgProcess.drawArea.GraphicsList.Add(dl); frmImgProcess.imgProcess.drawArea.Capture = true; frmImgProcess.imgProcess.drawArea.Refresh(); break; case "DrawRectangle": DrawRectangle dr = new DrawRectangle(Convert.ToInt32(xmlE.GetAttribute("X")), Convert.ToInt32(xmlE.GetAttribute("Y")), Convert.ToInt32(xmlE.GetAttribute("Width")), Convert.ToInt32(xmlE.GetAttribute("Height"))); dr.ID = Convert.ToInt32(xmlE.GetAttribute("ID")); frmImgProcess.imgProcess.drawArea.GraphicsList.UnselectAll(); frmImgProcess.imgProcess.drawArea.GraphicsList.Add(dr); frmImgProcess.imgProcess.drawArea.Capture = true; frmImgProcess.imgProcess.drawArea.Refresh(); break; case "DrawEllipse": DrawEllipse de = new DrawEllipse(Convert.ToInt32(xmlE.GetAttribute("X")), Convert.ToInt32(xmlE.GetAttribute("Y")), Convert.ToInt32(xmlE.GetAttribute("Width")), Convert.ToInt32(xmlE.GetAttribute("Height"))); de.ID = Convert.ToInt32(xmlE.GetAttribute("ID")); frmImgProcess.imgProcess.drawArea.GraphicsList.UnselectAll(); frmImgProcess.imgProcess.drawArea.GraphicsList.Add(de); frmImgProcess.imgProcess.drawArea.Capture = true; frmImgProcess.imgProcess.drawArea.Refresh(); break; case "DrawPoint": DrawPoint dp = new DrawPoint(Convert.ToInt32(xmlE.GetAttribute("X")), Convert.ToInt32(xmlE.GetAttribute("Y"))); dp.ID = Convert.ToInt32(xmlE.GetAttribute("ID")); frmImgProcess.imgProcess.drawArea.GraphicsList.UnselectAll(); frmImgProcess.imgProcess.drawArea.GraphicsList.Add(dp); frmImgProcess.imgProcess.drawArea.Capture = true; frmImgProcess.imgProcess.drawArea.Refresh(); break; case "DrawPolygon": DrawPolygon dpy = new DrawPolygon(); string pointStr = xmlE.GetAttribute("pointStr"); string[] poList = pointStr.Split('$'); string[] p = { }; for (int i = 0; i < poList.Length; i++) { if (poList[i].ToString() != "") { p = poList[i].Split(','); Point point = new Point(Convert.ToInt32(p[0]), Convert.ToInt32(p[1])); dpy.pointArray.Add(point); } } dpy.ID = Convert.ToInt32(xmlE.GetAttribute("ID")); frmImgProcess.imgProcess.drawArea.GraphicsList.UnselectAll(); frmImgProcess.imgProcess.drawArea.GraphicsList.Add(dpy); frmImgProcess.imgProcess.drawArea.Capture = true; frmImgProcess.imgProcess.drawArea.Refresh(); break; case "TextBox": ToolText tx = new ToolText(frmImgProcess.imgProcess.drawArea); tx.Location = new Point(Convert.ToInt32(xmlE.GetAttribute("X")), Convert.ToInt32(xmlE.GetAttribute("Y"))); tx.Width = Convert.ToInt32(xmlE.GetAttribute("Width")); tx.Height = Convert.ToInt32(xmlE.GetAttribute("Height")); tx.Name = xmlE.GetAttribute("ID"); tx.Min = true; tx.Max = true; tx.IsChangeSize = true; tx.ReadOnly = false; tx.IsMove = true; tx.Text = xmlE.GetAttribute("Content"); tx.ForeColor = System.Drawing.Color.Red; frmImgProcess.imgProcess.drawArea.Controls.Add(tx); break; case "Process": XmlNode nodeProcess = xmlDoc.SelectSingleNode("PatientBackImage/Image[@Name='" + ImageName + "']/Process "); if (nodeProcess != null) { if (nodeProcess.HasChildNodes) { XmlNodeList xmlNodeProcesslist = nodeProcess.ChildNodes; foreach (XmlNode xn2 in xmlNodeProcesslist) { XmlElement xmlE2 = (XmlElement)xn2; switch (xmlE2.Name) { case "BrightnessCorrection": //亮度 BrightnessCorrection brightnesscorr = new BrightnessCorrection(); brightnesscorr.AdjustValue = double.Parse(xmlE2.GetAttribute("Value")); frmImgProcess.imgProcess.ApplyFilter(brightnesscorr); break; case "ContrastCorrection": //对比 ContrastCorrection contrastCorr = new ContrastCorrection(); contrastCorr.Factor = double.Parse(xmlE2.GetAttribute("Value")); frmImgProcess.imgProcess.ApplyFilter(contrastCorr); break; case "HueModifier": //色相 HueModifier huemodifier = new HueModifier(); huemodifier.Hue = int.Parse(xmlE2.GetAttribute("Value")); frmImgProcess.imgProcess.ApplyFilter(huemodifier); break; case "Saturation": //饱和度 SaturationCorrection saturationcorr = new SaturationCorrection(); saturationcorr.AdjustValue = double.Parse(xmlE2.GetAttribute("Value")); frmImgProcess.imgProcess.ApplyFilter(saturationcorr); break; case "GrayscaleBT709": //灰度 GrayscaleBT709 grayscalebt = new GrayscaleBT709(); frmImgProcess.imgProcess.ApplyFilter(grayscalebt); break; case "Filter": //过滤 ColorFiltering colorfilter = new ColorFiltering(); IntRange red = new IntRange(0, 255); IntRange green = new IntRange(0, 255); IntRange blue = new IntRange(0, 255); byte fillR = 0, fillG = 0, fillB = 0; string fillType = ""; red.Min = int.Parse(xmlE2.GetAttribute("RedMin")); red.Max = int.Parse(xmlE2.GetAttribute("RedMax")); green.Min = int.Parse(xmlE2.GetAttribute("GreenMin")); green.Max = int.Parse(xmlE2.GetAttribute("GreenMax")); blue.Min = int.Parse(xmlE2.GetAttribute("BlueMin")); blue.Max = int.Parse(xmlE2.GetAttribute("BlueMax")); fillR = byte.Parse(xmlE2.GetAttribute("FillRed")); fillG = byte.Parse(xmlE2.GetAttribute("FillGreen")); fillB = byte.Parse(xmlE2.GetAttribute("FillBlue")); fillType = xmlE2.GetAttribute("FillType"); colorfilter.Red = red; colorfilter.Green = green; colorfilter.Blue = blue; colorfilter.FillColor = new RGB(fillR, fillG, fillB); if (fillType == "OutSide") { colorfilter.FillOutsideRange = true; } else { colorfilter.FillOutsideRange = false; } frmImgProcess.imgProcess.ApplyFilter(colorfilter); break; case "Gaussian": //柔化 GaussianBlur gaussianBlur = new GaussianBlur(); gaussianBlur.Sigma = double.Parse(xmlE2.GetAttribute("Sigma")); gaussianBlur.Size = int.Parse(xmlE2.GetAttribute("Size")); frmImgProcess.imgProcess.ApplyFilter(gaussianBlur); break; case "DifferenceEdgeDetector": //边缘增强 DifferenceEdgeDetector differenceEdgeD = new DifferenceEdgeDetector(); frmImgProcess.imgProcess.ApplyFilter(differenceEdgeD); break; case "RotateFlip": //镜像 frmImgProcess.imgProcess.drawArea.Image.RotateFlip(RotateFlipType.RotateNoneFlipX); frmImgProcess.imgProcess.drawArea.Refresh(); break; case "PerlinNoise": //去噪 string value = ""; value = xmlE2.GetAttribute("Value"); float imageWidth = 0; float imageHeight = 0; switch (value) { case "Marble": filter = new Texturer(new MarbleTexture(imageWidth / 96, imageHeight / 48), 0.7f, 0.3f); break; case "Wood": filter = new Texturer(new WoodTexture(), 0.7f, 0.3f); break; case "Clouds": filter = new Texturer(new CloudsTexture(), 0.7f, 0.3f); break; case "Labyrinth": filter = new Texturer(new LabyrinthTexture(), 0.7f, 0.3f); break; case "Textile": filter = new Texturer(new TextileTexture(), 0.7f, 0.3f); break; case "Dirty": TexturedFilter f = new TexturedFilter(new CloudsTexture(), new Sepia()); f.PreserveLevel = 0.30f; f.FilterLevel = 0.90f; filter = f; break; case "Rusty": filter = new TexturedFilter(new CloudsTexture(), new Sepia(), new GrayscaleBT709()); break; } frmImgProcess.imgProcess.ApplyFilter(filter); break; case "Sharpen": Sharpen sharpen = new Sharpen(); frmImgProcess.imgProcess.ApplyFilter(sharpen); break; case "Mean": Mean mean = new Mean(); frmImgProcess.imgProcess.ApplyFilter(mean); break; } } } } break; } } } } }
public static Image ApplyImageProperties(byte[] blobContent, ImageProperties properties) { Bitmap image = null; try { using (var ms = new MemoryStream(blobContent)) { image = (Bitmap)System.Drawing.Image.FromStream(ms, false, false); image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); if (properties.Crop != null) { AForge.Imaging.Filters.Crop filter = new AForge.Imaging.Filters.Crop(new Rectangle(properties.Crop.XOffset, properties.Crop.YOffset, properties.Crop.CropWidth, properties.Crop.CropHeight)); image = filter.Apply(image); } if (properties.ImageWidth != properties.OriginalWidth || properties.ImageHeight != properties.OriginalHeight) { var filter = new ResizeBicubic(properties.ImageWidth, properties.ImageHeight); image = filter.Apply(image); } if (properties.Colors != null) { if (properties.Colors.TransparentColor != null) { image.MakeTransparent(ColorTranslator.FromHtml("#" + properties.Colors.TransparentColor)); } var brightness = properties.Colors.Brightness; var bfilter = new BrightnessCorrection(brightness); bfilter.ApplyInPlace(image); var contrast = properties.Colors.Contrast; var cfilter = new ContrastCorrection(contrast); cfilter.ApplyInPlace(image); if (properties.Colors.Hue != 0) { var hue = properties.Colors.Hue; HueModifier filter = new HueModifier(hue); filter.ApplyInPlace(image); } var saturation = properties.Colors.Saturation; var sfilter = new SaturationCorrection(saturation * 0.01f); sfilter.ApplyInPlace(image); } # region Effects if (!String.IsNullOrEmpty(properties.Effects)) { var effects = properties.Effects.Split(';'); foreach (var item in effects) { switch (item) { case "Grayscale": var g = new Grayscale(0.2125, 0.7154, 0.0721); image = g.Apply(image); break; case "Sepia": var s = new Sepia(); image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); s.ApplyInPlace(image); break; case "Rotate Channels": image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); var r = new RotateChannels(); r.ApplyInPlace(image); break; case "Invert": var i = new Invert(); i.ApplyInPlace(image); break; case "Blur": var b = new Blur(); b.ApplyInPlace(image); break; case "Gaussian Blur": var gb = new GaussianBlur(4, 11); gb.ApplyInPlace(image); break; case "Convolution": int[,] kernel = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; var c = new Convolution(kernel); c.ApplyInPlace(image); break; case "Edges": var e = new Edges(); e.ApplyInPlace(image); break; } } } # endregion } } catch (Exception) {
public HueModifier_Correction() { _filter = new HueModifier(); }
private void hueModifierToolStripMenuItem_Click(object sender, EventArgs e) { HueModifier hue = new HueModifier(); pictureBox2.Image = hue.Apply((Bitmap)pictureBox1.Image); }
public HueModifierFilter() { _hueModifier = new HueModifier(); _hueModifier.Hue = 50; }