Intensity Level Slicing With C# – Explore Image Processing
In this tutorial we will be talking about intensity level slicing in image processing. What is Intensity Level Slicing It’s a process that highlights pixels in an arbitrary...
Filter by Category
In this tutorial we will be talking about intensity level slicing in image processing. What is Intensity Level Slicing It’s a process that highlights pixels in an arbitrary...
This post is a short revision of Contrast Stretch post we already worked on in the past. Where we talked about histogram equalization, which is a little more complex method than...
What is Log Transformation Anyway? Log transformation in image processing is a part of gray level transformations. It works by transforming each pixel individually. It is usually...
Where Do We Start? There are numerous ways you can flip an image horizontally. It’s pretty basic functionality in image processing. I wanted to challenge myself and not just...
Let’s Get Started A very basic problem that we face in image processing is how to scale images without making them look deformed when we want to make it of an arbitrary...
List of contents: Short intro First Method – Google Opinion Rewards Second Method – Taking & Fortifying Gyms Third Method – Answer a Few Questions List of...
Zero padding an image is useful when we’re convolving it with a filter of certain size. How much padding should we use depends on how big our filter is. What is the purpose...
Gamma correction is a process, which allows you to set the brightness of screen. You can often run into this setting in video games, where you set the brightness of your screen...
A negative image is a complete inversion of an image, we would say to be normal. In other words, dark areas will appear light, and light areas will become dark. More in detail, a...
Gaussian blur is an image processing operation, that reduces noise in images. It does so by a convolution process, using a matrix that contains values calculated by a Gaussian...
In this tutorial we will be talking about intensity level slicing in image processing.
It’s a process that highlights pixels in an arbitrary range of intensities. I created an example project that demonstrates this functionality.
There are two different themes this process can be applied. We could highlight our desired range of intensities and set those pixels to white and everything else to black. This way we would produce a binary image.
Another option is we highlight our range of intensities and leave everything else unchanged.
Graph above shows intensities, horizontal axis show for input and vertical for output.
Left graph shows the first method we described, where we produce a binary image. As for the right graph we can see that only a certain range of intensities is changed in the output, while other intensity levels stay unchanged.
“a” and “b” represent the lowest and the highest intensity levels to be highlighted. Or in other words, they define the position and width of the intensity level band to be highlighted. We also need to define the highlighting intensity, to which our pixels will be changed to.
This process is applied in various different fields, such as satellite imagery and x-ray imagery.
public static Bitmap IntensityLevel(Bitmap bmp, int min, int max, int intensity)
{
int w = bmp.Width;
int h = bmp.Height;
BitmapData sd = bmp.LockBits(new Rectangle(0, 0, w, h),
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
int bytes = sd.Stride * sd.Height;
byte[] buffer = new byte[bytes];
byte[] result = new byte[bytes];
Marshal.Copy(sd.Scan0, buffer, 0, bytes);
bmp.UnlockBits(sd);
int current = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
current = y * sd.Stride + x * 4;
for (int i = 0; i < 3; i++)
{
if (buffer[current + i] >= (byte)min && buffer[current + i] <= (byte)max)
{
result[current + i] = (byte)intensity;
}
else
{
result[current + i] = buffer[current + i];
}
result[current + 3] = 255;
}
}
}
Bitmap resimg = new Bitmap(w, h);
BitmapData rd = resimg.LockBits(new Rectangle(0, 0, w, h),
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb);
Marshal.Copy(result, 0, rd.Scan0, bytes);
resimg.UnlockBits(rd);
return resimg;
}
There are some things we need to provide for our function to work. We need to set intensity range by providing the lowest and the highest intensity to be highlighted. And lastly we need to set the highlighting intensity.
This code works for colored images too. Intensities are highlighted across all channels. Project also includes a function to convert color images into grayscale.
If you liked this project, let me know in the comments.
Is there anything you might add?
I’m always open for your suggestions.