ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | List of all members
ImageResizer.Plugins.RedEye.ManualSearcher Class Reference

Looks for the 'best' pixel within a given radius from a specified point, where 'best' is the brightest pixel after applying a red-eye filter. Uses weighted evaluation. More...

Public Member Functions

unsafe Point FindMaxPixel (UnmanagedImage img, PointF mouse, float maxDistanceFromMouse)
 Looks for the brightest pixel after applying a redness filter. Narrows search first using a resampled copy of the image to eliminate edge dots. Expects an image that is already cropped to the interested area for faster processing. More...
 

Detailed Description

Looks for the 'best' pixel within a given radius from a specified point, where 'best' is the brightest pixel after applying a red-eye filter. Uses weighted evaluation.

Definition at line 13 of file ManualSearcher.cs.

Member Function Documentation

unsafe Point ImageResizer.Plugins.RedEye.ManualSearcher.FindMaxPixel ( UnmanagedImage  img,
PointF  mouse,
float  maxDistanceFromMouse 
)
inline

Looks for the brightest pixel after applying a redness filter. Narrows search first using a resampled copy of the image to eliminate edge dots. Expects an image that is already cropped to the interested area for faster processing.

Parameters
img
mouse
maxDistanceFromMouse
Returns

Definition at line 23 of file ManualSearcher.cs.

23  {
24  int width = 15;
25  int height = (int)Math.Ceiling((double)img.Height / (double)img.Width * width);
26 
27  if (width <= img.Width && height <= img.Height + 1) {
28  width = img.Width;
29  height = img.Height;
30  }
31 
32  double scale = (double)img.Width / (double)width;
33 
34  UnmanagedImage lowRed = null;
35  try {
36  if (width != img.Width && height != img.Height) {
37  using (Bitmap reduced = new Bitmap(width, height, PixelFormat.Format24bppRgb))
38  using (Graphics g = Graphics.FromImage(reduced))
39  using (ImageAttributes ia = new ImageAttributes()) {
40  g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
41  g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
42  g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
43  g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
44  g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
45  ia.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
46  g.DrawImage(img.ToManagedImage(false), new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
47  //TODO: Not sure if ToManagedImage will stick around after the underying image is disposed. I know that the bitmap data will be gone, guess that's most of it.
48  using (UnmanagedImage rui = UnmanagedImage.FromManagedImage(reduced)) {
49  lowRed = new RedEyeFilter(2).Apply(rui); // Make an copy using the red eye filter
50  }
51  }
52  } else {
53  //Don't resample unless needed
54  lowRed = new RedEyeFilter(2).Apply(img);
55  }
56 
57 
58  Point max = GetMax(lowRed, new PointF(mouse.X / (float)scale, mouse.Y / (float)scale), maxDistanceFromMouse / scale);
59 
60  //We weren't scaling things? OK, cool...
61  if (scale == 0) return max;
62 
63  //Otherwise, let's get the unscaled pixel.
64  //Calculate the rectangle surrounding the selected pixel, but in source coordinates.
65  int tinySize = (int)Math.Ceiling(scale) + 1;
66  Rectangle tinyArea = new Rectangle((int)Math.Floor(scale * (double)max.X), (int)Math.Floor(scale * (double)max.Y), tinySize, tinySize);
67  if (tinyArea.Right >= img.Width) tinyArea.Width -= img.Width - tinyArea.Right + 1;
68  if (tinyArea.Bottom >= img.Height) tinyArea.Height -= img.Height - tinyArea.Bottom + 1;
69  //Filter it and look
70  using (UnmanagedImage tiny = new Crop(tinyArea).Apply(img)) {
71  using (UnmanagedImage tinyRed = new RedEyeFilter(2).Apply(tiny)) {
72  max = GetMax(tinyRed);
73  max.X += tinyArea.X;
74  max.Y += tinyArea.Y;
75  }
76  }
77  return max;
78  } finally {
79  if (lowRed != null) lowRed.Dispose();
80  }
81 
82  }
Width and height are considered exact values - cropping is used if there is an aspect ratio differenc...
Turns color images into grayscale images using a specialized filter that makes the red eyes stand out...
Definition: RedEyeFilter.cs:15

The documentation for this class was generated from the following file: