private void button1_Click_1(object sender, EventArgs e) { Bitmap RawIMG; ImageDataProcessor imgp = new ImageDataProcessor(); Int32[,] _imagearray = imgp.ReadRaw("C:\\temp\\IMG_2s_100iso_0C_2020-06-14--01-01-33.NEF"); var buffer = new byte[_imagearray.GetLength(0) * _imagearray.GetLength(1) * System.Runtime.InteropServices.Marshal.SizeOf(typeof(Int16))]; Buffer.BlockCopy(_imagearray, 0, buffer, 0, buffer.Length); var flatarray = FlipAndConvert2d(_imagearray); byte[] flatarraybyte = new byte[flatarray.Length * 2]; Buffer.BlockCopy(flatarray, 0, flatarraybyte, 0, flatarray.Length * 2); RawIMG = Contrast(ColorBalance(createImage(_imagearray), 50, 50, 50), 15); RawIMG.Save("C:\\temp\\test.png"); pictTestfrm.Image = RawIMG; }
public Camera() { _settingsProvider = new CameraSettingsProvider(); _imageDataProcessor = new ImageDataProcessor(); ReadProfile(); tl = new TraceLogger("", "DSLR"); tl.Enabled = CameraSettings.TraceLog; connectedState = false; }
private static void WriteImageStatistics(ImageDataProcessor dataProcessor, Array array) { var stats = dataProcessor.GetImageStatistics(array); if (stats != null) { Console.WriteLine( $"Image statistics: ADU min/max/mean/median: {stats.MinADU}/{stats.MaxADU}/{stats.MeanADU}/{stats.MedianADU}."); } else { Console.WriteLine("Image statistics not available."); } }
private void button1_Click_1(object sender, EventArgs e) { Bitmap RawIMG; ImageDataProcessor imgp = new ImageDataProcessor(); //Bitmap Test = new Bitmap("C:\\temp\\allskynikon.jpg"); Int32[,] _imagearray = imgp.ReadRaw("C:\\temp\\canon2.CR2"); //RawIMG = Contrast(ColorBalance(createImage(_imagearray), 50, 50, 50), 15); //RawIMG = createImage(_imagearray); RawIMG = createImage(_imagearray); RawIMG.Save("C:\\temp\\test.png"); pictTestfrm.Image = RawIMG; }
static void Main() { ExecuteCommand("--status --debug --timeout 3"); var d = ParseStatus(File.ReadAllText(@"c:\git-vtorkalo\ASCOM.DSLR\testdata\status.txt")); var p = new ImageDataProcessor(); var detector = new CameraModelDetector(p); var data0 = p.ReadRaw(@"d:\ascomdev\git\ASCOM.DSLR\testdata\test.dng-0000.dng"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
static void Main(string[] args) { var cameraModels = JsonConvert.DeserializeObject <CameraModel[]>(File.ReadAllText("cameramodels.json")); SonyCamera camera = new SonyCamera(cameraModels.First(m => m.ID == "SLTA99"), ImageFormat.CFA, false); camera.ExposureReady += Camera_ExposureReady; camera.ExposureCompleted += Camera_ExposureCompleted; Console.WriteLine("Press S to take exposure.\nPress R to read ARW file and save to grayscale TIFF.\nPress D to read ARW file and save to color TIFF.\nPress J to read JPEG file and save to color TIFF.\nPress E to exit program."); do { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.S) { if (camera.IsConnected() == false) { camera.Connect(); } camera.StartExposure(400, 3, true); } else if (key.Key == ConsoleKey.R) { ImageDataProcessor dataProcessor = new ImageDataProcessor(); Console.Write("Reading RAW file to array ..."); uint[,] array = dataProcessor.ReadRaw("D:\\astrophoto\\test\\test.ARW"); Console.WriteLine(" Done."); Console.WriteLine($"Array length: {array.LongLength*4} bytes"); WriteImageStatistics(dataProcessor, array); Console.Write("Saving to tiff..."); SaveToGrayscaleTiff("D:\\astrophoto\\test\\grayscale.tiff", array); Console.WriteLine(" Done."); } else if (key.Key == ConsoleKey.D) { ImageDataProcessor dataProcessor = new ImageDataProcessor(); Console.Write("Reading RAW file and debayer to array ..."); uint[,,] array = dataProcessor.ReadAndDebayerRaw("D:\\astrophoto\\test\\test.ARW"); Console.WriteLine(" Done."); Console.WriteLine($"Array length: {array.LongLength*4} bytes"); WriteImageStatistics(dataProcessor, array); Console.Write("Saving to tiff..."); SaveToColorTiff("D:\\astrophoto\\test\\color.tiff", array); Console.WriteLine(" Done."); } else if (key.Key == ConsoleKey.J) { ImageDataProcessor dataProcessor = new ImageDataProcessor(); Console.Write("Reading JPEG file array ..."); uint[,,] array = dataProcessor.ReadJpeg("D:\\astrophoto\\test\\test.JPG"); Console.WriteLine(" Done."); Console.WriteLine($"Array length: {array.LongLength} bytes"); WriteImageStatistics(dataProcessor, array); Console.Write("Saving to tiff..."); SaveToColor8bitTiff("D:\\astrophoto\\test\\jpeg.tiff", array); Console.WriteLine(" Done."); } else if (key.Key == ConsoleKey.A) { Console.Write("Writing camera models to json..."); //serialize CameraModel to JSON CameraModel.Models = new CameraModel[] { _sltA99 }; string json = JsonConvert.SerializeObject(CameraModel.Models); File.WriteAllText("test.json", json); Console.WriteLine(" Done."); Console.Write("Writing camera models from json..."); var models = JsonConvert.DeserializeObject <CameraModel[]>(File.ReadAllText("test.json")); Console.WriteLine($" Done. Read {models.Length} models."); } else if (key.Key == ConsoleKey.E) { break; } } while (true); }
Bitmap createImage(Int32[,] Iarray) { Bitmap bmp = new Bitmap(Iarray.GetLength(0), Iarray.GetLength(1), System.Drawing.Imaging.PixelFormat.Format64bppArgb); int r = 0; int g = 0; int g1 = 0; int b = 0; int R = 0; int G = 0; int B = 0; int G1 = 0, G2 = 0, G3 = 0, G4 = 0; int B1 = 0, B2 = 0, B3 = 0, B4 = 0; int R1 = 0, R2 = 0, R3 = 0, R4 = 0; ImageDataProcessor imgp = new ImageDataProcessor(); for (int y = 0; y < Iarray.GetLength(1); y++) { for (int x = 0; x < Iarray.GetLength(0); x++) { unsafe { fixed(int *p = &Iarray[x, y]) { int *p2 = p; r = *p2 / 255; r = (r < 0) ? 0 : r; r = (r > 255) ? 254 : r; p2 += 1; g = *p2 / 255; g = (g < 0) ? 0 : g; g = (g > 255) ? 254 : g; p2 += 1; g1 = *p2 / 255; g1 = (g1 < 0) ? 0 : g1; g1 = (g1 > 255) ? 254 : g1; p2 += 1; b = *p2 / 255; b = (b < 0) ? 0 : b; b = (b > 255) ? 254 : b; } R = r; G = (g + g1) / 2; B = b; } R = (R < 0) ? 0 : R; R = (R > 255) ? 254 : R; G = (G < 0) ? 0 : G; G = (G > 255) ? 254 : G; B = (B < 0) ? 0 : B; B = (B > 255) ? 254 : B; Color Color = Color.FromArgb(R, G, B); bmp.SetPixel(x, y, Color); R = 0; G = 0; B = 0; } } return(bmp); }