private RgbImage stackImages(Rectangle rect, out int count) { //var start = DateTime.Now; var result = new RgbImage(rect.Width, rect.Height); var currentOffset = currentStack[currentStackIndex].Offset; rect.Offset(-currentOffset.X, -currentOffset.Y); count = 0; foreach (var item in currentStack) { if (!item.IsExcluded) { using (var rawImage = libraw.load_raw(item.FilePath)) { var _rect = rect; _rect.Offset(item.Offset); //rawImage.ApplyDark( currentSession.Dark ); if (currentSession.Flat != null) { rawImage.ApplyFlat(currentSession.Flat, 1); } using (var rgbImage = rawImage.ExtractRgbImage(_rect)) { result.Add(rgbImage); count++; } } } } //MessageBox.Show( ( DateTime.Now - start ).TotalMilliseconds.ToString( "0.00" ) ); return(result); }
public override void Run() { Result = new RgbImage <byte>(InputImage.Width, InputImage.Height); //converte angolo in radianti double rad = (RotationDegrees / 180) * Math.PI; //applica il mapping inverso su ogni pixel double sin = Math.Sin(rad); double cos = Math.Cos(rad); //canale R for (int y = 0; y < InputImage.Height; y++) { for (int x = 0; x < InputImage.Width; x++) { double Xold = 0; double Yold = 0; InvertedMapping(x, y, TranslationX, TranslationY, sin, cos, ScaleFactorX, ScaleFactorY, ref Xold, ref Yold); //adesso ho x old e y old, faccio l'interpolazione di lagrange int xL = (int)Xold; int yL = (int)Yold; Result.RedChannel[y, x] = Lagrange(Xold, Yold, 1); Result.GreenChannel[y, x] = Lagrange(Xold, Yold, 2); Result.BlueChannel[y, x] = Lagrange(Xold, Yold, 3); } } }
private void zoomPictureBox_Click(object sender, EventArgs e) { if (stackedZoom != null) { stackedZoom.Dispose(); stackedZoom = null; } var p = zoomPictureBox.PointToClient(Control.MousePosition); var clientSize = zoomPictureBox.ClientSize; var imageSize = zoomPictureBox.Image.Size; p.X += (clientSize.Width - imageSize.Width) / 2; p.Y += (clientSize.Height - imageSize.Height) / 2; int dX = ((p.X - imageSize.Width / 2) * currentZoomRect.Width) / imageSize.Width; int dY = ((p.Y - imageSize.Height / 2) * currentZoomRect.Height) / imageSize.Height; zoomCenterX += dX; zoomCenterY += dY; /*if( quickPreviewRadioButton.Checked ) { * zoomCenterX = (int) System.Math.Round( newCenter.X ); * zoomCenterY = (int) System.Math.Round( newCenter.Y ); * label1.Text = newCenter.ToString() + " - " + ImageTools.StarSigma( currentImage, newCenter ).ToString(); * } else */ bool refineCenter = (Control.ModifierKeys & Keys.Shift) != 0 && rawPreviewRadioButton.Checked; showZoomImage(refineCenter, true); }
/// <summary> /// 2010/04/26, RGBImage转化为位图. /// </summary> /// <param name="img"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="bmp"></param> public static void RGBImage2Bitmap(RgbImage rgbImg, int width, int height, out Bitmap bmp) { int[][][] rgb_mat = new int[3][][]; rgb_mat[0] = rgbImg.R; rgb_mat[1] = rgbImg.G; rgb_mat[2] = rgbImg.B; Mat2BitmapColor(rgb_mat, width, height, out bmp); }
private static void Main(string[] args) { // ugly constants const int numberOfCandidates = 30; const int numberOfGenerations = 3000; // loading base structures var imageModel = new RgbImage("src/image.png"); var mutator = new FixedSquareMutator(); var candidates = new ImageCandidate[numberOfCandidates]; // creating candidates for (var i = 0; i < numberOfCandidates; i++) { candidates[i] = new ImageCandidate(imageModel); } // stopwatch for time measurment var stopwatch = Stopwatch.StartNew(); // main iteration loop for (var i = 1; i <= numberOfGenerations; i++) { // mutating loop for (var j = 0; j < numberOfCandidates; j++) { mutator.Mutate(candidates[j]); } // scoring loop foreach (var candidate in candidates) { candidate.Score(imageModel); } // sorting via score candidates = candidates.OrderBy(c => c.Difference).ToArray(); // coping best candidate as a new generation (crossing) for (var j = 1; j < numberOfCandidates; j++) { candidates[j].Image.Copy(candidates[0].Image); } if (i % 10 == 0) { candidates[0].Save("src/result" + i + ".png"); } Console.WriteLine("Iteration: " + i + ", time elapsed: " + stopwatch.Elapsed + ", difference: " + candidates[0].PercentageDifference + "%"); } }
public override void Run() { Result = new RgbImage <byte>(InputImage.Width, InputImage.Height); // TODO: impostare l'immagine Result come negativo dell'immagine InputImage for (int i = 0; i < InputImage.PixelCount; i++) { Result.BlueChannel[i] = (byte)~InputImage.BlueChannel[i]; Result.RedChannel[i] = (byte)~InputImage.RedChannel[i]; Result.GreenChannel[i] = (byte)~InputImage.GreenChannel[i]; } }
private void GetRgbImage() { if (DipLibImage is RgbImage) { return; } Image = new FormatConvertedBitmap(OriginImage, PixelFormats.Bgra32, null, 0); byte[] pixels = new byte[Image.PixelWidth * Image.PixelHeight * 4]; Image.CopyPixels(pixels, Image.PixelWidth * 4, 0); DipLibImage = new RgbImage(pixels, Image.PixelWidth, Image.PixelHeight); }
private void saveImageOpenFolder(Image image, RgbImage rgbImage, string fileName) { using (var saveDialog = new SaveFileDialog()) { saveDialog.Filter = "PNG|*.png|PNG 16-bit|*.16-bit.png|BMP|*.bmp|JPEG|*.jpg"; saveDialog.FileName = fileName; saveDialog.InitialDirectory = thumbnailsView.CurrentObjectPath; if (saveDialog.ShowDialog() == DialogResult.OK) { fullScreen(false); Application.DoEvents(); switch (Path.GetExtension(saveDialog.FileName).ToLower()) { case ".bmp": { var encoderParams = new System.Drawing.Imaging.EncoderParameters(1); encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter( System.Drawing.Imaging.Encoder.ColorDepth, 24); image.Save(saveDialog.FileName, getEncoder(System.Drawing.Imaging.ImageFormat.Bmp), encoderParams); } break; case ".png": if (saveDialog.FileName.ToLower().EndsWith(".16-bit.png")) { Export.Save16BitPng(saveDialog.FileName, rgbImage.GetRgbPixels16(), rgbImage.Width, rgbImage.Height); } else { image.Save(saveDialog.FileName, System.Drawing.Imaging.ImageFormat.Png); } break; case ".jpg": { var encoderParams = new System.Drawing.Imaging.EncoderParameters(1); encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter( System.Drawing.Imaging.Encoder.Quality, 99L); image.Save(saveDialog.FileName, getEncoder(System.Drawing.Imaging.ImageFormat.Jpeg), encoderParams); }; break; } System.Diagnostics.Process.Start(thumbnailsView.CurrentObjectPath); } } }
public override void Run() { Result = new RgbImage <byte>(InputImage.Width, InputImage.Height); GrayHSLToRGB performer = new GrayHSLToRGB(); for (int i = 0; i < InputImage.PixelCount; i++) { byte R = 0; byte G = 0; byte B = 0; performer.HslToRgb((byte)Hue, (byte)Saturation, InputImage[i], out R, out G, out B); Result.RedChannel[i] = R; Result.GreenChannel[i] = G; Result.BlueChannel[i] = B; } }
/// <summary> /// Forms a tabulated pdf to importance sample the given image. /// </summary> /// <param name="image">The source image to importance sample</param> /// <returns>Tabulated pdf for the image.</returns> public virtual RegularGrid2d BuildSamplingGrid(RgbImage image) { var result = new RegularGrid2d(image.Width, image.Height); for (int row = 0; row < image.Height; ++row) { for (int col = 0; col < image.Width; ++col) { var x = col / (float)image.Width; var y = row / (float)image.Height; result.Splat(x, y, image.GetPixel(col, row).Luminance); } } result.Normalize(); return(result); }
public void Clone_GivenRgbImage_ShouldReturnNewInstanceWithSameBackgroundColour() { // Arrange. Image initialImage = new RgbImage { BackgroundColour = "red" }; // Act. var newImage = initialImage.Clone(); // Assert. Assert.NotNull(newImage); Assert.AreNotSame(initialImage, newImage); Assert.IsInstanceOf <RgbImage>(newImage); Assert.AreEqual(initialImage.BackgroundColour, newImage.BackgroundColour); }
public override void Run() { Result = new RgbImage <byte>(InputImage.Width, InputImage.Height); // TODO: impostare l'immagine Result come negativo dell'immagine InputImage //uso la look up table già fatta nella classe statica LookupTables, poi converto //l'immagine per avere il tipo RgbImage<byte> in output LookupTableTransform <RgbPixel <byte> > lt = new LookupTableTransform <RgbPixel <byte> >(InputImage, LookupTables.Spectrum); Image <RgbPixel <byte> > tmp = lt.Execute(); for (int i = 0; i < InputImage.PixelCount; i++) { Result.BlueChannel[i] = tmp[i].Blue; Result.RedChannel[i] = tmp[i].Red; Result.GreenChannel[i] = tmp[i].Green; } }
void RunScene(SceneConfig sceneConfig, string format, bool skipReference) { string dir = Path.Join(workingDirectory, sceneConfig.Name); if (!skipReference) { string refFilename = Path.Join(dir, "Reference" + format); RgbImage refImg = sceneConfig.GetReferenceImage(width, height); refImg.WriteToFile(refFilename); } // Prepare a scene for rendering. We do it once to reduce overhead. Scene scene = sceneConfig.MakeScene(); scene.FrameBuffer = MakeFrameBuffer("dummy"); scene.Prepare(); var methods = experiment.MakeMethods(); foreach (var method in methods) { string path = Path.Join(dir, method.Name); // Clear old files (if there are any) if (Directory.Exists(path)) { var dirinfo = new DirectoryInfo(path); foreach (var file in dirinfo.GetFiles()) { if (file.Extension == format) { file.Delete(); } } } Logger.Log($"Rendering {sceneConfig.Name} with {method.Name}"); scene.FrameBuffer = MakeFrameBuffer(Path.Join(path, "Render" + format)); method.Integrator.MaxDepth = sceneConfig.MaxDepth; method.Integrator.Render(scene); scene.FrameBuffer.WriteToFile(); } }
public override void Run() { //controllo se i grigi in input abbiano le stesse dimensioni if (Grigio1.Width != Grigio2.Width || Grigio2.Width != Grigio3.Width || Grigio1.Width != Grigio3.Width) { throw new Exception("la width non è la stessa per le 3 immagini di grigio in input"); } if (Grigio1.Height != Grigio2.Height || Grigio2.Height != Grigio3.Height || Grigio1.Height != Grigio3.Height) { throw new Exception("la height non è la stessa per le 3 immagini di grigio in input"); } Result = new RgbImage <byte>(Grigio1.Width, Grigio1.Height); for (int i = 0; i < Grigio1.PixelCount; i++) { Result.BlueChannel[i] = Grigio1[i]; Result.RedChannel[i] = Grigio2[i]; Result.GreenChannel[i] = Grigio3[i]; } }
public PictureEdit(RgbImage _stackResult, int count, string _filePath) { InitializeComponent(); stackResult = _stackResult; filePath = _filePath; minRUpDown.Value = 0; maxRUpDown.Value = (255 * 255 * count) / Kr; minGUpDown.Value = 0; maxGUpDown.Value = (255 * 255 * count) / Kg; minBUpDown.Value = 0; maxBUpDown.Value = (255 * 255 * count) / Kb; //stackResult.Divide( count ); //pictureBox.Image = stackResult.RenderBitmap(); }
void thumbnailsView_SelectionChanged(object sender, EventArgs e) { if (currentImage != null) { currentImage.Dispose(); currentImage = null; } if (stackedImage != null) { stackedImage.Dispose(); stackedImage = null; } if (stackedZoom != null) { stackedZoom.Dispose(); stackedZoom = null; } currentStack = null; currentStackIndex = 0; zoomCenterX = -1; zoomCenterY = -1; BgRnumericUpDown.Value = 0; BgGnumericUpDown.Value = 0; BgBnumericUpDown.Value = 0; MaxVNumericUpDown.Value = 1024; BgNumericUpDown.Value = 0; KgNumericUpDown.Value = 135; KbNumericUpDown.Value = 245; gammaNumericUpDown.Value = 0; satNumericUpDown.Value = 0; recalcCurve(); hideStackPanel(); var start = DateTime.Now; updateImageView(); System.Diagnostics.Trace.WriteLine(string.Format("TIMER: {0} ms", (DateTime.Now - start).TotalMilliseconds)); stackButton.Enabled = thumbnailsView.SelectedImages.Any(); }
public override void Run() { Result = new RgbImage <byte>(InputImage.Width, InputImage.Height); //inizializza look up table for (int i = 0; i < 256; i++) { //per ogni possibile pixel bianco / nero, calcola il risultato //così si applica alla matrice direttamente la look up table //senza fare più calcoli lut[i] = (i + Lightness * 255 / 100).ClipToByte(); } for (int i = 0; i < InputImage.PixelCount; i++) { //applico la look up table su ogni canale RGB Result.BlueChannel[i] = lut[InputImage.BlueChannel[i]]; Result.RedChannel[i] = lut[InputImage.RedChannel[i]]; Result.GreenChannel[i] = lut[InputImage.GreenChannel[i]]; } }
private void showZoomAt(Point e) { if (stackedZoom != null) { stackedZoom.Dispose(); stackedZoom = null; } if (pictureBox.Image == null) { return; } if (noZoomRadioButton.Checked) { zoom1xRadioButton.Checked = true; } var clientSize = pictureBox.ClientSize; var rawSize = currentImage.RawSize; int dX = 0; int dY = 0; float scaleX = (1.0f * rawSize.Width) / clientSize.Width; float scaleY = (1.0f * rawSize.Height) / clientSize.Height; float scale = 1; if (scaleX > scaleY) { scale = scaleX; dY = (clientSize.Height - (int)(rawSize.Height / scale)) / 2; } else { scale = scaleY; dX = (clientSize.Width - (int)(rawSize.Width / scale)) / 2; } zoomCenterX = (int)((e.X - dX) * scale); zoomCenterY = (int)((e.Y - dY) * scale); showZoomImage(); }
public override void Run() { //controllo che le 3 immagini in input abbiano le stesse dimensioni if (Hue.Width != Saturation.Width || Saturation.Width != Lightness.Width || Hue.Width != Lightness.Width) { throw new Exception("immagini di dimensioni diverse"); } if (Hue.Height != Saturation.Height || Saturation.Height != Lightness.Height || Hue.Height != Lightness.Height) { throw new Exception("immagini di dimensioni diverse"); } Result = new RgbImage <byte>(Hue.Width, Hue.Height); for (int i = 0; i < Hue.PixelCount; i++) { byte tmpR = 0; byte tmpG = 0; byte tmpB = 0; //conversione pixel per pixel HslToRgb(Hue[i], Saturation[i], Lightness[i], out tmpR, out tmpG, out tmpB); Result.RedChannel[i] = tmpR; Result.GreenChannel[i] = tmpG; Result.BlueChannel[i] = tmpB; } }
public ImageArithmeticRGB(RgbImage <byte> image1, RgbImage <byte> image2) : this(image1, image2, defaultOperation) { }
public ImageArithmeticRGB(RgbImage <byte> image1, RgbImage <byte> image2, ImageArithmeticOperation operation) : base(image1, image2) { Operation = operation; }
public override void Run() { Result = new RgbImage <byte>(InputImage1.Width, InputImage1.Height); //implemento tutti gli enum per ciascun canale RGB //somma if (Operation == ImageArithmeticOperation.Add) { for (int i = 0; i < InputImage1.PixelCount; i++) { int tmp = InputImage1.BlueChannel[i] + InputImage2.BlueChannel[i]; if (tmp > 255) { tmp = 255; } Result.BlueChannel[i] = (byte)tmp; tmp = InputImage1.RedChannel[i] + InputImage2.RedChannel[i]; if (tmp > 255) { tmp = 255; } Result.RedChannel[i] = (byte)tmp; tmp = InputImage1.GreenChannel[i] + InputImage2.GreenChannel[i]; if (tmp > 255) { tmp = 255; } Result.GreenChannel[i] = (byte)tmp; } return; } //AND binario bit per bit if (Operation == ImageArithmeticOperation.And) { for (int i = 0; i < InputImage1.PixelCount; i++) { Result.BlueChannel[i] = (byte)(InputImage1.BlueChannel[i] & InputImage2.BlueChannel[i]); Result.RedChannel[i] = (byte)(InputImage1.RedChannel[i] & InputImage2.RedChannel[i]); Result.GreenChannel[i] = (byte)(InputImage1.GreenChannel[i] & InputImage2.GreenChannel[i]); } return; } //media fra i 2 pixel if (Operation == ImageArithmeticOperation.Average) { for (int i = 0; i < InputImage1.PixelCount; i++) { Result.BlueChannel[i] = (byte)((InputImage1.BlueChannel[i] + InputImage2.BlueChannel[i]) / 2); Result.RedChannel[i] = (byte)((InputImage1.RedChannel[i] + InputImage2.RedChannel[i]) / 2); Result.GreenChannel[i] = (byte)((InputImage1.GreenChannel[i] + InputImage2.GreenChannel[i]) / 2); } return; } //darkest, vince il valore minore if (Operation == ImageArithmeticOperation.Darkest) { for (int i = 0; i < InputImage1.PixelCount; i++) { Result.BlueChannel[i] = (InputImage1.BlueChannel[i] < InputImage2.BlueChannel[i]) ? InputImage1.BlueChannel[i] : InputImage2.BlueChannel[i]; Result.RedChannel[i] = (InputImage1.RedChannel[i] < InputImage2.RedChannel[i]) ? InputImage1.RedChannel[i] : InputImage2.RedChannel[i]; Result.GreenChannel[i] = (InputImage1.GreenChannel[i] < InputImage2.GreenChannel[i]) ? InputImage1.GreenChannel[i] : InputImage2.GreenChannel[i]; } return; } //calcola il modulo della differenza if (Operation == ImageArithmeticOperation.Difference) { for (int i = 0; i < InputImage1.PixelCount; i++) { int diff = InputImage1.BlueChannel[i] - InputImage2.BlueChannel[i]; if (diff < 0) { diff *= (-1); } Result.BlueChannel[i] = (byte)diff; diff = InputImage1.RedChannel[i] - InputImage2.RedChannel[i]; if (diff < 0) { diff *= (-1); } Result.RedChannel[i] = (byte)diff; diff = InputImage1.GreenChannel[i] - InputImage2.GreenChannel[i]; if (diff < 0) { diff *= (-1); } Result.GreenChannel[i] = (byte)diff; } return; } //lightest, vince il più chiaro if (Operation == ImageArithmeticOperation.Lightest) { for (int i = 0; i < InputImage1.PixelCount; i++) { Result.BlueChannel[i] = (InputImage1.BlueChannel[i] < InputImage2.BlueChannel[i]) ? InputImage2.BlueChannel[i] : InputImage1.BlueChannel[i]; Result.RedChannel[i] = (InputImage1.RedChannel[i] < InputImage2.RedChannel[i]) ? InputImage2.RedChannel[i] : InputImage1.RedChannel[i]; Result.GreenChannel[i] = (InputImage1.GreenChannel[i] < InputImage2.GreenChannel[i]) ? InputImage2.GreenChannel[i] : InputImage1.GreenChannel[i]; } return; } //or binario bit per bit per ogni pixel if (Operation == ImageArithmeticOperation.Or) { for (int i = 0; i < InputImage1.PixelCount; i++) { Result.BlueChannel[i] = (byte)(InputImage1.BlueChannel[i] | InputImage2.BlueChannel[i]); Result.RedChannel[i] = (byte)(InputImage1.RedChannel[i] | InputImage2.RedChannel[i]); Result.GreenChannel[i] = (byte)(InputImage1.GreenChannel[i] | InputImage2.GreenChannel[i]); } return; } //substract, differenza, se fuori dai limiti ci mette 0 if (Operation == ImageArithmeticOperation.Subtract) { for (int i = 0; i < InputImage1.PixelCount; i++) { int diff = InputImage1.BlueChannel[i] - InputImage2.BlueChannel[i]; if (diff < 0) { diff = 0; } Result.BlueChannel[i] = (byte)diff; diff = InputImage1.RedChannel[i] - InputImage2.RedChannel[i]; if (diff < 0) { diff = 0; } Result.RedChannel[i] = (byte)diff; diff = InputImage1.GreenChannel[i] - InputImage2.GreenChannel[i]; if (diff < 0) { diff = 0; } Result.GreenChannel[i] = (byte)diff; } return; } //xor binario bit per bit per ogni pixel if (Operation == ImageArithmeticOperation.Xor) { for (int i = 0; i < InputImage1.PixelCount; i++) { Result.BlueChannel[i] = (byte)(InputImage1.BlueChannel[i] ^ InputImage2.BlueChannel[i]); Result.RedChannel[i] = (byte)(InputImage1.RedChannel[i] ^ InputImage2.RedChannel[i]); Result.GreenChannel[i] = (byte)(InputImage1.GreenChannel[i] ^ InputImage2.GreenChannel[i]); } return; } }
public TrasformazioneAffineRgb(RgbImage <byte> inputImage, double scaleFactor, RgbPixel <byte> background) : base(inputImage, scaleFactor) { Background = background; }
/// <summary> /// Called once before the first rendering iteration /// </summary> /// <param name="width">The width of the frame buffer</param> /// <param name="height">The height of the frame buffer</param> public override void Init(int width, int height) => Image = new RgbImage(width, height);
private async void фокусToolStripMenuItem_Click(object sender, EventArgs e) { try { OpenFileDialog op = new OpenFileDialog(); op.Multiselect = true; if (op.ShowDialog() == DialogResult.OK) { await Task.Run(() => { try { List <Bitmap> images = new List <Bitmap>(); var fileNames = op.FileNames; for (int i = 0; i < fileNames.Length; i++) { images.Add((Bitmap)Bitmap.FromFile(fileNames[i])); } int Width = images[0].Width; int Height = images[0].Height; Bitmap result = new Bitmap(Width, Height); List <double[, ]> gray = new List <double[, ]>(); foreach (var image in images) { gray.Add(RgbImage.FromBitmap(image).ToGrayScale()); } for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { List <double> values = new List <double>(); for (int i = 0; i < gray.Count; i++) { values.Add(ImageProcessing.ImageWrapper.Focus(gray[i], x, y)); } int max = values.IndexOf(values.Max()); result.SetPixel(x, y, images[max].GetPixel(x, y)); } } Image = result; } catch (ArgumentOutOfRangeException ex) { MessageBox.Show("Изображения должны иметь одинаковый размер"); } catch (IOException ex) { MessageBox.Show("Ошибка при открытии файлов"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 2010/04/26, 位图转化为RGBImage. /// </summary> /// <param name="bmp"></param> /// <param name="rgbImg"></param> /// <param name="width"></param> /// <param name="height"></param> public static void Bitmap2RGBImage(Bitmap bmp, out RgbImage rgbImg, out int width, out int height) { int[][][] rgb_mat; Bitmap2MatColor(bmp, out rgb_mat, out width, out height); rgbImg = new RgbImage(rgb_mat, width, height); }
public TrasformazioneAffineRgb(RgbImage <byte> inputImage, double translationX, double translationY, double rotationDegrees, double scaleFactorX, double scaleFactorY, RgbPixel <byte> background, int resultWidth, int resultHeight) : base(inputImage, translationX, translationY, rotationDegrees, scaleFactorX, scaleFactorY, resultWidth, resultHeight) { Background = background; }
public TrasformazioneAffineRgb(RgbImage <byte> inputImage, double translationX, double translationY, double rotationDegrees, RgbPixel <byte> background) : base(inputImage, translationX, translationY, rotationDegrees) { Background = background; }
private RgbImage stackImages2(Rectangle rect, out int count) { //var start = DateTime.Now; var currentOffset = currentStack[currentStackIndex].Offset; rect.Offset(-currentOffset.X, -currentOffset.Y); count = 0; var p = new Int64[4][]; foreach (var item in currentStack) { if (!item.IsExcluded) { using (var rawImage = libraw.load_raw(item.FilePath)) { var _rect = rect; _rect.Offset(item.Offset); //rawImage.ApplyDark( currentSession.Dark ); if (currentSession.Flat != null) { //rawImage.ApplyFlat( currentSession.Flat, 32 ); } int channel = rawImage.Channel(_rect.X, _rect.Y); var _pixels = rawImage.GetRawPixelsApplyFlat(_rect, currentSession.Flat, 64); if (p[channel] == null) { var pixels = p[channel] = new Int64[rect.Width * rect.Height]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = _pixels[i]; //pixels[i] -= 128; } } else { var pixels = p[channel]; for (int i = 0; i < pixels.Length; i++) { pixels[i] += _pixels[i]; //pixels[i] -= 128; } } count++; GC.Collect(); Application.DoEvents(); } } } GC.Collect(0); //Application.DoEvents(); var result = new RgbImage(rect.Width - 4, rect.Height - 4); ushort[] upixels = new ushort[rect.Width * rect.Height]; for (int ch = 0; ch < 4; ch++) { if (p[ch] != null) { var pixels = p[ch]; Array.Clear(upixels, 0, upixels.Length); if (currentSession.Flat != null) { for (int i = 0; i < pixels.Length; i++) { upixels[i] = (ushort)(pixels[i] / 640 + 128); } } else { for (int i = 0; i < pixels.Length; i++) { upixels[i] = (ushort)(pixels[i]); } } using (var raw = new RawImage(rect.Width, rect.Height, ch, upixels)) using (var rgbImage = raw.ExtractRgbImage(new Rectangle(2, 2, rect.Width - 4, rect.Height - 4))) { result.Add(rgbImage); } } } //MessageBox.Show( ( DateTime.Now - start ).TotalMilliseconds.ToString( "0.00" ) ); return(result); }
public EnvironmentMap(RgbImage image) { this.Image = image; directionSampler = BuildSamplingGrid(image); }