static public GrayscaleFloatImage Canny(ColorFloatImage image, float sigma, float thigh, float tlow) { thigh *= 255; tlow *= 255; GrayscaleFloatImage EdgeMap = new GrayscaleFloatImage(image.Width, image.Height); image = ImageProcessing.Gauss(image, sigma); GrayscaleFloatImage GradientMap = ToGrayscaleImage(image); GrayscaleFloatImage Dir = ToGrayscaleImage(image); GradientSobel(ref GradientMap); Susperss_NonMaxima(ref GradientMap, Dir); EdgeDetect(GradientMap, thigh, tlow, EdgeMap); // Result = Mag; return(EdgeMap); }
public static void downsample(ref ColorFloatImage image, float s, string paramoff = "") { ColorFloatImage tempImg = new ColorFloatImage((int)(image.Width / s), image.Height); if (paramoff != "-off") { image = ImageProcessing.Gauss(image, (float)Math.Sqrt(Math.Abs(s * s - 1))); } float n = (image.Width * s - s) / ((float)image.Width - s); for (int y = 0; y < image.Height; ++y) { tempImg[0, y] = image[0, y]; tempImg[tempImg.Width - 1, y] = image[image.Width - 1, y]; for (int x = 1; x < tempImg.Width - 1; ++x) { ColorFloatPixel p = new ColorFloatPixel(); float x1 = (float)Math.Truncate(x * n), x2 = (int)(x * n) + 1; p.r = (x2 - (float)x * n) * image[(int)x1, y].r + ((float)x * n - x1) * image[(int)x2, y].r; p.g = (x2 - (float)x * n) * image[(int)x1, y].g + ((float)x * n - x1) * image[(int)x2, y].g; p.b = (x2 - (float)x * n) * image[(int)x1, y].b + ((float)x * n - x1) * image[(int)x2, y].b; tempImg[x, y] = p; } } image = tempImg; tempImg = new ColorFloatImage(image.Width, (int)(image.Height / s)); n = (image.Height * s - s) / ((float)image.Height - s); for (int x = 0; x < image.Width; ++x) { tempImg[x, 0] = image[x, 0]; tempImg[x, tempImg.Height - 1] = image[x, image.Height - 1]; for (int y = 1; y < tempImg.Height - 1; ++y) { ColorFloatPixel p = new ColorFloatPixel(); float y1 = (float)Math.Truncate(y * n) > image.Height - 1 ? image.Height - 1 : (float)Math.Truncate(y * n), y2 = (int)(y * n) + 1 > image.Height - 1 ? image.Height - 1 : (int)(y * n) + 1; p.r = (y2 - (float)y * n) * image[x, (int)y1].r + ((float)y * n - y1) * image[x, (int)y2].r; p.g = (y2 - (float)y * n) * image[x, (int)y1].g + ((float)y * n - y1) * image[x, (int)y2].g; p.b = (y2 - (float)y * n) * image[x, (int)y1].b + ((float)y * n - y1) * image[x, (int)y2].b; tempImg[x, y] = p; } } image = tempImg; }
static void Main(string[] args) { if (args.Length < 3) { return; } string InputFileName = args[args.Length - 2], OutputFileName = args[args.Length - 1]; if (!File.Exists(InputFileName)) { return; } switch (args[0]) { case ("prewitt"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length >= 4) { if (args[1] == "y") { ImageProcessing.Prewitt(image, "y"); } if (args[1] == "x") { ImageProcessing.Prewitt(image, "x"); } } else { ImageProcessing.Prewitt(image); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("invert"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.InvertImage(image); ImageIO.ImageToFile(image, OutputFileName); break; } case ("sobel"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length >= 4) { if (args[1] == "y") { ImageProcessing.Sobel(image, "y"); } if (args[1] == "x") { ImageProcessing.Sobel(image, "x"); } } else { ImageProcessing.Sobel(image); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("mirror"): { if (args.Length >= 4) { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args[1] == "y") { ImageProcessing.FlipImageY(image); } if (args[1] == "x") { ImageProcessing.FlipImageX(image); } ImageIO.ImageToFile(image, OutputFileName); } break; } case ("roberts"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length >= 4) { if (args[1] == "1") { ImageProcessing.Roberts(image, 1); } if (args[1] == "2") { ImageProcessing.Roberts(image, 2); } } else { ImageProcessing.Roberts(image); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("rotate"): { if (args.Length < 5) { return; } ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.Rotate(ref image, args[1], float.Parse(args[2], CultureInfo.InvariantCulture)); ImageIO.ImageToFile(image, OutputFileName); } break; case ("gauss"): { if (args.Length < 4) { return; } ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length < 5) { image = ImageProcessing.Gauss(image, float.Parse(args[1], CultureInfo.InvariantCulture)); } else { image = ImageProcessing.Gauss(image, float.Parse(args[1], CultureInfo.InvariantCulture), float.Parse(args[2], CultureInfo.InvariantCulture)); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("median"): { if (args.Length < 4) { return; } ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.Median(image, Int32.Parse(args[1])); ImageIO.ImageToFile(image, OutputFileName); break; } case ("gabor"): { GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName); image = ImageProcessing.Gabor(image, Single.Parse(args[1], CultureInfo.InvariantCulture), Single.Parse(args[2], CultureInfo.InvariantCulture), Single.Parse(args[3], CultureInfo.InvariantCulture), Single.Parse(args[4], CultureInfo.InvariantCulture), Single.Parse(args[5], CultureInfo.InvariantCulture)); ImageIO.ImageToFile(image, OutputFileName); break; } case ("gradient"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.gradient(ref image, Single.Parse(args[1], CultureInfo.InvariantCulture)); ImageIO.ImageToFile(ImageIO.BitmapToGrayscaleFloatImage(ImageIO.ImageToBitmap(image)), OutputFileName); break; } case ("vessels"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); var result = ImageProcessing.vessels(image, Single.Parse(args[3], CultureInfo.InvariantCulture)); ImageIO.ImageToFile(result, OutputFileName); break; } case ("canny"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); var result = EdgeDetection.Canny(image, Single.Parse(args[1], CultureInfo.InvariantCulture), Single.Parse(args[2], CultureInfo.InvariantCulture), Single.Parse(args[3], CultureInfo.InvariantCulture)); ImageIO.ImageToFile(result, OutputFileName); break; } case ("mse"): { ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]), image2 = ImageIO.FileToColorFloatImage(args[2]); Console.WriteLine(ImageInterpolation.MSE(image1, image2)); break; } case ("psnr"): { ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]), image2 = ImageIO.FileToColorFloatImage(args[2]); Console.WriteLine(ImageInterpolation.PSNR(image1, image2)); break; } case ("ssim"): { ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]), image2 = ImageIO.FileToColorFloatImage(args[2]); Console.WriteLine(ImageInterpolation.SSIM(image1, image2)); break; } case ("mssim"): { ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]), image2 = ImageIO.FileToColorFloatImage(args[2]); Console.WriteLine(ImageInterpolation.MSSIM(image1, image2)); break; } case ("unsharp"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); var result = ImageProcessing.unsharp(image); ImageIO.ImageToFile(result, OutputFileName); break; } default: break; } //GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName); //FlipImage(image); }
static void Main(string[] args) { if (args.Length < 3) { return; } string InputFileName = args[0], OutputFileName = args[1]; if (!File.Exists(InputFileName)) { return; } switch (args[2]) { case ("harris"): { GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName); GrayscaleFloatImage Res = EdgeDetection.harris(image, float.Parse(args[3])); ImageIO.ImageToFile(Res, OutputFileName); break; } case ("canny"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); GrayscaleFloatImage Reslut = EdgeDetection.Canny(image, float.Parse(args[3]), float.Parse(args[4]), float.Parse(args[5])); ImageIO.ImageToFile(Reslut, OutputFileName); break; } case ("nothing"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageIO.ImageToFile(image, OutputFileName); break; } case ("prewitt"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length >= 4) { if (args[3] == "y") { ImageProcessing.Prewitt(image, "y"); } if (args[3] == "x") { ImageProcessing.Prewitt(image, "x"); } } else { ImageProcessing.Prewitt(image); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("invert"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.InvertImage(image); ImageIO.ImageToFile(image, OutputFileName); break; } case ("sobel"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length >= 4) { if (args[3] == "y") { ImageProcessing.Sobel(image, "y"); } if (args[3] == "x") { ImageProcessing.Sobel(image, "x"); } } else { ImageProcessing.Sobel(image); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("mirror"): { if (args.Length >= 4) { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args[3] == "y") { ImageProcessing.FlipImageY(image); } if (args[3] == "x") { ImageProcessing.FlipImageX(image); } ImageIO.ImageToFile(image, OutputFileName); } break; } case ("roberts"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args.Length >= 4) { if (args[3] == "1") { ImageProcessing.Roberts(image, 1); } if (args[3] == "2") { ImageProcessing.Roberts(image, 2); } } else { ImageProcessing.Roberts(image); } ImageIO.ImageToFile(image, OutputFileName); break; } case ("rotate"): { if (args.Length < 5) { return; } ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); if (args[3] == "cw") { if (args[4] == "90") { ImageProcessing.RotateCw90(ref image); } if (args[4] == "180") { ImageProcessing.RotateCw90(ref image); ImageProcessing.RotateCw90(ref image); } if (args[4] == "270") { ImageProcessing.RotateCw90(ref image); ImageProcessing.RotateCw90(ref image); ImageProcessing.RotateCw90(ref image); } } else if (args[3] == "ccw") { if (args[4] == "90") { ImageProcessing.RotateCw90(ref image); ImageProcessing.RotateCw90(ref image); ImageProcessing.RotateCw90(ref image); } if (args[4] == "180") { ImageProcessing.RotateCw90(ref image); ImageProcessing.RotateCw90(ref image); } if (args[4] == "270") { ImageProcessing.RotateCw90(ref image); } } ImageIO.ImageToFile(image, OutputFileName); } break; case ("gauss"): { if (args.Length < 4) { return; } ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.Gauss(ref image, float.Parse(args[3])); ImageIO.ImageToFile(image, OutputFileName); break; } case ("median"): { if (args.Length < 4) { return; } ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.Median(image, Int32.Parse(args[3])); ImageIO.ImageToFile(image, OutputFileName); break; } case ("gabor"): { ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName); ImageProcessing.gabor(ref image, Single.Parse(args[3]), Single.Parse(args[4]), Single.Parse(args[5]), Single.Parse(args[6]), Single.Parse(args[7])); ImageIO.ImageToFile(image, OutputFileName); break; } default: break; } //GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName); //FlipImage(image); }