![]() ![]() The filter depends on the Filter property of the ResamplingService object.Ī few people mentioned the fact that older version of this library could not resample images with alpha channel. When you run the resampling, a new instance of ResamplingFilter is created as well. There is one class representing common resampling filter: The most important class is ResamplingService, whose method provides all the functionality. This code file contains few classes for precise resampling. Now point our view to ResamplingService.cs. If you want closer explanation of how convolution works, see one of the excellent articles from Christian Grauss at this site. The interpolation of the scaled image is done by image filtering, or convolution between image (intensity function) and convolution kernel. ![]() This interpolation includes more neighbors in every new pixel value and weights are distributed more effectively (the function is a cubic spline): If you want achieve the "best" quality, then use High Quality Bicubic ( InterpolationMode.HighQualityBicubic). The weight of neighboring pixels is a linear function. One of the simplest interpolation/resampling filter is Linear filter ( InterpolationMode.Low). Value of the new pixel can be computed as weighted average of nearest pixel and its neighbors (weights are given by the filter). When the image is scaled up, a space between pixels must be filled with some new pixel values. Much better results can be achieved using some interpolation spline. On the contrary, when downsampling by factor 2, every second pixel is lost: So called Nearest Neighbor ( .NearestNeighbor) filter is the fastest one, but it produces blocky artifacts on image stretching because this filter just copies samples from old image to a new image (no interpolation between them). If you've decided for GDI+ to resize your images, you can choose from variety of filters. Image resizing (or resampling) is one of the most common functions of every raster image processing tool. ![]() Grfx.PixelOffsetMode = PixelOffsetMode.HighQuality Image Resampling with GDI+ Filters Graphics grfx = Graphics.FromImage(imgInput) This problem can be easily solved using the ImageAttributes object in DrawImage method override (don't forget to dispose it): It's hard to see, but that last image is sharper than the third one, but there is other more visible defect in the GDI+ resampled version: The original roof image can be found in Wikipedia in the "Moiré pattern" article. This filter has three times larger radius, so it provides highest quality image from these filters (roof tiles are more visible and sharper): Finally, there is the image output from filtering via Lanczos8 filter (radius 8) from the ResamplingService class. Even better quality is provided by the High Quality Bicubic filter (radius 2). Much better quality can be obtained by using the GDI+ Low filter (second image - filter has radius 1). These examples shows the aliasing artifact produced by a so called Nearest Neighbor filter (first image from left). This effect is most visible when using a filter with low radius (this filter includes too few adjacent pixels around sample from old image). Samples taken from old images create new frequencies in the new image. This artifact can be seen when one shrinks images without blurring image before zooming, so the high frequencies in the image create a pattern. The first mentoined artifact was the Moiré pattern which appears due to aliasing. This article presents class for image resampling with more precise filters. In spite of GDI+, filters have big problems with Moiré patterns, they make some artifacts on image borders (it's not an error and can be eliminated, as will be discussed later). In order to prevent these artifacts, enhance edges and reduce pixelation - more complex filters were designed. One of the most unpleasant artifacts is the Moiré effect which can appear while scaling detailed image down. These filters works with reference to image's frequency spectra or edges. In some software products (especially specialized software for astronomical and medical imaging), we can see filters with strange names like Hermite, Mitchell or Lanczos. These are part of some "standard", but experts and freaks know that these filters doesn't provide as nice images as other filters can. A commonly used image resizing methods are e.g. Even the GDI+ methods aren't the most comprehensive. ![]()
0 Comments
Leave a Reply. |