예제 #1
0
		private void saveFile(List<CommandLineArgModel> args, filterIteration[] filters, RawImage image)
		{
			var output = args.First(arg => arg.Argument == CommandsLineArg.Output).Parameters.First();
			var extention = (Path.GetExtension(output) ?? "").ToLower();

			var isGrayscale = filters.Length > 0 && filters.Last().FilterParams.Argument == CommandsLineArg.Grayscale;
			var isBlackAndWhite = filters.Length > 0 && filters.Last().FilterParams.Argument == CommandsLineArg.ThresholdFilter;

			switch (extention)
			{
				case ".pbm":
					if (!isBlackAndWhite)
						image = ThresholdFilter.Process(new ThresholdFilterModel
						{
							DefaultRoi = new RoiModel(image),
							Threshold = 0.5
						},
						image);

					break;
				case ".pgm":
					if (!isGrayscale && !isBlackAndWhite)
						image = Grayscale.Process(new GrayscaleModel
						{
							DefaultRoi = new RoiModel(image)
						},
						image);
					break;
			}

			if (File.Exists(output)) File.Delete(output);

			image.Save(output);
		}
예제 #2
0
		public static bool TryParse(string path, out RawImage image)
		{
			try
			{
				if (TryParse8BitPbm(path, out image) ||
					TryParse16BitPbm(path, out image) ||
					TryParse32BitPbm(path, out image))
					return true;

				using (var bmp = (Bitmap)Image.FromFile(path))
					image = new RawImage(bmp);

				return true;
			}
			catch
			{
				image = null;
				return false;
			}
		}
예제 #3
0
		public static bool TryParse32BitPbm(string path, out RawImage image)
		{
			try
			{
				var reader = new NetpbmReader();

				using (var stream = File.OpenRead(path))
				{
					var pbmImage = reader.ReadImage(stream, Image8Factory);

					image = pbmImage.ToRawImage();
				}

				return true;
			}
			catch
			{
				image = null;
				return false;
			}
		}
예제 #4
0
		public RoiModel(RawImage image)
		{
			Region = new Rectangle(Point.Empty, image.Size);
		}
예제 #5
0
		public void Process(List<CommandLineArgModel> args)
		{
			var inputFile = args.First(arg => arg.Argument == CommandsLineArg.Input).Parameters.First();
			var inputImage = new RawImage(inputFile);
			
			var filters = getFilterPipe(args).ToArray();

			var currentImage = inputImage;
			foreach (var arg in filters)
			{
				var roi = new RoiModel(currentImage);
				if (arg.FilterParams.ParsedModel is IRoiModel)
				{
					(arg.FilterParams.ParsedModel as IRoiModel).DefaultRoi = roi;
					roi = (arg.FilterParams.ParsedModel as IRoiModel).Roi ?? roi;
				}

				Log.Info("Processing: -{0} {1}", arg.FilterParams.Argument, String.Join(" ", arg.FilterParams.Parameters.Select(param => String.Format("\"{0}\"", param))));
				if (arg.FilterParams.ParsedModel is IRoiModel) Log.Info("Roi: " + roi.Region);

				var nextImage = arg.Filter.ProcessInput(arg.FilterParams, currentImage);

				currentImage = nextImage;
			}

			saveFile(args, filters, currentImage);
		}