Images

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: ...

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...

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...

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 =...

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:...