public static Bitmap ModuleGradient(this Bitmap bm) { var newBm = new Bitmap(bm); for (var y = 1; y < bm.Height - 1; y++) { for (var x = 1; x < bm.Width - 1; x++) { Color colorH = bm.ApplyMask(x, y, Gx), colorV = bm.ApplyMask(x, y, Gy); newBm.SetPixel(x, y, Color.FromArgb( Pythagoras(colorH.R, colorV.R), Pythagoras(colorH.G, colorV.G), Pythagoras(colorH.B, colorV.B))); } } return(newBm); }
private static Bitmap ApplyMask(this Bitmap bm, int[,] mask) { var newBm = new Bitmap(bm); for (var y = 1; y < bm.Height - 1; y++) { for (var x = 1; x < bm.Width - 1; x++) { newBm.SetPixel(x, y, bm.ApplyMask(x, y, mask)); } } return(newBm); }
public Bitmap[] GetBitmaps(Bitmap mask) { List <Bitmap> ret = new List <Bitmap>(); foreach (var a in this) { Bitmap bmp = (Bitmap)Bitmap.FromFile(a.fileName); if (mask != null) { bmp.ApplyMask(mask); } ret.Add(bmp); } return(ret.ToArray()); }
public String Classify(String fileName, String[] map) { Bitmap bmp = (Bitmap)Bitmap.FromFile(fileName); if (mask != null) { bmp.ApplyMask(mask); } double[] features = bow.Transform(bmp); double[] answer = network.Compute(features); int actual; answer.Max(out actual); //logger.logStr("classifyImage " + map[actual] + " " + actual); bmp.Dispose(); return(map[actual]); }
public static async Task <APIResponse <Bitmap> > GetAvatar(string userID) { // If avatars contains the userID key, the download is either in progress, or has completed if (avatars.ContainsKey(userID)) { object avatar = avatars[userID]; // If the object is an APIResponse, return it if (avatar is APIResponse <Bitmap> ) { return((APIResponse <Bitmap>)avatar); } else { // If not, its a WaitHandle, so cast it and await it WaitHandle handle = (WaitHandle)avatar; await handle.WaitOneAsync(); return((APIResponse <Bitmap>)avatars[userID]); } } EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.ManualReset); avatars.Add(userID, ewh); try { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(APIBaseURL, string.Format("users/{0}/image", userID))); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Token); bool rateLimited = false; HttpResponseMessage response = null; while (!rateLimited) { response = await client.SendAsync(request); if ((int)response.StatusCode == 429) { await Task.Delay(1000); } else { rateLimited = true; } } APIResponse <Bitmap> retVal; if (response.StatusCode != HttpStatusCode.OK) { string responseContent = await response.Content.ReadAsStringAsync(); APIErrorResponse error = JsonConvert.DeserializeObject <APIErrorResponse>(responseContent); retVal = new APIResponse <Bitmap>() { Success = false, Error = error.Message }; avatars[userID] = retVal; ewh.Set(); return(retVal); } Bitmap avatar = new Bitmap(await response.Content.ReadAsStreamAsync()); retVal = new APIResponse <Bitmap>() { Success = true, Value = avatar.ApplyMask(Mattermost.Properties.Resources.AvatarMask) }; avatars[userID] = retVal; ewh.Set(); return(retVal); } catch (Exception e) { APIResponse <Bitmap> retVal = new APIResponse <Bitmap>() { Success = false, Error = e.Message }; avatars[userID] = retVal; ewh.Set(); return(retVal); } }
public static Bitmap HorizontalGradient(this Bitmap bm) => bm.ApplyMask(Gx);
public static Bitmap VerticalGradient(this Bitmap bm) => bm.ApplyMask(Gy);
public static Bitmap Hough(this Bitmap bm) { var points = new List <Point>(); for (var y = 1; y < bm.Height - 1; y++) { for (var x = 1; x < bm.Width - 1; x++) { Color colorH = bm.ApplyMask(x, y, Gx), colorV = bm.ApplyMask(x, y, Gy), color = Color.FromArgb( Pythagoras(colorH.R, colorV.R), Pythagoras(colorH.G, colorV.G), Pythagoras(colorH.B, colorV.B)); if (color.R + color.G + color.B > 220) { points.Add(new Point(x, y)); } } } var len = Pythagoras(bm.Height, bm.Width, false); var matrix = new int[180, 2 * len]; // Матрица собирающих элементов Array.Clear(matrix, 0, 2 * len); var max = 0; for (var i = 0; i < 180; i++) { double sinI = Math.Sin((i - 90) * Math.PI / 180), cosI = Math.Cos((i - 90) * Math.PI / 180); foreach (var d in points.Select(point => point.X * cosI + point.Y * sinI)) { var j = (int)d + len; matrix[i, j]++; if (matrix[i, j] > max) { max = matrix[i, j]; } } } var newBm = new Bitmap(180, 2 * len); for (var i = 0; i < 180; i++) { for (var j = 0; j < 2 * len; j++) { if (matrix[i, j] > max - 80) { newBm.SetPixel(i, j, Color.Yellow); } else if (matrix[i, j] > max - 115) { newBm.SetPixel(i, j, Color.DeepPink); } else if (matrix[i, j] > max - 125) { newBm.SetPixel(i, j, Color.Cyan); } else { newBm.SetPixel(i, j, Color.Black); } } } return(newBm); }
public static Bitmap Laplacian3(this Bitmap bm) => bm.ApplyMask(Laplaсian3);