/** * @brief * Creat an ImageF from a Bitmap * * The function takes the intensity of each pixel by adding the RGB values * * @param bm The bitmap to wrap * @return The created ImageF * * @note The funcion is declared <i>unsafe</i> since it uses pointers to the * bitmap data to speed-up the process ofg conversion */ unsafe static public ImageF FromBitmap(Bitmap bm) { Rectangle rect = new Rectangle(new Point(0, 0), bm.Size); BitmapData pixels = bm.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); var image = new ImageF(bm.Width, bm.Height); for (int y = 0; y < bm.Height; y++) { int scan = y * pixels.Stride; for (int x = 0; x < bm.Width; x++) { int offset = scan + 3 * x; byte r = ((byte *)pixels.Scan0)[offset]; byte g = ((byte *)pixels.Scan0)[offset + 1]; byte b = ((byte *)pixels.Scan0)[offset + 2]; double v = (r + g + b) / (256.0 * 3.0); image.imageData[x, y] = v; } } bm.UnlockBits(pixels); return(image); }
/** * @brief * Create an ImageF from a two-dimensional array * * @param array The two dimensional arry to wrap in an ImageF * @return The created ImageF */ static public ImageF FromArray(double[,] array) { ImageF result = new ImageF(); result.imageData = array; return(result); }
/** * @brief * Perform a single iteration * * @return The new estimate of the image */ public ImageF Iterate() { ImageF In = Psf.Convolute(Sn); ImageF Cn = Psf.ConvoluteTranspose(Image / In); Sn *= Cn; return(Sn); }
private void menuFileOpen_Click(object sender, EventArgs e) { if (this.openFileDialog.ShowDialog() == DialogResult.OK) { String theFile = openFileDialog.FileName; photograph = new PhotographData(theFile); iImage = Bitmap.FromFile(theFile); iImageF = ImageF.FromBitmap(iImage as Bitmap); this.pictureMain.Size = iImage.Size; pictureMain.Image = iImage; //this.AutoScrollMinSize = new Size(iImage.Width, iImage.Height); } }
/** * @brief * Multiply this object with an ImageF pixelwise * * @param rhs * ImageF object to multiply with * * @return * The result of the multiplication */ public ImageF Multiply(ImageF rhs) { ImageF result = new ImageF(Width, Height); for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { result.imageData[i, j] = this[i, j] * rhs[i, j]; } } return(result); }
/** * @brief * Create an image with a constant pixel value * * @param width Width of the image * @param height Height of the omage * @param value Value to set each pixel to */ public static ImageF ConstantImage(int width, int height, double value) { ImageF result = new ImageF(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { result.imageData[i, j] = value; } } return(result); }
/** * @brief * Divide this object by an ImageF pixelwise * * @param rhs * ImageF object to divide by * * @return * The result of the division * * @note Even ifg a pixel in rhs is 0, the division will not fail */ public ImageF Divide(ImageF rhs) { double Limit = 0.0000001; ImageF result = new ImageF(Width, Height); for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { result.imageData[i, j] = this[i, j] / Math.Max(rhs[i, j], Limit); } } return(result); }
/** * @brief * Add an ImageF pixelwise to this object * * @param rhs * ImageF object to add * * @return * The result of the addition */ public ImageF Add(ImageF rhs) { Debug.Assert(Width == rhs.Width && Height == rhs.Height); var result = new ImageF(Width, Height); for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { result.imageData[i, j] = this[i, j] + rhs[i, j]; } } return(result); }
private void CheckSize(ImageF image) { if (Convolver == null || FftSize.Width != image.Width || FftSize.Height != image.Height) { FftSize = new Size(image.Width, image.Height); double[,] imgData = new double[FftSize.Width, FftSize.Height]; for (int x = 0; x < FftSize.Width; x++) { for (int y = 0; y < FftSize.Height; y++) { imgData[x, y] = this[x + Xmin, y + Ymin]; } } Convolver = new FftwConvolver.FftwConvolver(FftSize, imgData, new Point(-Xmin, -Ymin)); } }
private void btnLoad_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "PhotoData|*.pds"; dlg.DefaultExt = "pds"; if (dlg.ShowDialog() == DialogResult.OK) { photograph = PhotographData.Load(dlg.FileName); iImage = Bitmap.FromFile(photograph.Image); iImageF = ImageF.FromBitmap(iImage as Bitmap); this.pictureMain.Size = iImage.Size; pictureMain.Image = iImage; foreach (SpatiallyVariantPsf thePsf in photograph.PSFs) { this.imageScan1.Add(thePsf); } } }
public static ImageF Starfield(int width, int height, int nStars, double noise) { ImageF result = new ImageF(width, height); Random rand = new Random(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { result.imageData[x, y] = rand.NextDouble() * noise; } } for (int i = 0; i < nStars; i++) { int x = rand.Next(width); int y = rand.Next(height); result.imageData[x, y] = 1.0; } return(result); }
public static ImageF RandomPixelImage(int width, int height, int nPoints) { ImageF result = new ImageF(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { result.imageData[x, y] = 0.0; } } Random rand = new Random(); for (int i = 0; i < nPoints; i++) { int x = rand.Next(width); int y = rand.Next(height); result.imageData[x, y] = 1.0; } return(result); }
/** * @brief * Constructor * * @param image * The image * @param psf * The %PSF to de-convolve * * Note that it is not important to know about the %PSF, just that * it is an object that can convolve itself withan image */ public RichardsonLucyDeconvolution(ImageF image, IConvolutable psf) { Image = image; Psf = psf; Sn = ImageF.ConstantImage(image.Width, image.Height, 0.5); }
public ImageF ConvoluteTranspose(ImageF image) { throw new NotImplementedException(); }
unsafe static public PSF FromBitmap(ImageF image, Point pos) { PSF thePsf = new PSF(); ScanLineAnalyzer analyzer = new ScanLineAnalyzer(image, pos.Y, pos.X); analyzer.FindBackground(); thePsf._xmin = analyzer.LeftBackgroundPosition; thePsf._xmax = analyzer.RightBackgroundPosition; List <double> row = new List <double>(); for (int x = analyzer.LeftBackgroundPosition; x <= analyzer.RightBackgroundPosition; x++) { row.Add(image[x, pos.Y]); } thePsf.iData[0] = row; do { analyzer.ScanLine--; analyzer.Analyze(); if (analyzer.LeftBackgroundPosition < thePsf.Xmin) { thePsf.Xmin = analyzer.LeftBackgroundPosition; } if (analyzer.RightBackgroundPosition > thePsf.Xmax) { thePsf.Xmax = analyzer.RightBackgroundPosition; } row = new List <double>(); for (int x = thePsf.Xmin; x <= thePsf.Xmax; x++) { if (x < analyzer.LeftBackgroundPosition || x > analyzer.RightBackgroundPosition) { row.Add(0.0); } else { row.Add(image[x, (int)analyzer.ScanLine]); } } thePsf.iData.Insert(0, row); thePsf._ymin = (int)analyzer.ScanLine; } while(!analyzer.IsBackgroundLine); analyzer.ScanLine = pos.Y; do { analyzer.ScanLine++; analyzer.Analyze(); if (analyzer.LeftBackgroundPosition < thePsf.Xmin) { thePsf.Xmin = analyzer.LeftBackgroundPosition; } if (analyzer.RightBackgroundPosition > thePsf.Xmax) { thePsf.Xmax = analyzer.RightBackgroundPosition; } row = new List <double>(); for (int x = thePsf.Xmin; x <= thePsf.Xmax; x++) { if (x < analyzer.LeftBackgroundPosition || x > analyzer.RightBackgroundPosition) { row.Add(0.0); } else { row.Add(image[x, (int)analyzer.ScanLine]); } } thePsf.iData.Add(row); thePsf._ymax = (int)analyzer.ScanLine; } while (!analyzer.IsBackgroundLine); thePsf.Normalize(); return(thePsf); }
public ScanLineAnalyzer(ImageF image) { Image = image; }
public ScanLineAnalyzer(ImageF image, int scanLine) { Image = image; ScanLine = scanLine; }
/// <summary> /// Constructor /// </summary> /// <param name="image"></param> /// <param name="scanLine"></param> /// <param name="xCenter"></param> public ScanLineAnalyzer(ImageF image, int scanLine, int xCenter) { Image = image; ScanLine = scanLine; XCenter = xCenter; }
public ImageF ConvoluteTranspose(ImageF image) { CheckSize(image); return(ImageF.FromArray(Convolver.Convolve(image.ToRawData))); }