private void DisplaySelectedImage(string fileName) { _fits = new FITS(fileName); if (!_headerMode) { Scale(); pictureBox.Image = _fits.Bitmap; } textBoxHeader.Text = _fits.Header.Text; toolStripStatusLabel.Text = Path.GetFileName(fileName); }
public FITS(FITS that) { Header.Bitpix = that.Header.Bitpix; Header.Width = that.Header.Width; Header.Height = that.Header.Height; FileName = that.FileName; PixelMap = new double[Header.Width * Header.Height]; for (int i = 0; i < Header.Width * Header.Height; i++) { PixelMap[i] = that.PixelMap[i]; } Bitmap = new Bitmap(that.Bitmap); Scaled = that.Scaled; }
// scale data to bitmap. Zscale, if that is possible. private void ZScale(FITS fits) { int width = fits.Header.Width; int height = fits.Header.Height; int size = width * height; fits.Bitmap = new Bitmap(width, height); float contrast = 0.25f; int NSample = Math.Min(size / 10, 10000); int NRows = height / 15; int[] SubSampleX = new int[NSample]; int[] SubSampleY = new int[NSample]; double[] SubSample = new double[NSample]; double[] SubSampleSorted = new double[NSample]; Random random = new Random(DateTime.Now.Millisecond); for (int cell = 0; cell < NSample; cell++) { int X = SubSampleX[cell] = random.Next(1, width - 1); int Y = SubSampleY[cell] = random.Next(1, height - 1); SubSample[cell] = fits.PixelMap[X + Y * width]; } float[] tmp = new float[NSample]; SubSample.CopyTo(SubSampleSorted, 0); Array.Sort(SubSampleSorted); double zmin = SubSampleSorted[0]; double zmed = SubSampleSorted[NSample / 2]; double zmax = SubSampleSorted[NSample - 1]; int midPoint = NSample / 2; double Sx = 0.5f * NSample * (NSample - 1); double Sy = SubSampleSorted.Sum(); double Sxx = Count_Sxx(SubSampleSorted); double Sxy = Count_Sxy(SubSampleSorted); double a = (NSample * Sxy - Sx * Sy) / (NSample * Sxx - Sx * Sx); double b = (Sy - a * Sx) / NSample; a /= contrast; double scale; double value; // The minimum value to use for display scaling float z1 = Math.Max((float)fits.Min, (float)(zmed - midPoint * a)); // The maximum value to use for display scaling float z2 = Math.Min((float)fits.Max, (float)(zmed + midPoint * a)); fits.Range = Math.Abs(z2 - z1); if (fits.Range < float.Epsilon) { scale = 0.0; } else { scale = byte.MaxValue / fits.Range; } Color newColor; byte byteValue; double temp; for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { value = fits.PixelMap[w + h * width]; /* Min - max scaling --------------------------------*/ temp = (value - z1) * scale; if (temp > 255.0) { byteValue = 255; } else { byteValue = (byte)temp; } /* _________________________________________________ */ newColor = Color.FromArgb(byteValue, byteValue, byteValue); fits.Bitmap.SetPixel(width - w - 1, height - h - 1, newColor); } } fits.Scaled = true; }