Shawn Weisfeld

I find when I talk to myself nobody listens. - Shawn Weisfeld
posts - 365, comments - 174, trackbacks - 34

My Links

News


Shawn Weisfeld's Facebook profile

The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Archives

Post Categories

Images

Extension Method to Resize an Image

I wrote this for an INETA project that I have been working on, but thought it would be great to share with everyone. We had a need to take an image and change its size. Below is an implementation of a Resize Extension Method on the .NET Image object.  I borrowed some ideas from this post by Mark McDonnell (http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx) 1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: using System.Drawing; 6: using System.Drawing.Drawing2D; 7: ...

posted @ Sunday, June 28, 2009 6:52 PM | Feedback (3) | Filed Under [ C# Images ]

Image Processing v2.1

BTW to convert from the byte[] back to an image is simple enough private Bitmap ConvertBitmap(byte[] frame, int width, int height){    Bitmap bmp = new Bitmap( width, height, PixelFormat.Format24bppRgb);     BitmapData data = bmp.LockBits( new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);     System.Runtime.InteropServices.Marshal.Copy(frame, 0, data.Scan0, frame.Length);     bmp.UnlockBits(data);    return bmp;}

posted @ Monday, September 17, 2007 7:35 PM | Feedback (0) | Filed Under [ .NET C# Images Robotics ]

Image Processing v2

I was tearing into v1.5 of Microsoft Robotics Studio (http://www.microsoft.com/robotics) and came across a novel way to process the pixels in an image. In previous posts I was using unmanaged C# code and pointers to move around the image. This worked well but is hard to manage. They take the approach of just dumping the entire image to a byte[], pure genius, now why did I not think of that. I will be rebuilding my library to utilize this technique but I thought this was so cool that I just had to share it! /// <summary>/// Coverts a bitmap to a...

posted @ Monday, September 17, 2007 5:47 PM | Feedback (1) | Filed Under [ .NET C# Images Robotics ]

Tampa Code Camp Robot Vision Presentation

Here is the powerpoint for my presentation tomorrow. http://www.onetug.org/DNN/Portals/0/member_files/2007_07_14_robot.ppt

posted @ Saturday, July 14, 2007 3:35 AM | Feedback (0) | Filed Under [ .NET C# Images Microsoft Robotics ]

Bounding Box

In my earlier post I put together an image processing class (http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2006/11/06/Bitmap-Processing-in-C_2300_.aspx). I needed a method that built a bounding box around a given shape. Here is the code: public static void BoundingBox(Bitmap b, ref Point upperLeft, ref Point lowerRight){    ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);    Queue<Point> q = new Queue<Point>();    q.Enqueue(upperLeft);     int jump = 10;     while (q.Count > 0)    {     Point p = q.Dequeue();     AddToStack(q, b, i, new Point(p.X + jump, p.Y), ref upperLeft, ref lowerRight);     AddToStack(q, b, i, new Point(p.X - jump, p.Y), ref upperLeft, ref lowerRight);     AddToStack(q, b, i, new Point(p.X, p.Y + jump), ref upperLeft, ref...

posted @ Monday, May 14, 2007 2:25 PM | Feedback (0) | Filed Under [ C# Images ]

Center of Mass

In my earlier post I put together an image processing class (http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2006/11/06/Bitmap-Processing-in-C_2300_.aspx). I needed a method that found the center of a given mass of pixels. Here is the code: public static Point CenterOfMass(Bitmap b){    ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);    int cogX = 0;    int cogY = 0;    int cogTotal = 0;     for (int column = 0; column < i.Bitmap.Width; column++)    {     for (int row = 0; row < i.Bitmap.Height; row++)     {         int px = i.GetGreyPixel(column, row);         cogX += (px * column);         cogY += (px * row);         cogTotal += px;     }    }    i.UnlockBitmap();    return new Point(cogX / cogTotal, cogY...

posted @ Monday, May 14, 2007 2:23 PM | Feedback (0) | Filed Under [ C# Images ]

Remove Background

In my earlier post I put together an image processing class (http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2006/11/06/Bitmap-Processing-in-C_2300_.aspx). I needed a method that did some segmentation based on a given color. It needed to take in the color and a threshold and it would black out any pixels that are not within the color threshold. Here is the code: public static Bitmap RemoveBackground(Bitmap b, Color c, int threshold){    ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);    int maxGreen = c.G + threshold;    int minGreen = c.G - threshold;    int maxRed = c.R + threshold;    int minRed = c.R - threshold;    int maxBlue = c.B + threshold;    int minBlue...

posted @ Monday, May 14, 2007 2:15 PM | Feedback (0) | Filed Under [ C# Images ]

Stack Based Flood Fill Algorithm

For a recent project I needed a Flood Fill Algorithm (see Flood Fill in Wikipedia, http://en.wikipedia.org/wiki/Flood_fill). Here is my implementation in C++.   Some things to note 1)      I am using the ImagerBitmapClass from a previous post (http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2006/11/06/Bitmap-Processing-in-C_2300_.aspx), which I converted to C++ 2)      I am doing this fill in grey scale, you can easily change it to use full color objects 3)      I am looking for all white objects, converting the first blob of white pixels to a given color, then moving to the next blob with a new color 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 marker = 100;for (int row =...

posted @ Monday, December 4, 2006 12:14 PM | Feedback (0) | Filed Under [ .NET ASP.NET C# Images ]

Bitmap Processing in C#

Need to crack a bitmap and dittle around with its pixels? I know there is a managed get pixel property on the bitmap object but that is SLOW if you have to work with a lot of pixels. After some digging around I have compiled a few examples together to make my ImagerBitmap Class. The class uses unmanaged C# and pointers to iterate over the pixels in an image to do stuff. Since unmanaged code is inherently dangerous everything is made private and only some static functions that perform the image filters are exposed. Some of the functions included are:...

posted @ Monday, November 6, 2006 1:18 PM | Feedback (5) | Filed Under [ C# Images ]

Powered by: