//@Override public override Image process(Image imageIn) { int width = imageIn.getWidth(); int halfw = width / 2; int height = imageIn.getHeight(); int halfh = height / 2; int R = Math.Min(halfw, halfh); //中心点,发亮此值会让强光中心发生偏移 Point point = new Point(halfw, halfh); int r = 0, g = 0, b = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float length = (float)Math.Sqrt(Math.Pow((x - point.X), 2) + Math.Pow((y - point.Y), 2)); r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); //位于光晕中 if (length < R) { float pixel = Light * (1.0f - length / R); r = r + (int)pixel; r = Math.Max(0, Math.Min(r, 255)); g = g + (int)pixel; g = Math.Max(0, Math.Min(g, 255)); b = b + (int)pixel; b = Math.Max(0, Math.Min(b, 255)); } imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn); }
//@Override public Image process(Image imageIn) { int r, g, b; int num = (int)(this.Intensity * 32768f); for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); if (num != 0) { int rr = getRandomInt(-255, 0xff) * num; int gg = getRandomInt(-255, 0xff) * num; int bb = getRandomInt(-255, 0xff) * num; int rrr = r + (rr >> 15); int ggg = g + (gg >> 15); int bbb = b + (bb >> 15); r = (rrr > 0xff) ? ((byte)0xff) : ((rrr < 0) ? ((byte)0) : ((byte)rrr)); g = (ggg > 0xff) ? ((byte)0xff) : ((ggg < 0) ? ((byte)0) : ((byte)ggg)); b = (bbb > 0xff) ? ((byte)0xff) : ((bbb < 0) ? ((byte)0) : ((byte)bbb)); } imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
//@Override public override Image process(Image imageIn) { int width = imageIn.getWidth(); int halfw = width / 2; int height = imageIn.getHeight(); int halfh = height / 2; int R = Math.Min(halfw, halfh); //中心点,发亮此值会让强光中心发生偏移 Point point = new Point(halfw, halfh); int r = 0, g = 0, b = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float length = (float)Math.Sqrt(Math.Pow((x - point.X), 2) + Math.Pow((y - point.Y), 2)); r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); //位于光晕中 if (length < R) { float pixel = Light * (1.0f - length / R); r = r + (int)pixel; r = Math.Max(0, Math.Min(r, 255)); g = g + (int)pixel; g = Math.Max(0, Math.Min(g, 255)); b = b + (int)pixel; b = Math.Max(0, Math.Min(b, 255)); } imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
public Image process(Image imageIn) { int tr = (255 << 24) + (Colors.Red.R << 16) + (Colors.Red.G << 8) + Colors.Red.B; int tg = (255 << 24) + (Colors.Green.R << 16) + (Colors.Green.G << 8) + Colors.Green.B; int tb = (255 << 24) + (Colors.Blue.R << 16) + (Colors.Blue.G << 8) + Colors.Blue.B; int r, g, b; for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = (255 - imageIn.getRComponent(x, y)); g = (255 - imageIn.getGComponent(x, y)); b = (255 - imageIn.getBComponent(x, y)); // Convert to gray with constant factors 0.2126, 0.7152, 0.0722 int gray = (r * 6966 + g * 23436 + b * 2366) >> 15; // Apply Tint color r = (byte)((gray * tr) >> 8); g = (byte)((gray * tg) >> 8); b = (byte)((gray * tb) >> 8); imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn); }
//@Override public Image process(Image imageIn) { int r, g, b; int num = (int)(this.Intensity * 32768f); for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); if (num != 0) { int rr = getRandomInt(-255, 0xff) * num; int gg = getRandomInt(-255, 0xff) * num; int bb = getRandomInt(-255, 0xff) * num; int rrr = r + (rr >> 15); int ggg = g + (gg >> 15); int bbb = b + (bb >> 15); r = (rrr > 0xff) ? ((byte)0xff) : ((rrr < 0) ? ((byte)0) : ((byte)rrr)); g = (ggg > 0xff) ? ((byte)0xff) : ((ggg < 0) ? ((byte)0) : ((byte)ggg)); b = (bbb > 0xff) ? ((byte)0xff) : ((bbb < 0) ? ((byte)0) : ((byte)bbb)); } imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn); }
//@Override public Image process(Image imageIn) { double width = imageIn.getWidth(); double height = imageIn.getHeight(); Image clone = imageIn.clone(); int r, g, b; for (int x = 0; x < (width - 1); x++) { for (int y = 0; y < (height - 1); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); _scale = Math.Sqrt(width * width + height * height) / 2; _offset = (int)(_scale / 2); double cx = (x - width / 2.0) / _scale; double cy = (y - height / 2.0) / _scale; double angle = Math.Floor(Math.Atan2(cy, cx) / 2.0 / _amount) * 2.0 * _amount + _amount; double radius = Math.Sqrt(cx * cx + cy * cy); int xx = (int)(x - _offset * Math.Cos(angle)); int yy = (int)(y - _offset * Math.Sin(angle)); xx = Function.FClamp(xx, 0, (int)(width - 1)); yy = Function.FClamp(yy, 0, (int)(height - 1)); r = Function.FClamp0255(r + radius * (clone.getRComponent(xx, yy) - r)); g = Function.FClamp0255(g + radius * (clone.getGComponent(xx, yy) - g)); b = Function.FClamp0255(b + radius * (clone.getBComponent(xx, yy) - b)); imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn); }
public Image process(Image imageIn) { int tr = (255 << 24) + (Colors.Red.R << 16) + (Colors.Red.G << 8) + Colors.Red.B; int tg = (255 << 24) + (Colors.Green.R << 16) + (Colors.Green.G << 8) + Colors.Green.B; int tb = (255 << 24) + (Colors.Blue.R << 16) + (Colors.Blue.G << 8) + Colors.Blue.B; int r, g, b; for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = (255 - imageIn.getRComponent(x, y)); g = (255 - imageIn.getGComponent(x, y)); b = (255 - imageIn.getBComponent(x, y)); // Convert to gray with constant factors 0.2126, 0.7152, 0.0722 int gray = (r * 6966 + g * 23436 + b * 2366) >> 15; // Apply Tint color r = (byte)((gray * tr) >> 8); g = (byte)((gray * tg) >> 8); b = (byte)((gray * tb) >> 8); imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
//@Override public Image process(Image imageIn) { double width = imageIn.getWidth(); double height = imageIn.getHeight(); Image clone = imageIn.clone(); int r, g, b; for (int x = 0; x < (width - 1); x++) { for (int y = 0; y < (height - 1); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); _scale = Math.Sqrt(width * width + height * height) / 2; _offset = (int)(_scale / 2); double cx = (x - width / 2.0) / _scale; double cy = (y - height / 2.0) / _scale; double angle = Math.Floor(Math.Atan2(cy, cx) / 2.0 / _amount) * 2.0 * _amount + _amount; double radius = Math.Sqrt(cx * cx + cy * cy); int xx = (int)(x - _offset * Math.Cos(angle)); int yy = (int)(y - _offset * Math.Sin(angle)); xx = Function.FClamp(xx, 0, (int)(width - 1)); yy = Function.FClamp(yy, 0, (int)(height - 1)); r = Function.FClamp0255(r + radius * (clone.getRComponent(xx, yy) - r)); g = Function.FClamp0255(g + radius * (clone.getGComponent(xx, yy) - g)); b = Function.FClamp0255(b + radius * (clone.getBComponent(xx, yy) - b)); imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
//@Override public Image process(Image imageIn) { int r, g, b; for(int x = 0 ; x < imageIn.getWidth() ; x++){ for(int y = 0 ; y < imageIn.getHeight() ; y++){ r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); double l = _lum_tab[GetGrayscale(r, g, b)] ; int cr = HLStoRGB (_hue, l, _saturation) ; imageIn.setPixelColor(x, y, cr); } } return imageIn; }
public Image process(Image imageIn) { int r, g, b; HslColor hsl = new HslColor(HueFactor, 0, 0); for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); HslColor.RgbToHsl(r, g, b, hsl); hsl.h = this.HueFactor; int color = HslColor.HslToRgb(hsl); imageIn.setPixelColor(x, y, color); } } return imageIn; }
public Image process(Image imageIn) { // get source image size int width = imageIn.getWidth(); int height = imageIn.getHeight(); // processing region's dimension int widthToProcess = width; int heightToProcess = height; // if generator was specified, then generate a texture // otherwise use provided texture if (textureGenerator != null) { texture = textureGenerator.Generate(width, height); } else { widthToProcess = Math.Min(width, texture.GetLength(1)); heightToProcess = Math.Min(height, texture.GetLength(0)); } int r, g, b; // texture for (int y = 0; y < heightToProcess; y++) { for (int x = 0; x < widthToProcess; x++) { double t = texture[y, x]; r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); // process each pixel r = (byte)Math.Min(255.0f, (preserveLevel * r) + (filterLevel * r) * t); g = (byte)Math.Min(255.0f, (preserveLevel * g) + (filterLevel * g) * t); b = (byte)Math.Min(255.0f, (preserveLevel * b) + (filterLevel * b) * t); imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn); }
//@Override public Image process(Image imageIn) { int r, g, b; for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); double l = _lum_tab[GetGrayscale(r, g, b)]; int cr = HLStoRGB(_hue, l, _saturation); imageIn.setPixelColor(x, y, cr); } } return(imageIn); }
public Image process(Image imageIn) { int r, g, b; HslColor hsl = new HslColor(HueFactor, 0, 0); for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); HslColor.RgbToHsl(r, g, b, hsl); hsl.h = this.HueFactor; int color = HslColor.HslToRgb(hsl); imageIn.setPixelColor(x, y, color); } } return(imageIn); }
public override Image process(Image imageIn) { if ((_pt.X + _pt.Y) <= 0) { _pt.X = imageIn.getWidth() / 2; _pt.Y = imageIn.getHeight() / 2; } for (int x = 0; x < (imageIn.getWidth() - 1); x++) { for (int y = 0; y < (imageIn.getHeight() - 1); y++) { int[] pixel = new int[3]; pixel[0] = imageIn.getRComponent(x, y); pixel[1] = imageIn.getGComponent(x, y); pixel[2] = imageIn.getBComponent(x, y); double u = (x - _pt.X + 0.001) / _radius; double v = (y - _pt.Y + 0.001) / _radius; double t = (Math.Atan2(u, v) / (2 * Function.LIB_PI) + 0.51) * _count; int i = (int)Math.Floor(t); t -= i; i %= _count; double w1 = _spoke[i] * (1 - t) + _spoke[(i + 1) % _count] * t; w1 = w1 * w1; double w = 1.0 / Math.Sqrt(u * u + v * v) * 0.9; double fRatio = Function.FClampDouble(w, 0.0, 1.0); double ws = Function.FClampDouble(w1 * w, 0.0, 1.0); for (int m = 0; m < 3; m++) { int[] _spokecolorm = new int[3]; _spokecolorm[0] = _spokecolor[i] & 0xFF0000 >> 16; _spokecolorm[1] = _spokecolor[i] & 0x00FF00 >> 8; _spokecolorm[2] = _spokecolor[i] & 0x0000FF; int[] _spokecolorcount = new int[3]; _spokecolorcount[0] = _spokecolor[(i + 1) % _count] & 0xFF0000 >> 16; _spokecolorcount[1] = _spokecolor[(i + 1) % _count] & 0x00FF00 >> 8; _spokecolorcount[2] = _spokecolor[(i + 1) % _count] & 0x0000FF; double spokecol = _spokecolorm[m] / 255.0 * (1 - t) + _spokecolorcount[m] / 255.0 * t; double r; if (w > 1.0) { r = Function.FClampDouble(spokecol * w, 0.0, 1.0); } else { r = pixel[m] / 255.0 * (1.0 - fRatio) + spokecol * fRatio; } r += ws; pixel[m] = Function.FClamp0255(r * 255); imageIn.setPixelColor(x, y, pixel[0], pixel[1], pixel[2]); } } } return(imageIn); }
//@Override public override Image process(Image imageIn) { int width = imageIn.getWidth(); int height = imageIn.getHeight(); int r = 0, g = 0, b = 0; Image clone = imageIn.clone(); clone.clearImage((255 << 24) + (Colors.LightGray.R << 16) + (Colors.LightGray.G << 8) + Colors.LightGray.B); Point[] point = new Point[BannerNum]; if (this.IsHorizontal) {//ˮƽ���� int dh = height / BannerNum; int dw = width; for (int i = 0; i < BannerNum; i++) { point[i] = new Point(0, i * dh); } for (int x = 0; x < dh; x++) { for (int y = 0; y < BannerNum; y++) { for (int k = 0; k < dw; k++) { int xx = (int)point[y].X + k; int yy = (int)point[y].Y + (int)(x / 1.1); r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } //��ͼ�����ಿ������� for (int xx = 0; xx < width; xx++) { for (int yy = (int)point[BannerNum - 1].Y + dh; yy < height; yy++) { r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } else {//��ֱ���� int dw = width / BannerNum; int dh = height; for (int i = 0; i < BannerNum; i++) { point[i] = new Point(i * dw, 0); } for (int x = 0; x < dw; x++) { for (int y = 0; y < BannerNum; y++) { for (int k = 0; k < dh; k++) { int xx = (int)point[y].X + (int)(x / 1.1); int yy = (int)point[y].Y + k; r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } //��ͼ�����ಿ������� for (int yy = 0; yy < height; yy++) { for (int xx = (int)point[BannerNum - 1].X + dw; xx < width; xx++) { r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } return clone; }
//@Override public override Image process(Image imageIn) { int width = imageIn.getWidth(); int height = imageIn.getHeight(); int r = 0, g = 0, b = 0; Image clone = imageIn.clone(); clone.clearImage((255 << 24) + (Colors.LightGray.R << 16) + (Colors.LightGray.G << 8) + Colors.LightGray.B); Point[] point = new Point[BannerNum]; if (this.IsHorizontal) {//水平方向 int dh = height / BannerNum; int dw = width; for (int i = 0; i < BannerNum; i++) { point[i] = new Point(0, i * dh); } for (int x = 0; x < dh; x++) { for (int y = 0; y < BannerNum; y++) { for (int k = 0; k < dw; k++) { int xx = (int)point[y].X + k; int yy = (int)point[y].Y + (int)(x / 1.1); r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } //对图像其余部分做填充 for (int xx = 0; xx < width; xx++) { for (int yy = (int)point[BannerNum - 1].Y + dh; yy < height; yy++) { r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } else {//垂直方向 int dw = width / BannerNum; int dh = height; for (int i = 0; i < BannerNum; i++) { point[i] = new Point(i * dw, 0); } for (int x = 0; x < dw; x++) { for (int y = 0; y < BannerNum; y++) { for (int k = 0; k < dh; k++) { int xx = (int)point[y].X + (int)(x / 1.1); int yy = (int)point[y].Y + k; r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } //对图像其余部分做填充 for (int yy = 0; yy < height; yy++) { for (int xx = (int)point[BannerNum - 1].X + dw; xx < width; xx++) { r = imageIn.getRComponent(xx, yy); g = imageIn.getGComponent(xx, yy); b = imageIn.getBComponent(xx, yy); clone.setPixelColor(xx, yy, r, g, b); } } } return(clone); }
public override Image process(Image imageIn) { int r, g, b; int width = imageIn.getWidth(); int height = imageIn.getHeight(); double hw = width / 2.0; double hh = height / 2.0; int ratio = width > height ? height * 32768 / width : width * 32768 / height; // Calculate center, min and max int cx = width >> 1; int cy = height >> 1; int max = cx * cx + cy * cy; int min = (int)(max * 0.5); int diff = max - min; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (m_focusType == 1)//椭圆 { // Calculate distance to center and adapt aspect ratio int dx = cx - x; int dy = cy - y; if (imageIn.getWidth() > imageIn.getHeight()) { dy = (dy * ratio) >> 14; } else { dx = (dx * ratio) >> 14; } int distSq = dx * dx + dy * dy; if (distSq <= min) continue; } else if (m_focusType == 2)//长方框 { bool inarray = false; if ((x < m_size) && (y < height - x) && (y >= x)) inarray = true; // left else if ((y < m_size) && (x < width - y) && (x >= y)) inarray = true; // top else if ((x > width - m_size) && (y >= width - x) && (y < height + x - width)) inarray = true; // right else if (y > height - m_size) inarray = true; // bottom if (!inarray) continue; } int i = (int)(x - hw); int j = (int)(y - hh); b = 0; g = 0; r = 0; for (int mm = 0; mm < aasamples; mm++) { double u = i + m_aapt[mm].X; double v = j - m_aapt[mm].Y; double s = m_cos * u + m_sin * v; double t = -m_sin * u + m_cos * v; s += m_curvature * Math.Tan(s * m_scale); t += m_curvature * Math.Tan(t * m_scale); u = m_cos * s - m_sin * t; v = m_sin * s + m_cos * t; int xSample = (int)(hw + u); int ySample = (int)(hh + v); xSample = Function.FClamp(xSample, 0, width - 1); ySample = Function.FClamp(ySample, 0, height - 1); r += imageIn.getRComponent(xSample, ySample); g += imageIn.getGComponent(xSample, ySample); b += imageIn.getBComponent(xSample, ySample); } imageIn.setPixelColor(x, y, Image.SAFECOLOR(r / aasamples), Image.SAFECOLOR(g / aasamples), Image.SAFECOLOR(b / aasamples)); } } return imageIn; }
public Image process(Image imageIn) { Color rgb = new Color(); YCbCr ycbcr = new YCbCr(); float ky = 0, by = 0; float kcb = 0, bcb = 0; float kcr = 0, bcr = 0; // Y line parameters if (inY.Max != inY.Min) { ky = (outY.Max - outY.Min) / (inY.Max - inY.Min); by = outY.Min - ky * inY.Min; } // Cb line parameters if (inCb.Max != inCb.Min) { kcb = (outCb.Max - outCb.Min) / (inCb.Max - inCb.Min); bcb = outCb.Min - kcb * inCb.Min; } // Cr line parameters if (inCr.Max != inCr.Min) { kcr = (outCr.Max - outCr.Min) / (inCr.Max - inCr.Min); bcr = outCr.Min - kcr * inCr.Min; } for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { rgb.R = (byte)imageIn.getRComponent(x, y); rgb.G = (byte)imageIn.getGComponent(x, y); rgb.B = (byte)imageIn.getBComponent(x, y); // convert to YCbCr ycbcr = YCbCr.FromRGB(rgb, ycbcr); // correct Y if (ycbcr.Y >= inY.Max) ycbcr.Y = outY.Max; else if (ycbcr.Y <= inY.Min) ycbcr.Y = outY.Min; else ycbcr.Y = ky * ycbcr.Y + by; // correct Cb if (ycbcr.Cb >= inCb.Max) ycbcr.Cb = outCb.Max; else if (ycbcr.Cb <= inCb.Min) ycbcr.Cb = outCb.Min; else ycbcr.Cb = kcb * ycbcr.Cb + bcb; // correct Cr if (ycbcr.Cr >= inCr.Max) ycbcr.Cr = outCr.Max; else if (ycbcr.Cr <= inCr.Min) ycbcr.Cr = outCr.Min; else ycbcr.Cr = kcr * ycbcr.Cr + bcr; // convert back to RGB rgb = YCbCr.ToRGB(ycbcr, rgb); imageIn.setPixelColor(x, y, rgb.R, rgb.G, rgb.B); } } return imageIn; }
// @Override public Image process(Image imageIn) { // Image size int width = imageIn.getWidth(); int height = imageIn.getHeight(); bool[,] mask = null; int[] grayMatrix = new int[256]; // Init gray matrix int outlineCase = 1; double rand = new Random().NextDouble(); if (rand > 0.33 && rand < 0.66) { outlineCase = 2; } else if (rand > 0.66) { outlineCase = 3; } for (int i = 255; i >= 0; i--) { int red = i, green = i, blue = i; if (i > 127) { switch (outlineCase) { case 1: red = 255 - i; break; case 2: green = 255 - i; break; case 3: blue = 255 - i; break; } } grayMatrix[255 - i] = (255 << 24) + (red << 16) + (green << 8) + blue; } int [,] luminance = new int[width, height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (mask != null && !mask[x, y]) { continue; } luminance[x, y] = (int)Luminance(imageIn.getRComponent(x, y), imageIn.getGComponent(x, y), imageIn.getBComponent(x, y)); } } int grayX, grayY; int magnitude; for (int y = 1; y < height - 1; y++) { for (int x = 1; x < width - 1; x++) { if (mask != null && !mask[x, y]) { continue; } grayX = -luminance[x - 1, y - 1] + luminance[x - 1, y - 1 + 2] - 2 * luminance[x - 1 + 1, y - 1] + 2 * luminance[x - 1 + 1, y - 1 + 2] - luminance[x - 1 + 2, y - 1] + luminance[x - 1 + 2, y - 1 + 2]; grayY = luminance[x - 1, y - 1] + 2 * luminance[x - 1, y - 1 + 1] + luminance[x - 1, y - 1 + 2] - luminance[x - 1 + 2, y - 1] - 2 * luminance[x - 1 + 2, y - 1 + 1] - luminance[x - 1 + 2, y - 1 + 2]; // Magnitudes sum magnitude = 255 - truncate(Math.Abs(grayX) + Math.Abs(grayY)); int grayscaleColor = grayMatrix[magnitude]; // Apply the color into a new image imageIn.setPixelColor(x, y, grayscaleColor); } } return(imageIn); }
//@Override public Image process(Image imageIn) { int[,] h = new int[3,256]; int[] array = new int[3]; int[] rgb = new int[] { 255, 255, 255 }; int[] bb = new int[256]; int[] gg = new int[256]; int[] rr = new int[256]; int intensity = (int) (this.Intensity * 255f); int intensity_invert = 255 - intensity; for (int x = 0; x < imageIn.getWidth() - 1; x++){ for (int y = 0; y < imageIn.getHeight() - 1; y++) { h[0,imageIn.getRComponent(x, y)]++; h[1,imageIn.getGComponent(x, y)]++; h[2,imageIn.getBComponent(x, y)]++; } } int[] percentileColor = GetPercentileColor(h, 0.005f); int[] meanColor = GetMeanColor(h); int[] hi = GetPercentileColor(h, 0.995f); float[] gamma = ComputeGamma(percentileColor, meanColor, hi); for (int i = 0; i < 3; i++){ for (int j = 0; j < 256; j++){ int[] arr = new int[3]; for (int n = 0; n < 3; n++){ float percent = j - percentileColor[n]; if (percent < 0f){ arr[n] = array[n]; } else if ((percent + percentileColor[n]) >= hi[n]){ arr[n] = rgb[n]; } else { double adjust = array[n] + ((rgb[n] - array[n]) * Math.Pow((double) (percent / ((float) (hi[n] - percentileColor[n]))), (double) gamma[n])); arr[n] = (adjust > 255.0) ? ((int) 255.0) : ((adjust < 0.0) ? ((int) 0.0) : ((int) adjust)); } } rr[j] = arr[0]; gg[j] = arr[1]; bb[j] = arr[2]; } } Image clone = imageIn.clone(); int r,g,b; for (int x = 0; x < imageIn.getWidth() - 1; x++){ for (int y = 0; y < imageIn.getHeight() - 1; y++) { r = clone.getRComponent(x, y); g = clone.getGComponent(x, y); b = clone.getBComponent(x, y); r = (r * intensity_invert + rr[r] * intensity) >> 8; g = (g * intensity_invert + gg[g] * intensity) >> 8; b = (b * intensity_invert + bb[b] * intensity) >> 8; imageIn.setPixelColor(x, y, r, g, b); } } return imageIn;//��ֱ��ͼģʽ��ǿ }
//@Override public virtual Image process(Image imageIn) { int r, g, b; int width = imageIn.getWidth(); int height = imageIn.getHeight(); int realxpos = (int)(width * Center.X); int realypos = (int)(height * Center.Y); float realradius = Math.Min(width, height) * Radius; Image clone = imageIn.clone(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float pos = 1f - ((float)Math.Sqrt((double)(((x - realxpos) * (x - realxpos)) + (y - realypos) * (y - realypos))) / realradius); if (pos <= 0f) { pos = 1f - (Distortion * pos * pos); float pos1 = (x - realxpos) * pos + realxpos; float pos2 = (y - realypos) * pos + realypos; int x1 = (int)pos1; float pos3 = pos1 - x1; int x2 = (pos3 > 0f) ? (x1 + 1) : x1; int y1 = (int)pos2; float pos4 = pos2 - y1; int y2 = (pos4 > 0f) ? (y1 + 1) : y1; if (x1 < 0) { x1 = 0; } else if (x1 >= width) { x1 = width - 1; } if (x2 < 0) { x2 = 0; } else if (x2 >= width) { x2 = width - 1; } if (y1 < 0) { y1 = 0; } else if (y1 >= height) { y1 = height - 1; } if (y2 < 0) { y2 = 0; } else if (y2 >= height) { y2 = height - 1; } r = clone.getRComponent(x1, y1); g = clone.getGComponent(x1, y1); b = clone.getBComponent(x1, y1); int r2 = clone.getRComponent(x2, y1); int g2 = clone.getGComponent(x2, y1); int b2 = clone.getBComponent(x2, y1); int r3 = clone.getRComponent(x2, y2); int g3 = clone.getGComponent(x2, y2); int b3 = clone.getBComponent(x2, y2); int r4 = clone.getRComponent(x1, y2); int g4 = clone.getGComponent(x1, y2); int b4 = clone.getBComponent(x1, y2); r = (int)((r * (1f - pos4) * (1f - pos3) + r2 * (1f - pos4) * pos3 + r3 * pos4 * pos3) + r4 * pos4 * (1f - pos3)); g = (int)((g * (1f - pos4) * (1f - pos3) + g2 * (1f - pos4) * pos3 + g3 * pos4 * pos3) + g4 * pos4 * (1f - pos3)); b = (int)((b * (1f - pos4) * (1f - pos3) + b2 * (1f - pos4) * pos3 + b3 * pos4 * pos3) + b4 * pos4 * (1f - pos3)); } else { r = clone.getRComponent(x, y); g = clone.getGComponent(x, y); b = clone.getBComponent(x, y); } imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn); }
//@Override public Image process(Image imageIn) { // Image size int width = imageIn.getWidth(); int height = imageIn.getHeight(); bool[][] mask = null; int[] grayMatrix = new int[256]; // Init gray matrix for (int i = 0; i <= 255; i++) { grayMatrix[i] = (255 << 24) + (i << 16) + (i << 8) + i; } int [,] luminance = new int[width, height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (mask != null && !mask[x][y]) { continue; } luminance[x, y] = (int)Luminance(imageIn.getRComponent(x, y), imageIn.getGComponent(x, y), imageIn.getBComponent(x, y)); } } int grayX, grayY; int magnitude; for (int y = 1; y < height - 1; y++) { for (int x = 1; x < width - 1; x++) { if (mask != null && !mask[x][y]) { continue; } grayX = -luminance[x - 1, y - 1] + luminance[x - 1, y - 1 + 2] - 2 * luminance[x - 1 + 1, y - 1] + 2 * luminance[x - 1 + 1, y - 1 + 2] - luminance[x - 1 + 2, y - 1] + luminance[x - 1 + 2, y - 1 + 2]; grayY = luminance[x - 1, y - 1] + 2 * luminance[x - 1, y - 1 + 1] + luminance[x - 1, y - 1 + 2] - luminance[x - 1 + 2, y - 1] - 2 * luminance[x - 1 + 2, y - 1 + 1] - luminance[x - 1 + 2, y - 1 + 2]; // Magnitudes sum magnitude = 255 - truncate(Math.Abs(grayX) + Math.Abs(grayY)); int grayscaleColor = grayMatrix[magnitude]; // Apply the color into a new image imageIn.setPixelColor(x, y, grayscaleColor); } } return(imageIn); }
public override Image process(Image imageIn) { { int r, g, b; int width = imageIn.getWidth(); int height = imageIn.getHeight(); double hw = width / 2.0; double hh = imageIn.getHeight() / 2.0; for(int x = 0 ; x < width ; x++){ for(int y = 0 ; y < height ; y++){ int i = (int)(x - hw); int j = (int)(y - hh); b=0; g=0; r=0; for (int mm=0 ; mm < aasamples ; mm++){ double u = i + m_aapt[mm].X ; double v = j - m_aapt[mm].Y ; double s = m_cos * u + m_sin * v ; double t = -m_sin * u + m_cos * v ; s += m_curvature * Math.Tan(s * m_scale) ; t += m_curvature * Math.Tan(t * m_scale) ; u = m_cos * s - m_sin * t ; v = m_sin * s + m_cos * t ; int xSample = (int)(hw + u) ; int ySample = (int)(hh + v) ; xSample = Function.FClamp (xSample, 0, width -1) ; ySample = Function.FClamp (ySample, 0, height-1) ; r += imageIn.getRComponent(xSample, ySample); g += imageIn.getGComponent(xSample, ySample); b += imageIn.getBComponent(xSample, ySample); } imageIn.setPixelColor(x, y, Image.SAFECOLOR(r/aasamples), Image.SAFECOLOR(g/aasamples), Image.SAFECOLOR(b/aasamples)); } } return imageIn; } }
public Image process(Image imageIn) { // get source image size int width = imageIn.getWidth(); int height = imageIn.getHeight(); // processing region's dimension int widthToProcess = width; int heightToProcess = height; // if generator was specified, then generate a texture // otherwise use provided texture if ( textureGenerator != null ) { texture = textureGenerator.Generate( width, height ); } else { widthToProcess = Math.Min( width, texture.GetLength( 1 ) ); heightToProcess = Math.Min( height, texture.GetLength( 0 ) ); } int r, g, b; // texture for ( int y = 0; y < heightToProcess; y++ ) { for ( int x = 0; x < widthToProcess; x++ ) { double t = texture[y, x]; r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); // process each pixel r = (byte) Math.Min( 255.0f, ( preserveLevel * r) + ( filterLevel * r) * t ); g = (byte) Math.Min( 255.0f, ( preserveLevel * g) + ( filterLevel * g) * t ); b = (byte) Math.Min( 255.0f, ( preserveLevel * b) + ( filterLevel * b) * t ); imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
public Image process(Image imageIn) { Color rgb = new Color(); YCbCr ycbcr = new YCbCr(); float ky = 0, by = 0; float kcb = 0, bcb = 0; float kcr = 0, bcr = 0; // Y line parameters if (inY.Max != inY.Min) { ky = (outY.Max - outY.Min) / (inY.Max - inY.Min); by = outY.Min - ky * inY.Min; } // Cb line parameters if (inCb.Max != inCb.Min) { kcb = (outCb.Max - outCb.Min) / (inCb.Max - inCb.Min); bcb = outCb.Min - kcb * inCb.Min; } // Cr line parameters if (inCr.Max != inCr.Min) { kcr = (outCr.Max - outCr.Min) / (inCr.Max - inCr.Min); bcr = outCr.Min - kcr * inCr.Min; } for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { rgb.R = (byte)imageIn.getRComponent(x, y); rgb.G = (byte)imageIn.getGComponent(x, y); rgb.B = (byte)imageIn.getBComponent(x, y); // convert to YCbCr ycbcr = YCbCr.FromRGB(rgb, ycbcr); // correct Y if (ycbcr.Y >= inY.Max) { ycbcr.Y = outY.Max; } else if (ycbcr.Y <= inY.Min) { ycbcr.Y = outY.Min; } else { ycbcr.Y = ky * ycbcr.Y + by; } // correct Cb if (ycbcr.Cb >= inCb.Max) { ycbcr.Cb = outCb.Max; } else if (ycbcr.Cb <= inCb.Min) { ycbcr.Cb = outCb.Min; } else { ycbcr.Cb = kcb * ycbcr.Cb + bcb; } // correct Cr if (ycbcr.Cr >= inCr.Max) { ycbcr.Cr = outCr.Max; } else if (ycbcr.Cr <= inCr.Min) { ycbcr.Cr = outCr.Min; } else { ycbcr.Cr = kcr * ycbcr.Cr + bcr; } // convert back to RGB rgb = YCbCr.ToRGB(ycbcr, rgb); imageIn.setPixelColor(x, y, rgb.R, rgb.G, rgb.B); } } return(imageIn); }
// @Override public Image process(Image imageIn) { // Image size int width = imageIn.getWidth(); int height = imageIn.getHeight(); bool[,] mask = null; int[] grayMatrix = new int[256]; // Init gray matrix int outlineCase = 1; double rand = new Random().NextDouble(); if (rand>0.33 && rand<0.66){ outlineCase=2; } else if (rand>0.66){ outlineCase=3; } for (int i = 255; i >= 0; i--) { int red=i,green=i,blue=i; if (i>127) { switch(outlineCase){ case 1 : red = 255-i; break; case 2 : green = 255-i; break; case 3 : blue = 255-i; break; } } grayMatrix[255 - i] = (255 << 24) + (red << 16) + (green << 8) + blue; } int [,] luminance = new int[width,height]; for (int y = 0; y < height ; y++) { for (int x = 0; x < width ; x++) { if(mask != null && !mask[x,y]){ continue; } luminance[x, y] = (int)Luminance(imageIn.getRComponent(x, y), imageIn.getGComponent(x, y), imageIn.getBComponent(x, y)); } } int grayX, grayY; int magnitude; for (int y = 1; y < height-1; y++) { for (int x = 1; x < width-1; x++) { if(mask != null && !mask[x,y]){ continue; } grayX = - luminance[x-1,y-1] + luminance[x-1,y-1+2] - 2* luminance[x-1+1,y-1] + 2* luminance[x-1+1,y-1+2] - luminance[x-1+2,y-1]+ luminance[x-1+2,y-1+2]; grayY = luminance[x-1,y-1] + 2* luminance[x-1,y-1+1] + luminance[x-1,y-1+2] - luminance[x-1+2,y-1] - 2* luminance[x-1+2,y-1+1] - luminance[x-1+2,y-1+2]; // Magnitudes sum magnitude = 255 - truncate(Math.Abs(grayX) + Math.Abs(grayY)); int grayscaleColor = grayMatrix[magnitude]; // Apply the color into a new image imageIn.setPixelColor(x, y, grayscaleColor); } } return imageIn; }
public override Image process(Image imageIn) { int r, g, b; int width = imageIn.getWidth(); int height = imageIn.getHeight(); double hw = width / 2.0; double hh = height / 2.0; int ratio = width > height ? height * 32768 / width : width * 32768 / height; // Calculate center, min and max int cx = width >> 1; int cy = height >> 1; int max = cx * cx + cy * cy; int min = (int)(max * 0.5); int diff = max - min; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (m_focusType == 1)//椭圆 { // Calculate distance to center and adapt aspect ratio int dx = cx - x; int dy = cy - y; if (imageIn.getWidth() > imageIn.getHeight()) { dy = (dy * ratio) >> 14; } else { dx = (dx * ratio) >> 14; } int distSq = dx * dx + dy * dy; if (distSq <= min) { continue; } } else if (m_focusType == 2)//长方框 { bool inarray = false; if ((x < m_size) && (y < height - x) && (y >= x)) { inarray = true; // left } else if ((y < m_size) && (x < width - y) && (x >= y)) { inarray = true; // top } else if ((x > width - m_size) && (y >= width - x) && (y < height + x - width)) { inarray = true; // right } else if (y > height - m_size) { inarray = true; // bottom } if (!inarray) { continue; } } int i = (int)(x - hw); int j = (int)(y - hh); b = 0; g = 0; r = 0; for (int mm = 0; mm < aasamples; mm++) { double u = i + m_aapt[mm].X; double v = j - m_aapt[mm].Y; double s = m_cos * u + m_sin * v; double t = -m_sin * u + m_cos * v; s += m_curvature * Math.Tan(s * m_scale); t += m_curvature * Math.Tan(t * m_scale); u = m_cos * s - m_sin * t; v = m_sin * s + m_cos * t; int xSample = (int)(hw + u); int ySample = (int)(hh + v); xSample = Function.FClamp(xSample, 0, width - 1); ySample = Function.FClamp(ySample, 0, height - 1); r += imageIn.getRComponent(xSample, ySample); g += imageIn.getGComponent(xSample, ySample); b += imageIn.getBComponent(xSample, ySample); } imageIn.setPixelColor(x, y, Image.SAFECOLOR(r / aasamples), Image.SAFECOLOR(g / aasamples), Image.SAFECOLOR(b / aasamples)); } } return(imageIn); }
//@Override public Image process(Image imageIn) { int[,] h = new int[3, 256]; int[] array = new int[3]; int[] rgb = new int[] { 255, 255, 255 }; int[] bb = new int[256]; int[] gg = new int[256]; int[] rr = new int[256]; int intensity = (int)(this.Intensity * 255f); int intensity_invert = 255 - intensity; for (int x = 0; x < imageIn.getWidth() - 1; x++) { for (int y = 0; y < imageIn.getHeight() - 1; y++) { h[0, imageIn.getRComponent(x, y)]++; h[1, imageIn.getGComponent(x, y)]++; h[2, imageIn.getBComponent(x, y)]++; } } int[] percentileColor = GetPercentileColor(h, 0.005f); int[] meanColor = GetMeanColor(h); int[] hi = GetPercentileColor(h, 0.995f); float[] gamma = ComputeGamma(percentileColor, meanColor, hi); for (int i = 0; i < 3; i++) { for (int j = 0; j < 256; j++) { int[] arr = new int[3]; for (int n = 0; n < 3; n++) { float percent = j - percentileColor[n]; if (percent < 0f) { arr[n] = array[n]; } else if ((percent + percentileColor[n]) >= hi[n]) { arr[n] = rgb[n]; } else { double adjust = array[n] + ((rgb[n] - array[n]) * Math.Pow((double)(percent / ((float)(hi[n] - percentileColor[n]))), (double)gamma[n])); arr[n] = (adjust > 255.0) ? ((int)255.0) : ((adjust < 0.0) ? ((int)0.0) : ((int)adjust)); } } rr[j] = arr[0]; gg[j] = arr[1]; bb[j] = arr[2]; } } Image clone = imageIn.clone(); int r, g, b; for (int x = 0; x < imageIn.getWidth() - 1; x++) { for (int y = 0; y < imageIn.getHeight() - 1; y++) { r = clone.getRComponent(x, y); g = clone.getGComponent(x, y); b = clone.getBComponent(x, y); r = (r * intensity_invert + rr[r] * intensity) >> 8; g = (g * intensity_invert + gg[g] * intensity) >> 8; b = (b * intensity_invert + bb[b] * intensity) >> 8; imageIn.setPixelColor(x, y, r, g, b); } } return(imageIn);//做直方图模式增强 }