C# Tutorial: How To Create An Image Negative
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...
Filter by Category
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...
Erosion is a morphological process, where pixels at an object boundaries are removed. Erosion and dilation are a pair of basic morphological transformations, which are completely...
Dilation is a simple morphology process which changes pixel intensities based on the change of intensities that occur at object boundaries. This process is used on grayscale...
What is sobel operator? Well, basically it’s 2 kernels, with which we can process an image in a way, that only edges are visible. It is commonly used for grayscale images,...
Contrast stretch or otherwise known as normalization is a process where your image’s intensity is changed in such a way, that dark pixels become darker and light pixels...
Grayscale images are basically black and white images. These images are good for programming, since their pixels hold only intensity values or in other words, shades of gray, they...
Why is image optimization important? There are a few different image formats that you can choose from to display it on your website. But it is not all the same even if it may look...
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 negative is created by subtracting the entire intensity range by values across all color channels of all pixels.
Where Ac denotes a complement of A set of values. This basicaly means that every value of our normal image is being changed. Following with x and y, which are spatial coordinates of our image elements – pixels. Intensity is denoted by value z. K represents the maximum intensity or value a color channel can hold. For 8-bit images, this value would be 255.
private Bitmap Negative(Bitmap image) { int w = image.Width; int h = image.Height; BitmapData srcData = image.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int bytes = srcData.Stride * srcData.Height; byte[] buffer = new byte[bytes]; byte[] result = new byte[bytes]; Marshal.Copy(srcData.Scan0, buffer, 0, bytes); image.UnlockBits(srcData); int current = 0; int cChannels = 3; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { current = y * srcData.Stride + x * 4; for (int c = 0; c < cChannels; c++) { result[current + c] = (byte)(255 - buffer[current + c]); } result[current + 3] = 255; } } Bitmap resImg = new Bitmap(w, h); BitmapData resData = resImg.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); Marshal.Copy(result, 0, resData.Scan0, bytes); resImg.UnlockBits(resData); return resImg; }