Browse Source

Moar updates

- EntopyCrop
- Color definitions
- Pixelate


Former-commit-id: 5605d078e59f63faf9354f1d80093e6c26096bff
Former-commit-id: c0ca96e94e189a760fe3d77f69d3470efc8d385f
Former-commit-id: ae7c743d17bde56511d6b312b9fbf9163f99da9c
af/merge-core
James Jackson-South 10 years ago
parent
commit
077dc165d4
  1. 5
      README.md
  2. 628
      src/ImageProcessor/Colors/ColorDefinitions.cs
  3. 2
      src/ImageProcessor/Common/Helpers/ImageMaths.cs
  4. 4
      src/ImageProcessor/Filters/Binarization/Threshold.cs
  5. 25
      src/ImageProcessor/Filters/ImageFilterExtensions.cs
  6. 1
      src/ImageProcessor/Filters/Invert.cs
  7. 92
      src/ImageProcessor/Filters/Pixelate.cs
  8. 23
      src/ImageProcessor/Samplers/EntropyCrop.cs
  9. 3
      tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
  10. 2
      tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs
  11. 8
      tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs

5
README.md

@ -59,7 +59,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] Rectangle
- [x] Size
- [x] Point
- [ ] Sphere
- [ ] Ellipse
- Resampling algorithms. (Performance improvements?)
- [x] Box
- [x] Bicubic
@ -77,7 +77,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- Cropping
- [x] Rectangular Crop
- [ ] Elliptical Crop
- [ ] Entropy Crop
- [x] Entropy Crop
- Rotation
- [ ] Flip (90, 270, FlipType etc. Need help)
- [ ] Rotate by angle (Need help)
@ -109,6 +109,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] Invert
- [x] BackgroundColor
- [x] Brightness
- [x] Pixelate
- [x] Saturation
- [ ] Hue
- [x] Blend

628
src/ImageProcessor/Colors/ColorDefinitions.cs

@ -25,7 +25,7 @@ namespace ImageProcessor
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7FFFD4.
/// </summary>
public static readonly Color AquaMarine = new Color(127 / 255f, 1, 212 / 255f);
public static readonly Color Aquamarine = new Color(127 / 255f, 1, 212 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0FFFF.
@ -47,75 +47,669 @@ namespace ImageProcessor
/// </summary>
public static readonly Color Black = new Color(0, 0, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFEBCD.
/// </summary>
public static readonly Color BlanchedAlmond = new Color(1, 235 / 255f, 205 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #0000FF.
/// </summary>
public static readonly Color Blue = new Color(0, 0, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C0C0C0.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8A2BE2.
/// </summary>
public static readonly Color Silver = new Color(192 / 255f, 192 / 255f, 192 / 255f);
public static readonly Color BlueViolet = new Color(138 / 255f, 43 / 255f, 226 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808080.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A52A2A.
/// </summary>
public static readonly Color Gray = new Color(128 / 255f, 128 / 255f, 128 / 255f);
public static readonly Color Brown = new Color(165 / 255f, 42 / 255f, 42 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFFF.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DEB887.
/// </summary>
public static readonly Color White = new Color(1, 1, 1);
public static readonly Color BurlyWood = new Color(222 / 255f, 184 / 255f, 135 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800000.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #5F9EA0.
/// </summary>
public static readonly Color Maroon = new Color(128 / 255f, 0, 0);
public static readonly Color CadetBlue = new Color(95 / 255f, 158 / 255f, 160 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF0000.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7FFF00.
/// </summary>
public static readonly Color Red = new Color(1, 0, 0);
public static readonly Color Chartreuse = new Color(127 / 255f, 1, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800080.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D2691E.
/// </summary>
public static readonly Color Purple = new Color(128 / 255f, 0, 128 / 255f);
public static readonly Color Chocolate = new Color(210 / 255f, 105 / 255f, 30 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF7F50.
/// </summary>
public static readonly Color Coral = new Color(1, 127 / 255f, 80 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6495ED.
/// </summary>
public static readonly Color CornflowerBlue = new Color(100 / 255f, 149 / 255f, 237 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF8DC.
/// </summary>
public static readonly Color Cornsilk = new Color(1, 248 / 255f, 220 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DC143C.
/// </summary>
public static readonly Color Crimson = new Color(220 / 255f, 20 / 255f, 60 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly Color Cyan = new Color(0, 1, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00008B.
/// </summary>
public static readonly Color DarkBlue = new Color(0, 0, 139 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008B8B.
/// </summary>
public static readonly Color DarkCyan = new Color(0, 139 / 255f, 139 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B8860B.
/// </summary>
public static readonly Color DarkGoldenrod = new Color(184 / 255f, 134 / 255f, 11 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary>
public static readonly Color DarkGray = new Color(169 / 255f, 169 / 255f, 169 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #006400.
/// </summary>
public static readonly Color DarkGreen = new Color(0, 100 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary>
public static readonly Color DarkKhaki = new Color(189 / 255f, 183 / 255f, 107 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B008B.
/// </summary>
public static readonly Color DarkMagenta = new Color(139 / 255f, 0, 139 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #556B2F.
/// </summary>
public static readonly Color DarkOliveGreen = new Color(85 / 255f, 107 / 255f, 47 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF8C00.
/// </summary>
public static readonly Color DarkOrange = new Color(1, 140 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9932CC.
/// </summary>
public static readonly Color DarkOrchid = new Color(153 / 255f, 50 / 255f, 204 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B0000.
/// </summary>
public static readonly Color DarkRed = new Color(139 / 255f, 0, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E9967A.
/// </summary>
public static readonly Color DarkSalmon = new Color(233 / 255f, 150 / 255f, 122 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8FBC8B.
/// </summary>
public static readonly Color DarkSeaGreen = new Color(143 / 255f, 188 / 255f, 139 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #483D8B.
/// </summary>
public static readonly Color DarkSlateBlue = new Color(72 / 255f, 61 / 255f, 139 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary>
public static readonly Color DarkSlateGray = new Color(47 / 255f, 79 / 255f, 79 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary>
public static readonly Color DarkTurquoise = new Color(0, 206 / 255f, 209 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9400D3.
/// </summary>
public static readonly Color DarkViolet = new Color(148 / 255f, 0, 211 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF1493.
/// </summary>
public static readonly Color DeepPink = new Color(1, 20 / 255f, 147 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00BFFF.
/// </summary>
public static readonly Color DeepSkyBlue = new Color(0, 191 / 255f, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #696969.
/// </summary>
public static readonly Color DimGray = new Color(105 / 255f, 105 / 255f, 105 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary>
public static readonly Color DodgerBlue = new Color(30 / 255f, 144 / 255f, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B22222.
/// </summary>
public static readonly Color Firebrick = new Color(178 / 255f, 34 / 255f, 34 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFAF0.
/// </summary>
public static readonly Color FloralWhite = new Color(1, 250 / 255f, 240 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #228B22.
/// </summary>
public static readonly Color ForestGreen = new Color(34 / 255f, 139 / 255f, 34 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly Color Fuchsia = new Color(1, 0, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DCDCDC.
/// </summary>
public static readonly Color Gainsboro = new Color(220 / 255f, 220 / 255f, 220 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F8F8FF.
/// </summary>
public static readonly Color GhostWhite = new Color(248 / 255f, 248 / 255f, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFD700.
/// </summary>
public static readonly Color Gold = new Color(1, 215 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DAA520.
/// </summary>
public static readonly Color Goldenrod = new Color(218 / 255f, 165 / 255f, 32 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808080.
/// </summary>
public static readonly Color Gray = new Color(128 / 255f, 128 / 255f, 128 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008000.
/// </summary>
public static readonly Color Green = new Color(0, 128 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #ADFF2F.
/// </summary>
public static readonly Color GreenYellow = new Color(173 / 255f, 1, 47 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary>
public static readonly Color Honeydew = new Color(240 / 255f, 1, 240 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF69B4.
/// </summary>
public static readonly Color HotPink = new Color(1, 105 / 255f, 180 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #CD5C5C.
/// </summary>
public static readonly Color IndianRed = new Color(205 / 255f, 92 / 255f, 92 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4B0082.
/// </summary>
public static readonly Color Indigo = new Color(75 / 255f, 0, 130 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFF0.
/// </summary>
public static readonly Color Ivory = new Color(1, 1, 240 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0E68C.
/// </summary>
public static readonly Color Khaki = new Color(240 / 255f, 230 / 255f, 140 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E6E6FA.
/// </summary>
public static readonly Color Lavender = new Color(230 / 255f, 230 / 255f, 250 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF0F5.
/// </summary>
public static readonly Color LavenderBlush = new Color(1, 240 / 255f, 245 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7CFC00.
/// </summary>
public static readonly Color LawnGreen = new Color(124 / 255f, 252 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFACD.
/// </summary>
public static readonly Color LemonChiffon = new Color(1, 250 / 255f, 205 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #ADD8E6.
/// </summary>
public static readonly Color LightBlue = new Color(173 / 255f, 216 / 255f, 230 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F08080.
/// </summary>
public static readonly Color LightCoral = new Color(240 / 255f, 128 / 255f, 128 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E0FFFF.
/// </summary>
public static readonly Color LightCyan = new Color(224 / 255f, 1, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAFAD2.
/// </summary>
public static readonly Color LightGoldenrodYellow = new Color(250 / 255f, 250 / 255f, 210 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #90EE90.
/// </summary>
public static readonly Color LightGreen = new Color(144 / 255f, 238 / 255f, 144 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary>
public static readonly Color LightGray = new Color(211 / 255f, 211 / 255f, 211 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary>
public static readonly Color LightPink = new Color(1, 182 / 255f, 193 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFA07A.
/// </summary>
public static readonly Color LightSalmon = new Color(1, 160 / 255f, 122 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #20B2AA.
/// </summary>
public static readonly Color LightSeaGreen = new Color(32 / 255f, 178 / 255f, 170 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #87CEFA.
/// </summary>
public static readonly Color LightSkyBlue = new Color(135 / 255f, 206 / 255f, 250 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #778899.
/// </summary>
public static readonly Color LightSlateGray = new Color(119 / 255f, 136 / 255f, 153 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary>
public static readonly Color LightSteelBlue = new Color(176 / 255f, 196 / 255f, 222 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFE0.
/// </summary>
public static readonly Color LightYellow = new Color(1, 1, 224 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FF00.
/// </summary>
public static readonly Color Lime = new Color(0, 1, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808000.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #32CD32.
/// </summary>
public static readonly Color Olive = new Color(128 / 255f, 128 / 255f, 0);
public static readonly Color LimeGreen = new Color(50 / 255f, 205 / 255f, 50 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFF00.
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAF0E6.
/// </summary>
public static readonly Color Yellow = new Color(1, 1, 0);
public static readonly Color Linen = new Color(250 / 255f, 240 / 255f, 230 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly Color Magenta = new Color(1, 0, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800000.
/// </summary>
public static readonly Color Maroon = new Color(128 / 255f, 0, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #66CDAA.
/// </summary>
public static readonly Color MediumAquamarine = new Color(102 / 255f, 205 / 255f, 170 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #0000CD.
/// </summary>
public static readonly Color MediumBlue = new Color(0, 0, 205 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BA55D3.
/// </summary>
public static readonly Color MediumOrchid = new Color(186 / 255f, 85 / 255f, 211 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9370DB.
/// </summary>
public static readonly Color MediumPurple = new Color(147 / 255f, 112 / 255f, 219 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #3CB371.
/// </summary>
public static readonly Color MediumSeaGreen = new Color(60 / 255f, 179 / 255f, 113 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7B68EE.
/// </summary>
public static readonly Color MediumSlateBlue = new Color(123 / 255f, 104 / 255f, 238 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FA9A.
/// </summary>
public static readonly Color MediumSpringGreen = new Color(0, 250 / 255f, 154 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #48D1CC.
/// </summary>
public static readonly Color MediumTurquoise = new Color(72 / 255f, 209 / 255f, 204 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C71585.
/// </summary>
public static readonly Color MediumVioletRed = new Color(199 / 255f, 21 / 255f, 133 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #191970.
/// </summary>
public static readonly Color MidnightBlue = new Color(25 / 255f, 25 / 255f, 112 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5FFFA.
/// </summary>
public static readonly Color MintCream = new Color(245 / 255f, 1, 250 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4E1.
/// </summary>
public static readonly Color MistyRose = new Color(1, 228 / 255f, 225 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4B5.
/// </summary>
public static readonly Color Moccasin = new Color(1, 228 / 255f, 181 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFDEAD.
/// </summary>
public static readonly Color NavajoWhite = new Color(1, 222 / 255f, 173 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #000080.
/// </summary>
public static readonly Color Navy = new Color(0, 0, 128 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FDF5E6.
/// </summary>
public static readonly Color OldLace = new Color(253 / 255f, 245 / 255f, 230 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808000.
/// </summary>
public static readonly Color Olive = new Color(128 / 255f, 128 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6B8E23.
/// </summary>
public static readonly Color OliveDrab = new Color(107 / 255f, 142 / 255f, 35 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFA500.
/// </summary>
public static readonly Color Orange = new Color(1, 165 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF4500.
/// </summary>
public static readonly Color OrangeRed = new Color(1, 69 / 255f, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DA70D6.
/// </summary>
public static readonly Color Orchid = new Color(218 / 255f, 112 / 255f, 214 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #EEE8AA.
/// </summary>
public static readonly Color PaleGoldenrod = new Color(238 / 255f, 232 / 255f, 170 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #98FB98.
/// </summary>
public static readonly Color PaleGreen = new Color(152 / 255f, 251 / 255f, 152 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #AFEEEE.
/// </summary>
public static readonly Color PaleTurquoise = new Color(175 / 255f, 238 / 255f, 238 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DB7093.
/// </summary>
public static readonly Color PaleVioletRed = new Color(219 / 255f, 112 / 255f, 147 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFEFD5.
/// </summary>
public static readonly Color PapayaWhip = new Color(1, 239 / 255f, 213 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFDAB9.
/// </summary>
public static readonly Color PeachPuff = new Color(1, 218 / 255f, 185 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #CD853F.
/// </summary>
public static readonly Color Peru = new Color(205 / 255f, 133 / 255f, 63 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFC0CB.
/// </summary>
public static readonly Color Pink = new Color(1, 192 / 255f, 203 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DDA0DD.
/// </summary>
public static readonly Color Plum = new Color(221 / 255f, 160 / 255f, 221 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B0E0E6.
/// </summary>
public static readonly Color PowderBlue = new Color(176 / 255f, 224 / 255f, 230 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800080.
/// </summary>
public static readonly Color Purple = new Color(128 / 255f, 0, 128 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #663399.
/// </summary>
public static readonly Color RebeccaPurple = new Color(102 / 255f, 51 / 255f, 153 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF0000.
/// </summary>
public static readonly Color Red = new Color(1, 0, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BC8F8F.
/// </summary>
public static readonly Color RosyBrown = new Color(188 / 255f, 143 / 255f, 143 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4169E1.
/// </summary>
public static readonly Color RoyalBlue = new Color(65 / 255f, 105 / 255f, 225 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B4513.
/// </summary>
public static readonly Color SaddleBrown = new Color(139 / 255f, 69 / 255f, 19 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FA8072.
/// </summary>
public static readonly Color Salmon = new Color(250 / 255f, 128 / 255f, 114 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F4A460.
/// </summary>
public static readonly Color SandyBrown = new Color(244 / 255f, 164 / 255f, 96 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #2E8B57.
/// </summary>
public static readonly Color SeaGreen = new Color(46 / 255f, 139 / 255f, 87 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF5EE.
/// </summary>
public static readonly Color SeaShell = new Color(1, 245 / 255f, 238 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A0522D.
/// </summary>
public static readonly Color Sienna = new Color(160 / 255f, 82 / 255f, 45 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C0C0C0.
/// </summary>
public static readonly Color Silver = new Color(192 / 255f, 192 / 255f, 192 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #87CEEB.
/// </summary>
public static readonly Color SkyBlue = new Color(135 / 255f, 206 / 255f, 235 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6A5ACD.
/// </summary>
public static readonly Color SlateBlue = new Color(106 / 255f, 90 / 255f, 205 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #708090.
/// </summary>
public static readonly Color SlateGray = new Color(112 / 255f, 128 / 255f, 144 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary>
public static readonly Color Snow = new Color(1, 250 / 255f, 250 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FF7F.
/// </summary>
public static readonly Color SpringGreen = new Color(0, 1, 127 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4682B4.
/// </summary>
public static readonly Color SteelBlue = new Color(70 / 255f, 130 / 255f, 180 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D2B48C.
/// </summary>
public static readonly Color Tan = new Color(210 / 255f, 180 / 255f, 140 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008080.
/// </summary>
public static readonly Color Teal = new Color(0, 128 / 255f, 128 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D8BFD8.
/// </summary>
public static readonly Color Thistle = new Color(216 / 255f, 191 / 255f, 216 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF6347.
/// </summary>
public static readonly Color Tomato = new Color(1, 99 / 255f, 71 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #40E0D0.
/// </summary>
public static readonly Color Turquoise = new Color(64 / 255f, 224 / 255f, 208 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #EE82EE.
/// </summary>
public static readonly Color Violet = new Color(238 / 255f, 130 / 255f, 238 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5DEB3.
/// </summary>
public static readonly Color Wheat = new Color(245 / 255f, 222 / 255f, 179 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly Color White = new Color(1, 1, 1);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5F5F5.
/// </summary>
public static readonly Color WhiteSmoke = new Color(245 / 255f, 245 / 255f, 245 / 255f);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFF00.
/// </summary>
public static readonly Color Yellow = new Color(1, 1, 0);
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary>
public static readonly Color YellowGreen = new Color(154 / 255f, 205 / 255f, 50 / 255f);
}
}

2
src/ImageProcessor/Common/Helpers/ImageMaths.cs

@ -240,6 +240,8 @@ namespace ImageProcessor
{
if (delegateFunc(imageBase, x, y, componentValue))
{
var c = imageBase[x, y];
return y;
}
}

4
src/ImageProcessor/Filters/Binarization/Threshold.cs

@ -10,8 +10,8 @@ namespace ImageProcessor.Filters
/// <summary>
/// An <see cref="IImageProcessor"/> to perform binary threshold filtering against an
/// <see cref="Image"/>. The mage will be converted to greyscale before thresholding
/// occurrs.
/// <see cref="Image"/>. The image will be converted to greyscale before thresholding
/// occurs.
/// </summary>
public class Threshold : ParallelImageProcessor
{

25
src/ImageProcessor/Filters/ImageFilterExtensions.cs

@ -301,6 +301,31 @@ namespace ImageProcessor.Filters
return source.Process(rectangle, new Polaroid());
}
/// <summary>
/// Pixelates and image with the given pixel size.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Pixelate(this Image source, int size = 4)
{
return source.Process(source.Bounds, new Pixelate(size));
}
/// <summary>
/// Pixelates and image with the given pixel size.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Pixelate(this Image source, int size, Rectangle rectangle)
{
return source.Process(rectangle, new Pixelate(size));
}
/// <summary>
/// Alters the saturation component of the image.
/// </summary>

1
src/ImageProcessor/Filters/Invert.cs

@ -29,7 +29,6 @@ namespace ImageProcessor.Filters
{
for (int x = startX; x < endX; x++)
{
// TODO: This doesn't work for gamma test images.
Color color = source[x, y];
color.R = 1 - color.R;
color.G = 1 - color.G;

92
src/ImageProcessor/Filters/Pixelate.cs

@ -0,0 +1,92 @@
// <copyright file="Invert.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessor.Filters
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// </summary>
public class Pixelate : ParallelImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="Pixelate"/> class.
/// </summary>
/// <param name="size">The size of the pixels. Must be greater than 0.</param>
/// <exception cref="ArgumentException">
/// <paramref name="size"/> is less than 0 or equal to 0.
/// </exception>
public Pixelate(int size)
{
Guard.MustBeGreaterThan(size, 0, nameof(size));
this.Value = size;
}
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets or the pixel size.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
int size = this.Value;
int offset = this.Value / 2;
// Get the range on the y-plane to choose from.
IEnumerable<int> range = EnumerableExtensions.SteppedRange(startY, i => i < endY, size);
Parallel.ForEach(
range,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x += size)
{
int offsetX = offset;
int offsetY = offset;
// Make sure that the offset is within the boundary of the
// image.
while (y + offsetY >= sourceBottom)
{
offsetY--;
}
while (x + offsetX >= endX)
{
offsetX--;
}
// Get the pixel color in the centre of the soon to be pixelated area.
// ReSharper disable AccessToDisposedClosure
Color pixel = source[x + offsetX, y + offsetY];
// For each pixel in the pixelate size, set it to the centre color.
for (int l = y; l < y + size && l < sourceBottom; l++)
{
for (int k = x; k < x + size && k < endX; k++)
{
target[k, l] = pixel;
}
}
}
}
});
}
}
}

23
src/ImageProcessor/Samplers/EntropyCrop.cs

@ -16,6 +16,8 @@ namespace ImageProcessor.Samplers
/// </summary>
public class EntropyCrop : ParallelImageProcessor
{
private Rectangle cropRectangle;
/// <summary>
/// Initializes a new instance of the <see cref="EntropyCrop"/> class.
/// </summary>
@ -39,37 +41,36 @@ namespace ImageProcessor.Samplers
{
ImageBase temp = new Image(source.Width, source.Height);
// TODO: Should we detect edges on a grayscale image?
new Sobel() { Greyscale = true }.Apply(temp, source, sourceRectangle);
// Detect the edges.
new Sobel().Apply(temp, source, sourceRectangle);
// Apply threshold binarization filter.
new Threshold(.5f).Apply(temp, temp, sourceRectangle);
// Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);
target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
// Reset the target pixel to the correct size.
target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
this.cropRectangle = rectangle;
}
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int targetY = targetRectangle.Y;
int targetBottom = targetRectangle.Height;
int targetY = this.cropRectangle.Y;
int startX = targetRectangle.X;
int endX = targetRectangle.Width;
int targetX = this.cropRectangle.X;
int endX = this.cropRectangle.Width;
Parallel.For(
startY,
endY,
y =>
{
if (y >= targetY && y < targetBottom)
for (int x = startX; x < endX; x++)
{
for (int x = startX; x < endX; x++)
{
target[x, y] = source[x, y];
}
target[x, y] = source[x + targetX, y + targetY];
}
});
}

3
tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs

@ -38,7 +38,8 @@ namespace ImageProcessor.Tests
//{ "Prewitt", new Prewitt() },
//{ "RobertsCross", new RobertsCross() },
//{ "Scharr", new Scharr() },
{ "Sobel", new Sobel {Greyscale = true} },
//{ "Sobel", new Sobel {Greyscale = true} },
{ "Pixelate", new Pixelate(8) },
//{ "GuassianBlur", new GuassianBlur(10) },
//{ "GuassianSharpen", new GuassianSharpen(10) }
};

2
tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs

@ -20,7 +20,7 @@ namespace ImageProcessor.Tests
public static readonly List<string> Files = new List<string>
{
//"TestImages/Formats/Jpg/Backdrop.jpg",
//"TestImages/Formats/Jpg/Calliphora.jpg",
"TestImages/Formats/Jpg/Calliphora.jpg",
//"TestImages/Formats/Jpg/china.jpg",
//"TestImages/Formats/Jpg/ant.jpg",
//"TestImages/Formats/Jpg/parachute.jpg",

8
tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs

@ -59,9 +59,9 @@ namespace ImageProcessor.Tests
[Fact]
public void ImageShouldEntropyCrop()
{
if (!Directory.Exists("TestOutput/EntropyCropped"))
if (!Directory.Exists("TestOutput/EntropyCrop"))
{
Directory.CreateDirectory("TestOutput/EntropyCropped");
Directory.CreateDirectory("TestOutput/EntropyCrop");
}
foreach (string file in Files)
@ -69,8 +69,8 @@ namespace ImageProcessor.Tests
using (FileStream stream = File.OpenRead(file))
{
Image image = new Image(stream);
string filename = Path.GetFileNameWithoutExtension(file) + "-EntropyCropped" + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/EntropyCropped/{filename}"))
string filename = Path.GetFileNameWithoutExtension(file) + "-EntropyCrop" + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/EntropyCrop/{filename}"))
{
image.EntropyCrop().Save(output);
}

Loading…
Cancel
Save