0% found this document useful (0 votes)
101 views

Image Processing For Displacement Filters, Including Swirl

The document discusses various image displacement filters that can be applied to digital images programmatically. It begins with an introduction to displacement filters and how they differ from color filters by changing pixel locations rather than colors. It then outlines the framework used to implement the filters, which involves creating an array to store new pixel locations and applying those offsets. Several example filters are described, including offset, random jitter, swirl, sphere, time warp, moire, water, and pixellate filters. The document concludes by stating that the examples demonstrate what can be done with a displacement filter framework and can serve as a starting point for other explorations.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Image Processing For Displacement Filters, Including Swirl

The document discusses various image displacement filters that can be applied to digital images programmatically. It begins with an introduction to displacement filters and how they differ from color filters by changing pixel locations rather than colors. It then outlines the framework used to implement the filters, which involves creating an array to store new pixel locations and applying those offsets. Several example filters are described, including offset, random jitter, swirl, sphere, time warp, moire, water, and pixellate filters. The document concludes by stating that the examples demonstrate what can be done with a displacement filter framework and can serve as a starting point for other explorations.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 20

Image Processing for Displacement filters, including swirl

Introduction This project displacement filters most of the information image processing is similar to the changing an image by changing the color values of pixels. Instead the filters we are looking at today change an image by changing each pixels location. Writing code to resize images the answer was that the last article explains bilinear filtering, a way of moving pixels so they are drawn to a theoretical location between physical pixels. Once again we will start by implementing a frame work which we can use to create filters. Our basic approach will be to create a two dimensional array of points. The array will be the size of the image, and each point will store the new location for the pixel at that index. We will do this two ways, one that stores a relative location, and one that stores an absolute location. Finally, we will create our own point struct, which contains two doubles instead of ints, which we will use to write the implementation to performs the bilinear filtering. Arrays in C# I must admit I had not done anything with 2D arrays in C# before this, and they are very cool. The code looks like this: Point [,] pt = new Point[nWidth, nHeight]; This creates a 2D array dynamically, and we can access the pixels using notation like pt[2, 3], instead of the C++ pt[2][3]. Not only is this much neater than C++, but a

Point[,] is a valid parameter to pass into a function, making it a snap to pass around arrays of size unknown at compile time. Offset Filter The first helper function we will write will take a relative location, so for example if we want to move pixel 2, 4 to location 5, 2, then pt[2, 4] will equal 3, -2. We could use Set/GetPixel to do this, but we will continue to use direct access, which is probably faster. As we must now span an arbitrary number of rows to access pixels from anywhere in the image, we will do so by using the Stride member of the BitmapData, which we can multiply by our Y value to get the number of rows down. Then our X value is multiplied by 3, because we are using 3 bytes per pixel ( 24 bit ) as our format. The code looks like this: Collapse public static bool OffsetFilter(Bitmap b, Point[,] offset ) { Bitmap bSrc = (Bitmap)b.Clone();

// GDI+ still lies to us - the return format is BGR, NOT RGB. BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

int scanline = bmData.Stride;

System.IntPtr Scan0 = bmData.Scan0; System.IntPtr SrcScan0 = bmSrc.Scan0;

unsafe { byte * p = (byte *)(void *)Scan0; byte * pSrc = (byte *)(void *)SrcScan0;

int nOffset = bmData.Stride - b.Width*3; int nWidth = b.Width; int nHeight = b.Height;

int xOffset, yOffset;

for(int y=0;y < nHeight;++y) { for(int x=0; x < nWidth; ++x ) { xOffset = offset[x,y].X; yOffset = offset[x,y].Y;

p[0] = pSrc[((y+yOffset) * scanline) + ((x+xOffset) * 3)]; p[1] = pSrc[((y+yOffset) * scanline) + ((x+xOffset) * 3) + 1]; p[2] = pSrc[((y+yOffset) * scanline) + ((x+xOffset) * 3) + 2];

p += 3; } p += nOffset; } }

b.UnlockBits(bmData); bSrc.UnlockBits(bmSrc);

return true; } You'll notice that the framework is there for a boolean success code, but it's not really used. The OffsetFilterAbs does pretty much the same thing, except that if we want to move any pixel to location 3, 2, the point stored for that location will be 3, 2 and not an offset. OffsetFilterAntiAlias is much more complex because it implements a bilinear filter, if you don't understand that code, refer to the previous [^]article. Now, the filters

The basic format then for all the filters is to create an array, populate it with values ( either offset or absolute ) and then pass the bitmap and the array to the appropriate function. There is a lot of trigonometry going on in quite a few of these, which I am not going to discuss in any great detail, instead focusing on what the filter does, and it's parameters. Flip I guess the most obvious thing to do if we're going to move pixels around is flip the image. I'll show the code for this one as it is a simple example, which will highlight the underlying process more so than later examples such as swirl. The end result is obvious, so I won't slow your bandwidth with an example. public static bool Flip(Bitmap b, bool bHorz, bool bVert) { Point [,] ptFlip = new Point[b.Width,b.Height];

int nWidth = b.Width; int nHeight = b.Height;

for (int x = 0; x < nWidth; ++x) for (int y = 0; y < nHeight; ++y) { ptFlip[x, y].X = (bHorz) ? nWidth - (x+1) : x; ptFlip[x,y].Y = (bVert) ? nHeight - (y + 1) : y;

OffsetFilterAbs(b, ptFlip);

return true; } RandomJitter This filter takes a number and moves each pixel by a random amount that is within the bounds of that number. This is surprisingly effective, doing it multiple times ends up with quite an effective oil painting effect.

Swirl This filter was my personal holy grail, and the impetus for my coming up with this stuff. Basically it starts in the middle, and moves around in a circle, increasing the radius as it also increases the degree of rotation. As a result of using trig, it benefits greatly from the bilinear filter which is an option. I will show both the normal, then the bilinear filtered example for this image, then all others that offer the filter, I will show with the filter on. The parameter that is passed in is a very small number, for the example it is .05.

Sphere The sphere filter is one example of a filter created through playing around. I was trying for the effect of the image being wrapped around a ball. I don't think it works that well, but it is interesting and a starting point for such an idea.

Time Warp Another interesting filter, this one causes the image the warp as it disappears in the distance. The example uses a factor of 15.

Moire While playing with the swirl idea, I discovered that if I increased the rate at which the radius moved out, I could either get a wide swirl, or with the right parameters, a moire effect was produced. The example uses a factor of 3.

Water A more useful filter is one that makes things appear to be underwater. This could be improved by the addition of extra artifacts, such as rings and ripples. In effect this filter passes a sin wave through the water in both x and y directions.

Pixellate This is an example of a filter which can be done generically but would be better done with specific code. Pixellation is a way of referring to the fact that when an image is enlarged, curves become blocky. This filter provides a mosaic effect by creating blocks that are the same colour as their top left corner, and can also draw lines to mark the individual tiles. A better implementation would use the average colour present within the block in question, as opposed to the top left corner, but this still works quite well.

Conclusion The filters provided are designed to show some of the things you can do with a displacement framework, and to provide a variety of samples from which you can

derive your own filters. I hope you find the examples useful, and the framework a good starting point for your own explorations of the underlying concept. I hope next to demonstrate writing of a specific one-off filter, and to discuss how this is always the most flexible approach, although transformation matrices and displacement techniques are an excellent way of establishing rough ideas and implementing general concepts. SYSTEM IMPLEMENTATION 5.1 REQUIREMENT ANALYSIS The completion of this thesis requires the following Software & Hardware Software Requirements Hardware Requirements PROCESSOR RAM SECONDARY STORAGE MOUSE 5.2 SOFTWARE DESCRIPTION Microsoft.NET Framework Microsoft made the specifications for .net development platform freely available for the compiler vendors in the form of common language specification (CLS). The common language specifications provide the specifications for a language to compile into a common platform. The compiler vendors must design the compiler in such a way that the compiled code conforms these specifications. These compilers compile the programs written in the high level language into a format called intermediate language format. Pentium IV 1 MB Logitech 32 MB

High Level Language


Common Language Function

Compiler

Intermediate Language format

This IL code format is not the machine language code. So, in order to execute the program we need to compile it again into machine language.This is done by the Common Language Functions(CLR). The Just-in-time compiler(JIT compiler) of th CLR takes the IL code as input and Compiles it and executes it.

Source Code

Compiler

IL Format

CLR

A Sample view of .NET Framework

Source Code in C#

DLL in

.NET C# Compiler

IL Format (C.DLL)

CLR

C#.NET framework Microsoft .NET The Microsoft .NET software developers list can br downloaded from Microsoft official website. It contains the following: Compiler for C#

Common Language Runtime CLR Debugger .Net base classes Some utilities

C# Base Classes : A significant part of the power of the .Net framework comes from the base classes supplied by microsoft as part of the .NET framework. These classes are all callable from C# and provide the bind of basic functionality that is needed by many applications to perform, amongst other things, basic system, windows, and The types of purposes you can use the base classes to do include String handling Arrays, lists,maps etc., Accessing files and the file system Accessing the registry Security Windowing Windows messages Database access [14] Visual C# .NET 2003 is the modern, innovative programming language and tool for building .NET-connected software for Microsoft Windows, the Web, and a wide range of devices. With syntax that resembles C++, a flexible integrated development environment (IDE), and the capability to build solutions across a variety of platforms and devices, Visual C# .NET 2003 significantly eases the development .

of .NET-connected software. Visual C# .NET builds on a strong C++ heritage. Immediately familiar to C++ and Java developers, C# is a modern and intuitive object-oriented programming language that offers significant improvements, including a unified type system, "unsafe" code for maximum developer control, and powerful new language constructs easily understood by most developers. Developers can take advantage of an innovative component-oriented language with inherent support for properties, indexers, delegates, versioning, operator overloading, and custom attributes. With XML comments, C# developers can produce useful source code documentation. An advanced inheritance model enables developers to reuse their code from within any programming language that supports .NET. C# developers can join the newest, fastest-growing developer community, in which they can exchange code and resources, leverage skills across multiple computing environments, and contribute to the standardization process that ensures vibrant and active community participation. With a superior IDE, Visual C# .NET provides users with the ultimate developer environment, bringing together the development community and valuable online resources. The Start Page offers developers a one-click portal to updates, preferences, information on recently used projects, and the MSDN Online community. Improved IntelliSense, the Toolbox, and the Task List provide significant productivity enhancements, while AutoHide windows and multiple-monitor support help programmers maximize screen real estate and customize their development

environment. New custom build rules make developing robust and powerful software easier than ever. Using the Web Forms Designer and XML Designer, developers can use IntelliSense features and tag completion or the WYSIWYG editor for drag-and-drop authoring to build interactive Web applications. With a few simple steps, programmers can design, develop, debug, and deploy powerful XML Web services that reduce development time by encapsulating business processes accessible from any platform. With Visual C# .NET 2003, developers can take advantage of Microsoft .NET and incorporate next-generation technology for resource management, unified types, and remoting. With Microsoft .NET, developers gain superior memory management technology for seamless garbage collection and reduced program complexity. Developers can use the Microsoft .NET Framework Common Type System to leverage code written in any of more than 20 languages that support .NET, while making efficient remote procedure calls. Developers can also use the tested and proven .NET Framework class library to gain powerful built-in functionality, including a rich set of collection classes, networking support, multithreading support, string and regular expression classes, and broad support for XML, XML schemas, XML namespaces, XSLT, XPath, and SOAP. And, with the Java Language Conversion Assistant (JLCA), programmers can begin migrating their Java-based projects to the Microsoft .NET environment. Using Visual C# .NET 2003, developers can construct powerful Web services that encapsulate business processes and make them available to applications running

on any platform. Developers can easily incorporate any number of Web services that are catalogued and available in many independent Universal Description, Discovery, and Integration (UDDI) directories, providing a strong foundation of services and business logic for their applications. Visual C# .NET 2003 also enables developers to build the next generation of Windows-based applications. With visual inheritance, developers can greatly simplify the creation of Windows-based applications by centralizing in parent forms the common logic and user interface for their entire solution. Using control anchoring and docking, programmers can build resizable forms automatically, while the in-place menu editor enables developers to visually author menus directly from within the Forms Designer. Visual C# .NET 2003 is a modern, innovative programming language and tool for building .NET-connected software for Microsoft Windows, the Web, and a wide range of devices. With familiar C++-like syntax, a flexible integrated development environment (IDE), and the capability to build solutions across a variety of platforms and devices, Visual C# .NET 2003 significantly eases the development of .NETconnected software. Visual C# .NET provides users with a superior developer environment, bringing together the development community and valuable online resources. The Start Page offers developers a one-click portal to updates, preferences, information on recently used projects, and the MSDN Online community. Improved IntelliSense, the Toolbox, and the Task List provide significant productivity enhancements, while AutoHide windows and multiple-monitor support help programmers maximize screen

real estate and customize their development environment. With Visual C# .NET 2003, developers can take advantage of Microsoft .NET and incorporate next-generation technology for resource management, unified types, and remoting. With Microsoft .NET, developers gain superior memory management technology for seamless garbage collection and reduced program complexity. Developers can use the Microsoft .NET Framework Common Type System to leverage code written in any of more than 20 languages that support .NET, while making efficient remote procedure calls.

You might also like