I am designing an WPF application which renders data as a 500x500 8-bit indexed image at 10 frames per second using WriteableBitmap.
We would like to add some real-time image processing algorithms to our output, such as 2-D median filtering, gaussian blur or moving average, which are computationaly power hungry.
Did anyone try to use WPF pixel shaders to do such tasks ?
Would a platform-specific image processing library be efficient ? (e.g. Intel IPP ?)
Or would a DirectX based custom renderer be the solution ?
Any tip would be much welcome. At the moment everything is computed within our .NET application and I believe there is room for optimization.
Thank you for your help,
Best Regards,
Romain
If your data is purely for display I would recommend using pixel shaders. The other two options you suggest both require interop with unmanaged code which adds complexity.
Related
I've got an application where I am processing images from a camera at around 20Hz. Each image is segmented into a matrix of regions, let's say 100 x 50 (for example). Each region is processed, resulting in a single floating point metric. I'm trying to create simple 2d plot for each region's data as it is created. So, on the screen would be a matrix layout of 500 (in this worse case example) plots/charts.
I'm currently processing the images without issue using managedCUDA and writing some CUDA kernels to take care of that. What I'm faced with now is trying to create a way to logically view all this data has it's coming in. Things I've considered:
Building an "image" on the gpu with dimensions matching the target display control. This image would be segmented into the appropriate number of regions and a rudimentary chart would be drawn, pixel by pixel.
Learn Direct3D or OpenGL and code the algorithms necessary to draw the charts
Use the native WPF capabilities to draw the charts myself.
Use a commercial or open-source charting tool
Option 1 seems crazy to me (but I had a gpu-centric friend suggest it).
Option 2 seems like I'd have to learn all the unnessary 3D overhead of D3D or OpenGL just to draw 2D plots.
Option 3 and 4 probably have the most appeal to me, but I'm worried about performance.
So just looking for advice before I charge off in one of these directions.
I thoroughly recommend SciChart if you have the money. We develop scientific software that need to process large amounts of data being received from external devices, and have found SciChart to be excellent (features and performance). And no I'm not affiliated to them in any way!
Like all charting components it takes a while to get your head around the many features, but it's worth it. If you download their trial it includes a load of samples, including demos of real-time performance.
I'm designing a game and thinking about using WPF for making a simple prototype of the basic gameplay.
Is it possible to render basic 2d-graphics in WPF in real-time? By basic graphics I mean simple shapes such as lines, circles, etc. By "real-time" I mean things are rendered based on parameters such as velocity, acceleration, etc. that changes depending on player input - which I assume means I can't use storyboards for the animations.
Thanks
Check out the previous question High Performance Graphics using the WPF Visual Layer for a good related discussion. While WPF provides a great framework for rich vector graphics, it lacks somewhat for real-time 2D performance.
There are workarounds, for instance, depending on your scene complexity you may get away with using DrawingVisuals or virtualized Shape classes (WPF Vector graphics) to draw your sprites. Going a little lower level, you could cache sprites using the BitmapCache mode available in .NET4.0, or pre-prendering them to Bitmaps and using various optimization patterns to improve throughput.
Going lower level still, you can mix Vector/Raster graphics using the fantantastic WriteableBitmapEx project, or Vector/GPU graphics using the D3DImage.
Regarding how to update your scene, you'll need to write a primitive game engine where on the CompositionTarget.Rendering event (fired on redraw of the screen) you get the updated parameters and compute positions/orientations of your sprites. Something that might help with this is this great codeplex project which integrates WPF/Silverlight and Farseer physics.
I am trying to create a WPF based application which will allows users to edit photos and provide features like:
Increase/Decrease Brightness
Crop
Retro looks
and lot more.
I am also looking forward to provide more fancy features like : Framing an image, print to a Tshirt, but these are low on priority.
Any open source libraries for that?
P.S -> This is a POC project, even if i miss some features it will be fine.
I would suggest you to use BitmapEffects available in WPF, the BitmapEffects make use Shading language; at present very few effects available in .net Fx. But it is quite easy create your own shaders to adjust the birghtness, gamma, colour saturation, and they can be data bound too. The great thing about shaders is you apply them to videos as well.
Shazzam Tool is on of the best tool to create shadders, it lets you try the effect on your images and generate the C# or VB.Net binding code to use in WPF/Silverlight.
I guess you have to write code to do the image cropping, or quick Google search would help.
Opensource shader effects available here in codeplex.
For a low-level library that allows GDI like operations on bitmaps please see the WriteableBitmapEx library. This is open source and as a disclaimer, I have made a minor contribution to it.
WriteableBitmapEx has functions for drawing shapes, lines, ellipses, applying filters (via matrices, e.g. convolution blur etc), rotation, resize and cropping. You would have to write your own code to apply framing but this could be done by rendering to a separate bitmap and using the Blit function.
Above all its very fast and portable, to WP7 and Silverlight!
Best regards,
When should we use images (jpg, png) and when should we use XAML in an application.
Image
+ "easy" for the designer to create what he wants
+ are displayed the same on every computer
- fixed resolution
XAML
+ vector format (resolution independent, resize able, ...)
+ can be animated
+/- rendered by the client
- not as many effects available as for images or are really complex to create
- complex visual tree
I could not find any source, that compares the resource usage (CPU, RAM) between images and XAML.
I personally think everything should be XAML, but I don't want to have an application that is slow as hell. Are there any good performance guidelines for using XAML drawings?
Researching this I've read that you should have everything in XAML and then use RenderTargetBitmap to create static images on demand, but according to this article it will cause the window to be rendered without hardware acceleration. So I'm wondering if it is really an improvement for performance. Ignoring the fact that it is much more work for the coder.
From your comment:-
I am only talking about the cases where image and xaml is interchangeable
Use a PNG, period. Only use Xaml based imagery when you actually need the advantages it provides. There may be some edge case exceptions, for example, a large image that can be composed from a couple of simple paths in Xaml. However you would also have to have a good reason to believe that any performance difference is appreciable and worth eliminating. Ultimately favor simplicity over complexity when the same results are achievable from both.
If your artist/designer can create vector graphics and there are no complex gradients, then I would prefer vector graphics. You get all advantages and no disadvantages.
And if you are concerned about complex visual trees, then WPF offers bitmap caching specifically for these kind of cases.
I'm working on a diagnostic tool and receives data every 25 ms. I need this data to be drawn in my chart using a lineSeries. I'm using a a wpf chart with a lineSeries which I bind in xaml to an ObservebleCollection.
The problem is that I need the collection needs to contain atleast 1600 datapoints before starting to remove them at the front.
I understand that 25 ms is a short tiem then it comes to drawing in wpf. Dose anyone have any solution to my problem?
Regards
You should check out SciChart, which can handle data updates at 1ms. It renders like a game-loop, so only draws when new data is appended and the UI thread is free. Some more information at www.scichart.com/wpf-chart-features which shows the features and talks about performance.
Disclosure: It's my own component, so ask any questions if you have them!
I'd suggest you use a custom made drawing routine utilizing WritebleBitmap instead of shapes and draw your lines in a fixed area one segment at a time without any scrolling. The, when you reach 1600 points at the right side of your plot area, start over. Maybe some visual indicator (like vertical line or something) would help perception.
I don't think there any charting libraries targeted at updating 1600 point line every 25ms.
I have a .NET application that charts many measurements on a 33ms interval. I tested a number of charting solutions to accomplish this task, but the only real viable option I found was Arction LightningChart (http://www.arction.com). Lightning Chart will do what you want pretty easily, and I think you can get the basic version for free. The downside will be a dependency on DirectX and the SlimDX library. The trial that you can download from the site will give you pretty good examples of how to use this control in WPF and Windows Forms.
Use Microsoft Chart for WinForms using the WindowsFormsHost control. MS-Chart can handle such data rates well. It internally uses the WritableBitmap method, so it is both fast and stable. Also, don't forget to set the series type to FastLine to avoid slowdown.
I've created a "Tip" article on codeproject which tries to highlight this type of high-data volume usage on MS-Chart. You can change the timer interval to even 1 ms. and see that there is no issue in showing the data.
The article is at http://www.codeproject.com/Tips/1006180/Using-Microsoft-Chart-in-WPF