public RGBChannels ApplyConstrastEnhancement(RGBChannels image, ContrastType type, double quantil = 0.1) { if (contrastEnhancer == null) { contrastEnhancer = ContrastEnhancer.Instance(); } RGBChannels output = image; switch (type) { case ContrastType.AutoContrast: output = contrastEnhancer.AutoContrast(image); break; case ContrastType.RobustContrast: output = contrastEnhancer.RobustContrast(image, quantil); break; case ContrastType.HistogramEqualization: output = contrastEnhancer.HistogramEqualization(image); break; } return(output); }
private void ChangeContrast(int contrastChange, ContrastType contrastType) { ImageOperations.ChangeContrast(SelectedImage.Bitmap, contrastChange, contrastType); }
private void CalculateContrast(ref Mat src, ref Mat maskSrc, out double L, out double a, out double b, out double contrast, out double H, out double C, ContrastType type) { contrast = -1; L = a = b = C = H = 0; if (type == ContrastType.RMS) { Mat img = src; Mat imgLab = new Mat(new OpenCvSharp.Size(img.Width, img.Height), MatType.CV_8UC3, 0); Cv2.CvtColor(img, imgLab, ColorConversionCodes.LBGR2Lab); Mat mask = maskSrc; Scalar mean, std; Cv2.MeanStdDev(imgLab, out mean, out std, mask); L = mean.Val0 * 100 / 255; a = mean.Val1 - 128; b = mean.Val2 - 128; contrast = std.Val0 / 255; H = calc_H(ref a, ref b); C = calc_C(ref a, ref b); } else if (type == ContrastType.Weber) { } else if (type == ContrastType.Michelson) { } }
public unsafe static void ChangeContrast(WriteableBitmap image, int contrastChange, ContrastType contrastType) { int[] contrastArray = new int[256]; if (contrastType.Equals(ContrastType.Decrease)) { for (int i = 0; i < 256; i++) { contrastArray[i] = (int)(127 + (i - 127) * (255 - 2 * contrastChange) / 255 + 0.5); } } else { for (int i = 0; i < 256; i++) { contrastArray[i] = (int)(127 + (i - 127) * 255 / (255 - 2 * contrastChange) + 0.5); } } ChangePixelsValue(image, contrastArray, ColorChannel.All); }