public FilterImage Execute(FilterImage input) { cImage cimage = input.tocImage(); cimage = cimage.ApplyHQ(scale.Value, complex.GetSelected()); return(new FilterImage(cimage)); }
/// <summary> /// creates a new FilterImage form a Hawkynt cImage /// </summary> /// <param name="image"></param> public FilterImage(cImage image) { this.width = image.Width; this.height = image.Height; this.r = new byte[width * height]; this.g = new byte[width * height]; this.b = new byte[width * height]; this.a = new byte[width * height]; int x; int y; sPixel pixel; for (x = 0; x < this.width; x++) { for (y = 0; y < this.height; y++) { pixel = image.GetPixel(x, y); this.r[x * height + y] = pixel.Red; this.g[x * height + y] = pixel.Green; this.b[x * height + y] = pixel.Blue; this.a[x * height + y] = pixel.Alpha; } } }
/// <summary> /// body for HQ2x etc. /// </summary> public static void ComplexFilter(PixelWorker<sPixel> worker, byte scaleX, byte scaleY, cImage.NqKernel kernel) { var c0 = worker.SourceM1M1(); var c1 = worker.SourceP0M1(); var c2 = worker.SourceP1M1(); var c3 = worker.SourceM1P0(); var c4 = worker.SourceP0P0(); var c5 = worker.SourceP1P0(); var c6 = worker.SourceM1P1(); var c7 = worker.SourceP0P1(); var c8 = worker.SourceP1P1(); byte pattern = 0; if ((c4.IsNotLike(c0))) pattern |= 1; if ((c4.IsNotLike(c1))) pattern |= 2; if ((c4.IsNotLike(c2))) pattern |= 4; if ((c4.IsNotLike(c3))) pattern |= 8; if ((c4.IsNotLike(c5))) pattern |= 16; if ((c4.IsNotLike(c6))) pattern |= 32; if ((c4.IsNotLike(c7))) pattern |= 64; if ((c4.IsNotLike(c8))) pattern |= 128; kernel(pattern, c0, c1, c2, c3, c4, c5, c6, c7, c8, worker); } // end sub
public FilterImage Execute(FilterImage input) { cImage cimage = input.tocImage(); cimage = cimage.ApplyXbr(scale.Value, alphaBlending.Value); return(new FilterImage(cimage)); }
private Surface _CreateSurfaceFromImage(cImage image, Rectangle rect) { var bitmap = image.ToBitmap(); var selection = bitmap.Clone(rect, bitmap.PixelFormat); var result = Surface.CopyFromBitmap(selection); return(result); }
private void lbxFiles_OnKeyDown(object sender, KeyEventArgs e) { // delete attempt if ((e.KeyCode == Keys.Delete) && (lbxFiles.SelectedIndex != -1)) { int file_index = this.lbxFiles.SelectedIndex; this.lbxFiles.Items.RemoveAt(file_index); _ImageList.RemoveAt(file_index); this.txtFileCount.Text = _ImageList.Count.ToString(); ResetProgressbar(_ImageList.Count); } // Move item up if ((e.KeyCode == Keys.Q) && (lbxFiles.SelectedIndex != -1) && (lbxFiles.SelectedIndex != 0)) { int index = this.lbxFiles.SelectedIndex; cImage image = _ImageList[index]; _ImageList.RemoveAt(index); _ImageList.Insert(index - 1, image); this.lbxFiles.Items.Clear(); foreach (cImage item in _ImageList) { this.lbxFiles.Items.Add(item.Filename); } lbxFiles.SelectedIndex = index - 1; ResetProgressbar(_ImageList.Count); } // Move item down if ((e.KeyCode == Keys.A) && (lbxFiles.SelectedIndex != -1) && (lbxFiles.SelectedIndex != lbxFiles.Items.Count - 1)) { int index = this.lbxFiles.SelectedIndex; cImage image = _ImageList[index]; _ImageList.RemoveAt(index); _ImageList.Insert(index + 1, image); this.lbxFiles.Items.Clear(); foreach (cImage item in _ImageList) { this.lbxFiles.Items.Add(item.Filename); } lbxFiles.SelectedIndex = index + 1; ResetProgressbar(_ImageList.Count); } }
} // end sub /// <summary> /// body for HQ2xBold etc. as seen in SNES9x /// </summary> public static void ComplexFilterBold(PixelWorker<sPixel> worker, byte scaleX, byte scaleY, cImage.NqKernel kernel) { var c0 = worker.SourceM1M1(); var c1 = worker.SourceP0M1(); var c2 = worker.SourceP1M1(); var c3 = worker.SourceM1P0(); var c4 = worker.SourceP0P0(); var c5 = worker.SourceP1P0(); var c6 = worker.SourceM1P1(); var c7 = worker.SourceP0P1(); var c8 = worker.SourceP1P1(); var brightness = new[] { c0.Brightness, c1.Brightness, c2.Brightness, c3.Brightness, c4.Brightness, c5.Brightness, c6.Brightness, c7.Brightness, c8.Brightness }; var avgBrightness = (byte)(( brightness[0] + brightness[1] + brightness[2] + brightness[3] + brightness[4] + brightness[5] + brightness[6] + brightness[7] + brightness[8] ) / 9); var dc4 = c4.Brightness > avgBrightness; byte pattern = 0; if ((c4.IsNotLike(c0)) && ((brightness[0] > avgBrightness) != dc4)) pattern |= 1; if ((c4.IsNotLike(c1)) && ((brightness[1] > avgBrightness) != dc4)) pattern |= 2; if ((c4.IsNotLike(c2)) && ((brightness[2] > avgBrightness) != dc4)) pattern |= 4; if ((c4.IsNotLike(c3)) && ((brightness[3] > avgBrightness) != dc4)) pattern |= 8; if ((c4.IsNotLike(c5)) && ((brightness[5] > avgBrightness) != dc4)) pattern |= 16; if ((c4.IsNotLike(c6)) && ((brightness[6] > avgBrightness) != dc4)) pattern |= 32; if ((c4.IsNotLike(c7)) && ((brightness[7] > avgBrightness) != dc4)) pattern |= 64; if ((c4.IsNotLike(c8)) && ((brightness[8] > avgBrightness) != dc4)) pattern |= 128; kernel(pattern, c0, c1, c2, c3, c4, c5, c6, c7, c8, worker); } // end sub
public FilterImage Execute(FilterImage input) { cImage cimage = input.tocImage(); cimage = cimage.ApplyXbr(4, false); cimage = cimage.ApplyXbr(2, false); int normalizedDegs = rotateDegrees.Value < 0 ? rotateDegrees.Value + 360 : rotateDegrees.Value; double rotateRads = normalizedDegs * Math.PI / 180.0; FilterImage rot = RotateAndDownscale(new FilterImage(cimage), rotateRads); return(rot); }
/// <summary> /// converts this image to an instance of Hawkynt cImage /// </summary> public cImage tocImage() { cImage image = new cImage(this.width, this.height); int y; int x; for (x = 0; x < this.width; x++) { for (y = 0; y < this.height; y++) { image.SetPixel(x, y, new sPixel(this.r[x * height + y], this.g[x * height + y], this.b[x * height + y], this.a[x * height + y])); } } return(image); }
/// <summary> /// This is the XBR2x by Hyllian (see http://board.byuu.org/viewtopic.php?f=10&t=2248) /// </summary> public static void Xbr2X(cImage sourceImage, int srcX, int srcY, cImage targetImage, int tgtX, int tgtY, bool allowAlphaBlending) { var pa = sourceImage[srcX - 1, srcY - 1]; var pb = sourceImage[srcX + 0, srcY - 1]; var pc = sourceImage[srcX + 1, srcY - 1]; var pd = sourceImage[srcX - 1, srcY + 0]; var pe = sourceImage[srcX + 0, srcY + 0]; var pf = sourceImage[srcX + 1, srcY + 0]; var pg = sourceImage[srcX - 1, srcY + 1]; var ph = sourceImage[srcX + 0, srcY + 1]; var pi = sourceImage[srcX + 1, srcY + 1]; var a1 = sourceImage[srcX - 1, srcY - 2]; var b1 = sourceImage[srcX + 0, srcY - 2]; var c1 = sourceImage[srcX + 1, srcY - 2]; var a0 = sourceImage[srcX - 2, srcY - 1]; var d0 = sourceImage[srcX - 2, srcY + 0]; var g0 = sourceImage[srcX - 2, srcY + 1]; var c4 = sourceImage[srcX + 2, srcY - 1]; var f4 = sourceImage[srcX + 2, srcY + 0]; var i4 = sourceImage[srcX + 2, srcY + 1]; var g5 = sourceImage[srcX - 1, srcY + 2]; var h5 = sourceImage[srcX + 0, srcY + 2]; var i5 = sourceImage[srcX + 1, srcY + 2]; sPixel e1, e2, e3; var e0 = e1 = e2 = e3 = pe; _Kernel2Xv5(pe, pi, ph, pf, pg, pc, pd, pb, f4, i4, h5, i5, ref e1, ref e2, ref e3, allowAlphaBlending); _Kernel2Xv5(pe, pc, pf, pb, pi, pa, ph, pd, b1, c1, f4, c4, ref e0, ref e3, ref e1, allowAlphaBlending); _Kernel2Xv5(pe, pa, pb, pd, pc, pg, pf, ph, d0, a0, b1, a1, ref e2, ref e1, ref e0, allowAlphaBlending); _Kernel2Xv5(pe, pg, pd, ph, pa, pi, pb, pf, h5, g5, d0, g0, ref e3, ref e0, ref e2, allowAlphaBlending); targetImage[tgtX + 0, tgtY + 0] = e0; targetImage[tgtX + 1, tgtY + 0] = e1; targetImage[tgtX + 0, tgtY + 1] = e2; targetImage[tgtX + 1, tgtY + 1] = e3; }
/// <summary> /// Converts a given image into a floating point one. /// </summary> /// <param name="image">The image.</param> /// <param name="filterRegion">The filter region.</param> /// <returns></returns> public static FloatImage FromImage(cImage image, Rectangle?filterRegion) { Contract.Requires(image != null); var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left); var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top); var endX = filterRegion == null ? image.Width : Math.Min(image.Width, filterRegion.Value.Right); var endY = filterRegion == null ? image.Height : Math.Min(image.Height, filterRegion.Value.Bottom); var width = endX - startX; var height = endY - startY; var result = new FloatImage(width, height, image.HorizontalOutOfBoundsMode, image.VerticalOutOfBoundsMode); // copy image data Parallel.ForEach( Partitioner.Create(startY, endY), () => 0, (range, _, threadStorage) => { var i = (range.Item1 - startY) * width; for (var y = range.Item1; y < range.Item2; ++y) { for (var x = startX; x < endX; ++x) { var color = image[x, y]; result._redPlane[i] = color.SingleRed; result._greenPlane[i] = color.SingleGreen; result._bluePlane[i] = color.SingleBlue; result._alphaPlane[i] = color.SingleAlpha; ++i; } } return(threadStorage); }, _ => { } ); return(result); }
private void button1_Click(object sender, EventArgs e) { var Item = (TextureElement)TextureList.SelectedItem; var InBitmap = (Bitmap)TextureView.Image; Bitmap OutBitmap; if (false) { var OutImage = new cImage(InBitmap.Width * 2, InBitmap.Height * 2); libXBR.Xbr2X(cImage.FromBitmap(InBitmap), 0, 0, OutImage, 0, 0, true); OutBitmap = OutImage.ToBitmap(); } else { OutBitmap = (new Engine(new ColorAlphaLerp(), new ColorAlphaThreshold(32, 32, 32, 32))).Process(InBitmap); } Item.TextureOpengl.SetData( OutBitmap.GetChannelsDataInterleaved(BitmapChannelList.Rgba).CastToStructArray <OutputPixel>(), OutBitmap.Width, OutBitmap.Height); UpdateTexture(); TextureList.Focus(); }
/// <summary> /// Converts this floating point image to a normal image. /// </summary> /// <returns></returns> public cImage ToImage() { var width = this.Width; var height = this.Height; var result = new cImage(width, height) { HorizontalOutOfBoundsMode = this.HorizontalOutOfBoundsMode, VerticalOutOfBoundsMode = this.VerticalOutOfBoundsMode }; // copy image data Parallel.ForEach( Partitioner.Create(0, height), () => 0, (range, _, threadStorage) => { var i = range.Item1 * width; for (var y = range.Item1; y < range.Item2; ++y) { for (var x = 0; x < width; ++x) { result[x, y] = sPixel.FromFloat( this._redPlane[i], this._greenPlane[i], this._bluePlane[i], this._alphaPlane[i] ); ++i; } } return(threadStorage); }, _ => { } ); return(result); }
private void memoryTestToolStripMenuItem_Click(object sender, EventArgs e) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); var before = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64; // performs operations here for (int Idx = 0; Idx < 100; Idx++) { cImage Im = new cImage(30000, 5000, 1, 1); for (int i = 0; i < Im.SliceSize; i++) { Im.SingleChannelImage[0].Data[i] = i; } // Im.Dispose(); GC.Collect(); } var after = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64; var Mem = after - before; }
public cImage Apply(cImage source) { return(this._planeExtractionFunction(source)); }
private void toolStripMenuItemLoadImage_Click(object sender, EventArgs e) { OpenFileDialog CurrOpenFileDialog = new OpenFileDialog(); CurrOpenFileDialog.Filter = "TIF Files (*.tif)|*.tif|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files (*.bmp)|*.bmp|Cellomics Files (*.c01)|*.c01|Zeiss LSM Files (*.lsm)|*.lsm|MetaMorph Stack STK Files (*.stk)|*.stk"; //CurrOpenFileDialog.Filter = "Tif files (*.tif)|*.tif"; DialogResult Res = CurrOpenFileDialog.ShowDialog(); if (Res != DialogResult.OK) return; cImage NewIm = new cImage(CurrOpenFileDialog/*CurrOpenFileDialog.FileName*/); cDisplaySingleImage NewView = new cDisplaySingleImage(); NewView.SetInputData(NewIm); NewView.Run(); //if((NewIm.Width>500)||(NewIm.Height>500)) // NewView.ConstraintImageSize = new Point(500, 500); //GlobalInfo.DisplayViewer(NewView); return; }
public cImage Apply(cImage source, int width, int height, bool useCenteredGrid) { Contract.Requires(source != null); return(source.ApplyScaler(this._type, width, height, useCenteredGrid)); }
public cImage(cImage Source, bool IsCopyData) { //Source.GetNumChannels(); this.Width = Source.Width; this.Height = Source.Height; this.Depth = Source.Depth; this.SliceSize = this.Height * this.Width; this.ImageSize = SliceSize * Depth; this.Resolution = new cPoint3D(Source.Resolution); this.SingleChannelImage = new cListSingleChannelImage(); for (int IdxChannel = 0; IdxChannel < Source.GetNumChannels(); IdxChannel++) { this.SingleChannelImage.Add(new cSingleChannelImage(Source.Width, Source.Height, Source.Depth, new cPoint3D(Source.Resolution))); this.SingleChannelImage[IdxChannel].Name = Source.SingleChannelImage[IdxChannel].Name; this.SingleChannelImage[IdxChannel].Data = new float[Source.SingleChannelImage[IdxChannel].Data.Length]; if (IsCopyData) Array.Copy(Source.SingleChannelImage[IdxChannel].Data, this.SingleChannelImage[IdxChannel].Data, Source.SingleChannelImage[IdxChannel].Data.Length); } }
} // end sub /// <summary> /// body for HQ2xSmart etc. as seen in SNES9x /// </summary> public static void ComplexFilterSmart(PixelWorker<sPixel> worker, byte scaleX, byte scaleY, cImage.NqKernel kernel) { var c0 = worker.SourceM1M1(); var c2 = worker.SourceP1M1(); var c4 = worker.SourceP0P0(); var c6 = worker.SourceM1P1(); var c8 = worker.SourceP1P1(); if (c0.IsLike(c4) || c2.IsLike(c4) || c6.IsLike(c4) || c8.IsLike(c4)) ComplexFilter(worker, scaleX, scaleY, kernel); else ComplexFilterBold(worker, scaleX, scaleY, kernel); } // end sub
public cImage Crop(cPoint3D StartingPoint, cPoint3D EndingPoint) { int RealXStartPt = (int)StartingPoint.X; if (RealXStartPt < 0) RealXStartPt = 0; else if (RealXStartPt >= this.Width) RealXStartPt = this.Width - 1; int RealXEndPt = (int)EndingPoint.X; if (RealXEndPt < 0) RealXEndPt = 0; else if (RealXEndPt >= this.Width) RealXEndPt = this.Width - 1; int RealYStartPt = (int)StartingPoint.Y; if (RealYStartPt < 0) RealYStartPt = 0; else if (RealYStartPt >= this.Height) RealYStartPt = this.Height - 1; int RealYEndPt = (int)EndingPoint.Y; if (RealYEndPt < 0) RealYEndPt = 0; else if (RealYEndPt >= this.Height) RealYEndPt = this.Height - 1; int RealZStartPt = (int)StartingPoint.Z; if (RealZStartPt < 0) RealZStartPt = 0; else if (RealZStartPt >= this.Depth) RealZStartPt = this.Depth - 1; int RealZEndPt = (int)EndingPoint.Z; if (RealZEndPt < 0) RealZEndPt = 0; else if (RealZEndPt >= this.Depth) RealZEndPt = this.Depth - 1; cImage CroppedImage = new cImage((int)(RealXEndPt - RealXStartPt + 1), (int)(RealYEndPt - RealYStartPt + 1), (int)(EndingPoint.Z - StartingPoint.Z + 1), this.GetNumChannels()); CroppedImage.Resolution = new cPoint3D(this.Resolution); int RealPosZ; int RealPosY; int RealPosX; for (int Channel = 0; Channel < this.GetNumChannels(); Channel++) { for (int z = (int)RealZStartPt; z <= (int)RealZEndPt; z++) { RealPosZ = (int)(z - RealZStartPt); for (int y = (int)RealYStartPt; y <= (int)RealYEndPt; y++) { RealPosY = (int)(y - RealYStartPt); for (int x = (int)RealXStartPt; x <= (int)RealXEndPt; x++) { RealPosX = (int)(x - RealXStartPt); CroppedImage.SingleChannelImage[Channel].Data[RealPosX + RealPosY * CroppedImage.Width + RealPosZ * CroppedImage.SliceSize] = this.SingleChannelImage[Channel].Data[x + y * this.Width + z * this.SliceSize]; } } } CroppedImage.SingleChannelImage[Channel].Resolution = new cPoint3D(this.Resolution); } // CroppedImage.Resolution = new cPoint3D(this.Resolution); CroppedImage.Name = "Crop(" + this.Name + ")"; return CroppedImage; }
public cImage GetColorImage() { int IdxDesc = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorIndex(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor()); bool MissingWells; cImage ToReturn = new cImage(new cExtendedTable(this.GetAverageValueDescTable(IdxDesc, out MissingWells))); return ToReturn; }
public bool Execute() { var source = this._applyToTarget ? this.TargetImage : this.SourceImage; var width = this.Width; var height = this.Height; // pverwrite dimensions from percentage if needed var percentage = this.Percentage; if (percentage > 0) { width = (word)Math.Round(source.Width * percentage / 100d); height = (word)Math.Round(source.Height * percentage / 100d); } // correct aspect ratio if needed if (this.MaintainAspect) { if (width == 0) { width = (word)Math.Round((double)height * source.Width / source.Height); } else { height = (word)Math.Round((double)width * source.Height / source.Width); } } sPixel.AllowThresholds = this.UseThresholds; source.HorizontalOutOfBoundsMode = this.HorizontalBph; source.VerticalOutOfBoundsMode = this.VerticalBph; cImage result = null; var method = this.Manipulator; var scaler = method as AScaler; var interpolator = method as Interpolator; var planeExtractor = method as PlaneExtractor; var resampler = method as Resampler; var radiusResampler = method as RadiusResampler; if (scaler != null) { result = source; for (var i = 0; i < this.Count; i++) { result = scaler.Apply(result); } } else { if (interpolator != null) { result = interpolator.Apply(source, width, height); } else if (planeExtractor != null) { result = planeExtractor.Apply(source); } else if (resampler != null) { result = resampler.Apply(source, width, height, this.UseCenteredGrid); } else if (radiusResampler != null) { result = radiusResampler.Apply(source, width, height, this.Radius, this.UseCenteredGrid); } } this.TargetImage = result; return(true); }
public cImage Apply(cImage source, int width, int height) { Contract.Requires(source != null); return(source.ApplyScaler(this._type, width, height)); }
public cImage Apply(cImage source, int width, int height, float radius, bool useCenteredGrid) => source == null ? throw new ArgumentNullException(nameof(source)) : source.ApplyScaler(this._type, width, height, radius, useCenteredGrid, default(Rectangle?)) ;
public cImage Apply(cImage source) => this._planeExtractionFunction(source);
private void ToolStripMenuItem_DisplayImages(object sender, EventArgs e) { //if (cWell.cGlobalInfo.ImageAccessor.ImagingPlatformType == HCSAnalyzer.Classes.General_Types.eImagingPlatformType.OPERETTA) return; cGlobalInfo.ImageAccessor.Field = 1;// (int)this.numericUpDownField.Value; //string FileName = cWell.cGlobalInfo.ImageAccessor.GetImageFileName(this); foreach (cWell item in this.ListActiveWells) { List<cImageMetaInfo> ListMetaInfo = cGlobalInfo.ImageAccessor.GetImageInfo(item); cImage Image = new cImage(ListMetaInfo); Image.Name = "Image [" + item.GetShortInfo() + "] - Field [" + cGlobalInfo.ImageAccessor.Field + "]"; cImage FinaleImage = Image.Crop(new cPoint3D(400, 400, 0), new cPoint3D(800 + 400, 800 + 400, 0)); //cImageGeometricResize IR = new cImageGeometricResize(); //IR.SetInputData(Image); //IR.InterpolationType = Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR; //IR.ListProperties.UpdateValueByName("Scale", (double)0.25); //IR.Run(); //cImage FinaleImage = IR.GetOutPut(); //FinaleImage.Name = "Image [" + item.GetShortInfo()+"] - Field ["+ cWell.cGlobalInfo.ImageAccessor.Field + "]"; cDisplaySingleImage IV = new cDisplaySingleImage(); IV.SetInputData(FinaleImage); IV.Run(); } //cImage IM = new cImage(this.Info); //if (IM == null) return; //cImageViewer IV = new cImageViewer(); //IV.SetImage(IM); //IV.Show(); //cViewerImage3D VI3D = new cViewerImage3D(); //foreach (cWell item in this.ListActiveWells) //{ // vtkJPEGReader JPEGReader = vtkJPEGReader.New(); // JPEGReader.SetFileName(item.Info); // JPEGReader.Update(); // vtkImageData ID0 = JPEGReader.GetOutput(); // VI3D.SetInputData(ID0); //} //// cVolume3D Volume3D0 = new cVolume3D(ID0, new HCSAnalyzer.Classes._3D.cPoint3D(0, 0, 0)); //VI3D.Run(); //cDisplayToWindow DTW = new cDisplayToWindow(); //DTW.SetInputData(VI3D.GetOutPut()); //DTW.Run(); //DTW.Display(); }
public override cImage Apply(cImage source) { Contract.Requires(source != null); return(source.ApplyScaler(this._type, this._allowAlphaBlending)); }
/// <summary> /// Filters the image. /// </summary> /// <param name="source">The source.</param> /// <param name="method">The method.</param> /// <param name="targetWidth">Width of the target.</param> /// <param name="targetHeight">Height of the target.</param> /// <param name="horizontalBh">The horizontal bounds handling.</param> /// <param name="verticalBh">The vertical bounds handling.</param> /// <param name="useThresholds">if set to <c>true</c> [use thresholds].</param> /// <param name="useCenteredGrid">if set to <c>true</c> [use centered grid].</param> /// <param name="repetitionCount">The repetition count.</param> /// <param name="radius">The radius.</param> /// <returns></returns> internal static cImage FilterImage(cImage source, IImageManipulator method, ushort targetWidth, ushort targetHeight, OutOfBoundsMode horizontalBh, OutOfBoundsMode verticalBh, bool useThresholds, bool useCenteredGrid, byte repetitionCount, float radius) { Contract.Requires(source != null); sPixel.AllowThresholds = useThresholds; source.HorizontalOutOfBoundsMode = horizontalBh; source.VerticalOutOfBoundsMode = verticalBh; cImage result = null; var scaler = method as AScaler; var interpolator = method as Interpolator; var planeExtractor = method as PlaneExtractor; var resampler = method as Resampler; var radiusResampler = method as RadiusResampler; if (scaler != null) { result = source; for (var i = 0; i < repetitionCount; i++) { result = scaler.Apply(result); } } else if (interpolator != null) { if (targetWidth <= 0 || targetHeight <= 0) { MessageBox.Show(Resources.txNeedWidthAndHeightAboveZero, Resources.ttNeedWidthAndHeightAboveZero, MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { result = interpolator.Apply(source, targetWidth, targetHeight); } } else if (planeExtractor != null) { result = planeExtractor.Apply(source); } else if (resampler != null) { if (targetWidth <= 0 || targetHeight <= 0) { MessageBox.Show(Resources.txNeedWidthAndHeightAboveZero, Resources.ttNeedWidthAndHeightAboveZero, MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { result = resampler.Apply(source, targetWidth, targetHeight, useCenteredGrid); } } else if (radiusResampler != null) { if (targetWidth <= 0 || targetHeight <= 0) { MessageBox.Show(Resources.txNeedWidthAndHeightAboveZero, Resources.ttNeedWidthAndHeightAboveZero, MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { result = radiusResampler.Apply(source, targetWidth, targetHeight, radius, useCenteredGrid); } } return(result); }
public cImage GetClassColorImage() { cImage ToReturn = new cImage(cGlobalInfo.CurrentScreening.Columns, cGlobalInfo.CurrentScreening.Rows, 1, 3); for (int j = 0; j < ToReturn.Height; j++) for (int i = 0; i < ToReturn.Width; i++) { cWell TmpWell = this.GetWell(i , j , true); if(TmpWell==null) continue; Color C = TmpWell.GetClassColor(); ToReturn.SingleChannelImage[0].Data[i + j * ToReturn.Width] = C.R; ToReturn.SingleChannelImage[1].Data[i + j * ToReturn.Width] = C.G; ToReturn.SingleChannelImage[2].Data[i + j * ToReturn.Width] = C.B; } return ToReturn; }
public override cImage Apply(cImage source) { Contract.Requires(source != null); return(source.ApplyScaler(this._type)); }
/// <summary> /// creates a new FilterImage form a Hawkynt cImage /// </summary> public static FilterImage FromCImage(cImage cimage) { return(new FilterImage(cimage)); }
public void AddInto(cImage SubImage, int Dest_PosX, int Dest_PosY, int Dest_PosZ, int Dest_Channel) { if (SubImage.GetNumChannels() > 1) return; for (int Z = 0; Z < SubImage.Depth; Z++) { int OriginalPosZ = Dest_PosZ + Z; if ((OriginalPosZ < 0) || (OriginalPosZ > this.Depth - 1)) continue; for (int Y = 0; Y < SubImage.Height; Y++) { int OriginalPosY = Dest_PosY + Y; if ((OriginalPosY < 0) || (OriginalPosY > this.Height - 1)) continue; for (int X = 0; X < SubImage.Width; X++) { int OriginalPosX = Dest_PosX + X; if ((OriginalPosX < 0) || (OriginalPosX > this.Width - 1)) continue; this.SingleChannelImage[Dest_Channel].Data[OriginalPosX + OriginalPosY * this.Width + OriginalPosZ * this.SliceSize] += SubImage.SingleChannelImage[0].Data[X + Y * SubImage.Width + Z * SubImage.SliceSize]; } } } }
/// <summary> /// Converts a given image into a floating point one. /// </summary> /// <param name="image">The image.</param> /// <param name="filterRegion">The filter region.</param> /// <returns></returns> public static FloatImage FromImage(cImage image, Rect?filterRegion) => FromImage(image, filterRegion?.ToRectangle());
public override cImage Apply(cImage source) => source.ApplyScaler(this._type, this._mode, default(Rectangle?));
/// <summary> /// Converts this floating point image to a normal image. /// </summary> /// <returns></returns> public cImage ToImage() { var width = this.Width; var height = this.Height; var result = new cImage(width, height) { HorizontalOutOfBoundsMode = this.HorizontalOutOfBoundsMode, VerticalOutOfBoundsMode = this.VerticalOutOfBoundsMode }; // copy image data Parallel.ForEach( Partitioner.Create(0, height), () => 0, (range, _, threadStorage) => { var i = range.Item1 * width; for (var y = range.Item1; y < range.Item2; ++y) { for (var x = 0; x < width; ++x) { result[x, y] = sPixel.FromFloat( this._redPlane[i], this._greenPlane[i], this._bluePlane[i], this._alphaPlane[i] ); ++i; } } return (threadStorage); }, _ => { } ); return (result); }
public abstract cImage Apply(cImage source);
/// <summary> /// Converts a given image into a floating point one. /// </summary> /// <param name="image">The image.</param> /// <param name="filterRegion">The filter region.</param> /// <returns></returns> public static FloatImage FromImage(cImage image, Rectangle? filterRegion) { Contract.Requires(image != null); var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left); var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top); var endX = filterRegion == null ? image.Width : Math.Min(image.Width, filterRegion.Value.Right); var endY = filterRegion == null ? image.Height : Math.Min(image.Height, filterRegion.Value.Bottom); var width = endX - startX; var height = endY - startY; var result = new FloatImage(width, height, image.HorizontalOutOfBoundsMode, image.VerticalOutOfBoundsMode); // copy image data Parallel.ForEach( Partitioner.Create(startY, endY), () => 0, (range, _, threadStorage) => { var i = (range.Item1 - startY) * width; for (var y = range.Item1; y < range.Item2; ++y) { for (var x = startX; x < endX; ++x) { var color = image[x, y]; result._redPlane[i] = color.SingleRed; result._greenPlane[i] = color.SingleGreen; result._bluePlane[i] = color.SingleBlue; result._alphaPlane[i] = color.SingleAlpha; ++i; } } return (threadStorage); }, _ => { } ); return (result); }
public override cImage Apply(cImage source) => source.ApplyScaler(this._type, this._allowAlphaBlending, default(Rectangle?));
public cImage Apply(cImage source, int width, int height) => source.ApplyScaler(this._type, width, height);