static void Main(string[] args) { try { if (args.Length < 4) { Console.WriteLine("Usage: SimpleElastix <fixedImage> <movingImage> <parameterFile> <output>"); return; } // Instantiate SimpleElastix ElastixImageFilter silx; // Read input ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); silx.SetFixedImage(reader.Execute()); reader.SetFileName(args[1]); silx.SetMovingImage(reader.Execute()); silx.SetParameterMap(ReadParameterFile(args[2])); // Perform Registration silx.LogToConsoleOn(); silx.Execute(); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[3]); writer.Execute(silx.GetResultImage()); } catch (Exception e) { Console.WriteLine(e); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>"); return; } // Read input image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); Image image = reader.Execute(); // Execute Gaussian smoothing filter SmoothingRecursiveGaussianImageFilter gaussian = new SmoothingRecursiveGaussianImageFilter(); gaussian.SetSigma(Double.Parse(args[1])); Image blurredImage = gaussian.Execute(image); // Covert the real output image back to the original pixel type , to // make writing easier , as many file formats don 't support real // pixels . CastImageFilter castFilter = new CastImageFilter(); castFilter.SetOutputPixelType(image.GetPixelID()); Image destImage = castFilter.Execute(blurredImage); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(destImage); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>"); return; } // Read input image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); Image image = reader.Execute(); // Execute Gaussian smoothing filter SmoothingRecursiveGaussianImageFilter gaussian = new SmoothingRecursiveGaussianImageFilter(); gaussian.SetSigma(Double.Parse(args[1])); image = gaussian.Execute(image); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(image); } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// Load crosshair texture. /// </summary> private void LoadCrosshairTexture() { // Load crosshair image ImageFileReader reader = new ImageFileReader(host.Arena2Path); reader.LibraryType = LibraryTypes.Cif; DFImageFile crosshair = reader.GetImageFile("PNTER.CIF"); DFBitmap crosshairBitmap = crosshair.GetBitmapFormat(4, 0, 0, DFBitmap.Formats.RGBA); // Create texture crosshairTexture = new Texture2D( host.GraphicsDevice, crosshairBitmap.Width, crosshairBitmap.Height, false, SurfaceFormat.Color); // Set data crosshairTexture.SetData <byte>( 0, null, crosshairBitmap.Data, 0, crosshairBitmap.Width * crosshairBitmap.Height * 4); }
public override Texture2DContent Import(string filename, ContentImporterContext context) { // Load Arena2Path.txt arena2Path = File.ReadAllText( Path.Combine(Path.GetDirectoryName(filename), Arena2PathTxt)); // Read input text string input = File.ReadAllText(filename); // Remove new lines input = input.Replace('\n', ' ').Trim(); input = input.Replace('\r', ' ').Trim(); // Get source information string[] lines = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string textureFilename = lines[0].Trim(); int record = Convert.ToInt32(lines[1].Trim()); int frame = Convert.ToInt32(lines[2].Trim()); // Get bitmap in RGBA format ImageFileReader fileReader = new ImageFileReader(arena2Path); DFImageFile imageFile = fileReader.LoadFile(textureFilename); DFBitmap dfBitmap = imageFile.GetBitmapFormat(record, frame, 0, DFBitmap.Formats.RGBA); // Set bitmap data BitmapContent bitmapContent = new PixelBitmapContent <Color>(dfBitmap.Width, dfBitmap.Height); bitmapContent.SetPixelData(dfBitmap.Data); Texture2DContent tc = new Texture2DContent(); tc.Faces[0] = bitmapContent; return(tc); }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: {0} <input> <variance> <output>", args[0]); return; } // Read input image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); Image image = reader.Execute(); // Execute Gaussian smoothing filter DiscreteGaussianImageFilter filter = new DiscreteGaussianImageFilter(); filter.SetVariance(Double.Parse(args[1])); MyCommand cmd = new MyCommand(filter); filter.AddCommand(EventEnum.sitkProgressEvent, cmd); image = filter.Execute(image); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(image); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main(string[] args) { try { if (args.Length < 1) { Console.WriteLine("Usage: ImageIOSelection image_input_file"); return; } // Find out which image IOs are supported ImageFileReader reader = new ImageFileReader(); itk.simple.VectorString image_ios = reader.GetRegisteredImageIOs(); Console.Write("The supported image IOs are: "); for (int i = 0; i < image_ios.Count; i++) { Console.Write(image_ios[i] + " "); } Console.WriteLine("\n--------------------"); // Another option is to just print the reader and see which // IOs are supported Console.WriteLine(reader.ToString()); Console.WriteLine("--------------------"); // Force the use of a specific IO. If the IO doesn't support // reading the image type it will throw an exception. reader.SetImageIO("PNGImageIO"); reader.SetFileName(args[0]); Image image = reader.Execute(); Console.WriteLine("Read image: " + args[0]); } catch (Exception ex) { Console.WriteLine("Read failed: " + ex); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>"); return; } // Read input image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); Image image = reader.Execute(); // Execute Gaussian smoothing filter SmoothingRecursiveGaussianImageFilter gaussian = new SmoothingRecursiveGaussianImageFilter(); gaussian.SetSigma(Double.Parse(args[1])); Image blurredImage = gaussian.Execute(image); // Covert the real output image back to the original pixel type , to // make writing easier , as many file formats don 't support real // pixels . CastImageFilter castFilter = new CastImageFilter(); castFilter.SetOutputPixelType(image.GetPixelIDValue()); Image destImage = castFilter.Execute(blurredImage); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(destImage); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>"); return; } ImageFileReader reader = new ImageFileReader(); reader.setFileName(args[0]); SmartPointerImage image = reader.execute(); Console.WriteLine(image.toString()); Gaussian gaussian = new Gaussian(); gaussian.setSigma(Double.Parse(args[1])); image = gaussian.execute(image); Console.WriteLine(image.toString()); ImageFileWriter writer = new ImageFileWriter(); writer.setFileName(args[2]); writer.execute(image); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main() { ImageFileReader reader = new ImageFileReader(); // Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainForm()); }
public Image wczytajObraz(string sciezka) { ImageFileReader r = new ImageFileReader(); r.SetFileName(sciezka); r.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); var image = r.Execute(); nazwaObrazu = Path.GetFileName(r.GetFileName()); obraz = image; return obraz; }
private async void LoadImg_Click(object sender, RoutedEventArgs e) { webcam.Enable = false; var img = await ImageFileReader.SelectImage(); if (img != null) { ProcessImage(img); } }
public Image wczytajObraz(string sciezka) { ImageFileReader r = new ImageFileReader(); r.SetFileName(sciezka); r.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); var image = r.Execute(); nazwaObrazu = Path.GetFileName(r.GetFileName()); obraz = image; return(obraz); }
public MainWindow() { InitializeComponent(); string[] args = new string[3]; string s = System.AppDomain.CurrentDomain.BaseDirectory; args[0] = s + "Obrazy\\abc.png"; args[1] = "1"; args[2] = s + "Obrazy\\cba.png"; try { if (args.Length < 3) { //Console.WriteLine("Usage: SimpleGausian <imput> <sigma> <output>"); lTest.Content = "Usage: SimpleGausian <imput> <sigma> <output>"; return; } //Read imput image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); itk.simple.Image image = reader.Execute(); //Remember format //itk.simple.Image image2 = new itk.simple.Image(image); //PixelIDValueEnum id = PixelIDValueEnum.sitkVectorUInt8; //PixelIDValueEnum id = image2.GetPixelID(); //Execute Gausian smoothing filter //SmoothingRecursiveGaussianImageFilter gausian = new SmoothingRecursiveGaussianImageFilter(); //gausian.SetSigma(Double.Parse(args[1])); //image = gausian.Execute(image); //Convert? //PixelIDValueEnum id = image.GetPixelID(); //SimpleITK.Cast(image, id); //id = image.GetPixelID(); //Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(image); lTest.Content = "Chyba się udało, sprwadź :P"; } catch (Exception ex) { //Console.WriteLine(ex); lTest.Content = ex; } }
public void SetInput(string filePath) { string fileName = string.Format("{0}", filePath); sitk.Image inputImage = ImageFileReader.ReadImage(fileName); sitk.Image outputImage = BinaryThinningImageFilter.BinaryThinning(inputImage); string newFileName = string.Format("temporary\\{0}.jpg", Guid.NewGuid().ToString()); ImageFileWriter.WriteImage(outputImage, newFileName); originalBitmap = new Bitmap(Image.FromFile(newFileName)); }
static void example1(string inputImageFileName, string outputImageFileName) { ImageFileReader reader = new ImageFileReader(); reader.SetImageIO("PNGImageIO"); reader.SetFileName(inputImageFileName); Image image = reader.Execute(); ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(outputImageFileName); writer.Execute(image); }
/// <summary> /// Reads the image asynchronous. /// </summary> /// <param name="path">The location of the image on the file system.</param> /// <param name="ct">The cancellation token.</param> /// <returns> /// The ITK image. /// </returns> /// <exception cref="ArgumentNullException"> /// path /// or /// ct /// </exception> public async Task <Image> ReadImageAsync(string path, CancellationToken ct) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } if (ct == null) { throw new ArgumentNullException(nameof(ct)); } return(await Task.Run( () => { // TODO: // - check if path is a directory // - check if path contains multiple files // - determine file format // read DICOM image series // https://simpleitk.readthedocs.io/en/master/Examples/DicomSeriesReader/Documentation.html using (ImageFileReader reader = new ImageFileReader()) { try { ct.Register(() => { reader.Abort(); }); ct.ThrowIfCancellationRequested(); reader.SetFileName(path); Image image = reader.Execute(); image = ApplyRescaleIntensityImageFilter(image); image = ApplyCastImageFilter(image); return image; } catch (OperationCanceledException e) { throw new AmiException("The reading of the ITK image has been cancelled.", e); } catch (Exception e) { throw new AmiException("The ITK image could not be read.", e); } } }, ct)); }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: %s <fixedImageFilter> <movingImageFile> <outputTransformFile>\n", "ImageRegistrationMethod2"); return; } ImageFileReader reader = new ImageFileReader(); reader.SetOutputPixelType(PixelIDValueEnum.sitkFloat32); reader.SetFileName(args[0]); Image fixedImage = reader.Execute(); fixedImage = SimpleITK.Normalize(fixedImage); SimpleITK.DiscreteGaussian(fixedImage, 2.0); reader.SetFileName(args[1]); Image movingImage = reader.Execute(); movingImage = SimpleITK.Normalize(movingImage); movingImage = SimpleITK.DiscreteGaussian(movingImage, 2.0); ImageRegistrationMethod R = new ImageRegistrationMethod(); R.SetMetricAsJointHistogramMutualInformation(); double learningRate = 1; uint numberOfIterations = 200; double convergenceMinimumValue = 1e-4; uint convergenceWindowSize = 5; R.SetOptimizerAsGradientDescentLineSearch(learningRate, numberOfIterations, convergenceMinimumValue, convergenceWindowSize); R.SetInitialTransform(new TranslationTransform(fixedImage.GetDimension())); R.SetInterpolator(InterpolatorEnum.sitkLinear); IterationUpdate cmd = new IterationUpdate(R); R.AddCommand(EventEnum.sitkIterationEvent, cmd); Transform outTx = R.Execute(fixedImage, movingImage); outTx.WriteTransform(args[2]); }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: %s <fixedImageFilter> <movingImageFile> <outputTransformFile>\n", "ImageRegistrationMethod1"); return; } ImageFileReader reader = new ImageFileReader(); reader.SetOutputPixelType(PixelIDValueEnum.sitkFloat32); reader.SetFileName(args[0]); Image fixedImage = reader.Execute(); reader.SetFileName(args[1]); Image movingImage = reader.Execute(); ImageRegistrationMethod R = new ImageRegistrationMethod(); R.SetMetricAsMeanSquares(); double maxStep = 4.0; double minStep = 0.01; uint numberOfIterations = 200; double relaxationFactor = 0.5; R.SetOptimizerAsRegularStepGradientDescent(maxStep, minStep, numberOfIterations, relaxationFactor); R.SetInitialTransform(new TranslationTransform(fixedImage.GetDimension())); R.SetInterpolator(InterpolatorEnum.sitkLinear); IterationUpdate cmd = new IterationUpdate(R); R.AddCommand(EventEnum.sitkIterationEvent, cmd); Transform outTx = R.Execute(fixedImage, movingImage); // System.out.println("-------"); // System.out.println(outTx.toString()); // System.out.format("Optimizer stop condition: %s\n", R.getOptimizerStopConditionDescription()); // System.out.format(" Iteration: %d\n", R.getOptimizerIteration()); // System.out.format(" Metric value: %f\n", R.getMetricValue()); outTx.WriteTransform(args[2]); }
static void Main(string[] args) { // Specify Arena2 path of local Daggerfall installation string MyArena2Path = "C:\\dosgames\\DAGGER\\ARENA2"; // Instantiate ImageFileReader ImageFileReader MyImageFileReader = new ImageFileReader(MyArena2Path); // Set desired library type MyImageFileReader.LibraryType = LibraryTypes.Texture; // Output information about each file in library foreach (DFImageFile file in MyImageFileReader) { Console.WriteLine("{0} - {1}", file.FileName, file.Description); } }
static void Main(string[] args) { if ( args.Length < 3 ) { Console.WriteLine("Usage: %s <fixedImageFilter> <movingImageFile> <outputTransformFile>\n", "ImageRegistrationMethod1"); return; } ImageFileReader reader = new ImageFileReader(); reader.SetOutputPixelType( PixelIDValueEnum.sitkFloat32 ); reader.SetFileName(args[0]); Image fixedImage = reader.Execute(); reader.SetFileName(args[1]); Image movingImage = reader.Execute(); ImageRegistrationMethod R = new ImageRegistrationMethod(); R.SetMetricAsMeanSquares(); double maxStep = 4.0; double minStep = 0.01; uint numberOfIterations = 200; double relaxationFactor = 0.5; R.SetOptimizerAsRegularStepGradientDescent( maxStep, minStep, numberOfIterations, relaxationFactor ); R.SetInitialTransform( new TranslationTransform( fixedImage.GetDimension() ) ); R.SetInterpolator( InterpolatorEnum.sitkLinear ); IterationUpdate cmd = new IterationUpdate(R); R.AddCommand(EventEnum.sitkIterationEvent, cmd); Transform outTx = R.Execute( fixedImage, movingImage ); // System.out.println("-------"); // System.out.println(outTx.toString()); // System.out.format("Optimizer stop condition: %s\n", R.getOptimizerStopConditionDescription()); // System.out.format(" Iteration: %d\n", R.getOptimizerIteration()); // System.out.format(" Metric value: %f\n", R.getMetricValue()); outTx.WriteTransform(args[2]); }
/// <summary> /// Builds compass textures. /// </summary> private void BuildCompass() { // Load compass images ImageFileReader imageReader = new ImageFileReader(arena2Path); imageReader.LibraryType = LibraryTypes.Img; DFImageFile compass = imageReader.GetImageFile("COMPASS.IMG"); DFImageFile compassBox = imageReader.GetImageFile("COMPBOX.IMG"); // Get DFBitmaps DFBitmap compassBitmap = compass.GetBitmapFormat(0, 0, 0, DFBitmap.Formats.RGBA); DFBitmap compassBoxBitmap = compassBox.GetBitmapFormat(0, 0, 0, DFBitmap.Formats.RGBA); // Create textures compassTexture = new Texture2D( GraphicsDevice, compassBitmap.Width, compassBitmap.Height, false, SurfaceFormat.Color); compassBoxTexture = new Texture2D( GraphicsDevice, compassBoxBitmap.Width, compassBoxBitmap.Height, false, SurfaceFormat.Color); // Set data compassTexture.SetData <byte>( 0, null, compassBitmap.Data, 0, compassBitmap.Width * compassBitmap.Height * 4); compassBoxTexture.SetData <byte>( 0, null, compassBoxBitmap.Data, 0, compassBoxBitmap.Width * compassBoxBitmap.Height * 4); }
/// <inheritdoc/> public ImageReaderBase CreateImageReader(string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } var fs = fileSystemStrategy.Create(path); if (fs == null) { throw new UnexpectedNullException("Filesystem could not be created based on the provided path."); } if (fs.IsDirectory(path)) { var entryPath = DiscoverEntryPath(fs.Directory.GetFiles(path)); if (string.IsNullOrWhiteSpace(entryPath)) { // By default try to read DICOM image series // https://simpleitk.readthedocs.io/en/master/Examples/DicomSeriesReader/Documentation.html ImageSeriesReader seriesReader = new ImageSeriesReader(); seriesReader.SetFileNames(ImageSeriesReader.GetGDCMSeriesFileNames(path)); return(seriesReader); } else { // Try to read the image based on the entry path ImageFileReader reader = new ImageFileReader(); reader.SetFileName(entryPath); return(reader); } } else { ImageFileReader reader = new ImageFileReader(); reader.SetFileName(path); return(reader); } }
static void Main(string[] args) { // Specify Arena2 path of local Daggerfall installation string MyArena2Path = "C:\\dosgames\\DAGGER\\ARENA2"; // Instantiate ImageFileReader ImageFileReader MyImageFileReader = new ImageFileReader(MyArena2Path); // Set desired library type MyImageFileReader.LibraryType = LibraryTypes.Texture; // Load TEXTURE.285 file MyImageFileReader.LoadFile("TEXTURE.285"); // Output some information about this file Console.WriteLine("Image file {0} has {1} records", MyImageFileReader.FileName, MyImageFileReader.RecordCount); // Get image file to work with DFImageFile imageFile = MyImageFileReader.ImageFile; // Loop through all records for (int r = 0; r < imageFile.RecordCount; r++) { // Output some information about this record int frameCount = imageFile.GetFrameCount(r); Size sz = imageFile.GetSize(r); Console.WriteLine("Record {0} has {1} frames and is {2}x{3} pixels", r, frameCount, sz.Width, sz.Height); // Get first frame of record as a managed bitmap Bitmap managedBitmap = imageFile.GetManagedBitmap(r, 0, true, false); } }
void GeneratePixels() { byte[] fileData; string path; Texture2D tex; colorData = new Color[100, 10]; path = Path.Combine(new string[] { LoadedData.gameDataPath, "Datafiles", "2", "ImageAssets", "Bullet" }); path += ".png"; if (File.Exists(path)) { fileData = File.ReadAllBytes(path); tex = new Texture2D(1, 1); tex.LoadImage(fileData); //ImageConversion.LoadImage(tex, fileData); //display.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2()); colorData = ImageFileReader.ReadImageFile(tex.GetPixels()); } for (int i = 0; i < colorData.GetLength(0); i++) { for (int j = 0; j < colorData.GetLength(1); j++) { if (colorData[i, j].a > 0) { SpawnerOutput inst = CreatePixel(); LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Image>(inst).color = colorData[i, j]; inst.script.transform.localPosition = new Vector2(scaleFactor * i, scaleFactor * j) + pixelOffset; imageData[i, j] = inst; } } } }
static void Main(string[] args) { try { if (args.Length < 4) { Console.WriteLine("Usage: SimpleElastix <fixedImage> <movingImage> <inputImage> <parameterFile> <output>"); return; } // Make transform SimpleElastix elastix; ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); elastix.SetFixedImage(reader.Execute()); reader.SetFileName(args[1]); elastix.SetMovingImage(reader.Execute()); elastix.SetParameterMap(ReadParameterFile(args[3])); elastix.Execute(); // Instantiate transformix SimpleTransformix transformix; // Read input reader.SetFileName(args[4]); transformix.SetInputImage(reader.execute()); transformix.SetTransformParameterMapList(elastix.GetTransformParameterMapList()); // Perform warp transformix.LogToConsoleOn(); transformix.Execute(); // Write result image sitk.WriteImage(transformix.GetResultImage(), args[5]); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>");