Generate heatmap using canvas in WPF - c#

I want to know how can I generate a heatmap on a canvas in WPF (.NET)
I have an array of points (coordinates) with the color intensity, with these data I want to create something similar to this
But, I found that there is no tutorial or library to generate them on a canvas..

I am very sorry, but you have it wrong. WPF canvas is a sandbox for higher level objects, not points. So there are rectangles, circles, ellipses, lines, polylines etc, but more you put in, slower it gets. Now an image like an heat map could use tens of thousands points or even millions of points and that would be a pretty bad idea to play with it directly in canvas. For this kind manipulation, you need pixels to play with and it means special kind of container, like WritableImage. Please look on the link.
This kind container/class is capable manipulate efficiently with pixels, and that is the way it should be done.
Please note, that there are multiple kinds of bitmap containers for WPF.

Related

WPF Fastdrawing for Audio visualation

As part of my audio libary i would like to create a sample visualisations.
I know how I get the values I want to draw like fft results and so on.
But the main problem is that I don t know whats the best way to draw them. I have quite a lot of experience in using wpf but I never had to do something like this. What should I use to keep performance as good as possible?
There are a number of different approaches you can take, depending on the quality you need, memory usage, and performance....here are just some.
create a new object derived from FrameworkElement, and then inside draw the "visual" aspect dynamically by drawing onto a DrawingContext during OnRender. Drawings have a much lower overhead than other WPF elements such as Shapes, Image, etc. However, it still may not scale well if you have 1000s of elements. http://msdn.microsoft.com/en-us/library/ms751619.aspx
WriteableBitmapEx....it will give you the drawing primitives you need to write into a Bitmap directly. http://writeablebitmapex.codeplex.com/ .. see this for some demos which are spookily similar to what you would do for an audio visualization. http://blogs.claritycon.com/blog/2011/03/advanced-animation-animating-15000-visuals-in-silverlight-2/
use DirectX with Direct2D. This offers DirectX like performance, but you would need to use COM interop or C++/CLI code wrappers to make it available to your .NET C# code. http://www.codeproject.com/Articles/113991/Using-Direct2D-with-WPF
Some other links:
http://jeremiahmorrill.wordpress.com/2011/02/14/a-critical-deep-dive-into-the-wpf-rendering-system/

2D images to 3D view

I need to be able to generate a 3D perspective from a bunch of 2D images of a pipe.
Basically... We have written software that interprets combined data from laser and sonar units to give us an image slice from a section of pipe. These units travel through the pipe and scan the inside of the pipe every 100mm.
All of this is working great. My client now wants to take all these 2D image slices and generate a 3D view so they can "travel" through the pipe looking at defects etc.. that are picked up by the scans. We can see the defects in the 2D images but there can be hundreds of images in a single inspection - hence the requirement to be able to look through the pipe.
I am doing this in VS2010 on the .NET 4 platform in C#.
I am honestly clueless as to where to start here. I am not a graphics developer so this is all new territory to me. I see it as a great challenge but need some help kicking off - and a bit of direction.
Any help appreciated :)
Mike
Well, every 10cm isn't very detailed.. However, you need to scan the pixels of the pipe, creating a list of closed polygons, then just use a trianglestrip to connect one set to the next, all the way down the pipe.
Try to start with very basic 2d instead of full blown 3d rendering - may be good enough. Pipe when you look at it from inside can be represented as several trapeze. Assuming your images are small cylinder portions of a pipe - map each stripe to trapezoids (4 would be good start - easy to position) and draw than in circular pattern. You may draw several stripes this way at the same time. To move back/forward - just reassign images to trapezoids.
If you need full 3d - consider if WPF would work, if not - XNA or some OpenGL library will give you full 3d.
You don't specify the context, 100mm sample intervals may be sparse (a 1m pipe) or detailed (10km pipe). Nor do you specify how many sample points there are (number of cross sections and size of cross section image).
A simple way to show the data is to use voxels where each pixel on a cross section is treated as a cube and adjacent samples form adjacent cubes (think Minecraft). The result will look blocky but as it's an engineering / scientific application this is probably preferable. Interpolating the model to produce a smooth surface may hide defects or make areas appear to be defective. Also, rendering a cross section through a voxel is a bit easier than a polygon surface.

search for shapes in BMP image file

I have an image processing question, using C#.
Say I have some schematic diagrams in BMP format, the diagram contains component shapes which are connected to each other.
I wrote a simple program to detect square shapes in the diagram as one component, and record the location of it. However, the next level is to detect more complicated shapes like a few arcs joined together. Note that these shapes can be different sizes in the image. Does anyone know any good method of doing it? without downloading any library (this is my limitation now).
After detecting the shapes, I also need to record which shape is connected to which, so later on, I can redraw them. I have one week to do this, so thanks a lot for any help!!
I'm using C#.
Have a look at this paper. My understanding of their approach:
Detect edges
Detect corners by looking for perpendicular edges
Detect polygons by looking for groups of corners
Detect circles using Hough transform
This is a fairly difficult research problem. Even with a powerful computer vision library like OpenCV, implementing an effective solution within 1 week would be a demanding task.
Have you taken a look at using EmguCV? It is an open-source C# wrapper of OpenCV. It also has a shape detection sample you might interested in.
To answer an old post I had, I have done what I needed to do in 2 weeks time, it worked well. I actually ended up using different algorithms for different shapes. The algorithms are a bit self inventions, but a good method I want to mention is that get the histogram and then use projection on different axis helped a lot.

How to select, display and save regions of a graphic?

So here's the situation: I need to take a (user-specified) graphic, and allow the user to define and label regions within that graphic. For example, if you uploaded a picture of a face, you might want to define "right eye", "left eye", "nose" etc. Also, having defined the regions, if I select a previously defined region, it should be highlighted on the image somehow. These regions are (obviously) not necessarily rectangular, and they cannot overlap. And if you click within a defined region in the graphic, I would be able to identify which region was clicked on.
There are a couple ways I can think of for doing this, none of which are quite satisfactory. Another developer before me tried doing it with a transparent grid overlaid on the original graphic, fiddling with the background alpha/color for highlighting regions, but I think they rather kludged it. I could either get my hands really dirty trying to clean up their code, or try a completely new approach.
What would you suggest for maximum speed and user-friendliness?
Bounty added: for the best solution that will get me up and running in the minimum time.
The GraphicsPath class is made to do this. Keep a list of them along with the image. Draw the image first, then Graphics.DrawPath() to draw the regions on top of the image.
Hit testing is simple with GraphicsPath.IsVisible(). Iterate the list in reverse order so overlaps work.
Assuming you haven't decided yet on the technology you'll use, I'd suggest WPF; I find most graphics-related tasks easier with WPF (at least in version 4) and it's specifically geared for interactivity, so creating non-rectangular regions using mouse clicks and hit-testing clicks to select shapes would be pretty easy. Loading images is also easy.
However, if you haven't used WPF or Silverlight until now, there is some overhead in learning the basic concepts and APIs; so I'm afraid there's no real way I can recommend it as a maximum speed solution without knowing your (or whoever's will be working on it) competencies. That said, using MVVM and WPF would be definitely the maximum speed solution for me. Also the maximum user-friendliness since WPF enables quite interesting interaction models out-of-the-box, like multi-touch support (that's the trendy one that should be mentioned, right?) and easy non-standard layout and placement of controls.
You need polygons, saved as list of points. And you need hit testing for them. See the link:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/40ebadc1-6154-4c7c-9cb1-d608a426b29c

Finding Sub-Images in a image

I have a fairly simple situation. I just don't know any specific terms to search for.
I have a single image, in that image I have several other images that follow a basic pattern.
They are rectangles and will possibly have landmark image to base things off of.
An important part, is that I need to detect rotated/mis-scaled sub-images.
Basically what I need to be able to do is split 'business cards' from a single image into properly aligned single images.
As I am also designing the cards to be scanned I can put in whatever symbol or something that would make detection easier (as I said a landmark)
If your example is representative (which I doubt for some reason) then Hough transform is your friend (google it, there are plenty of explanations and code around). With it you'll be able to detect the rectangles.
Some examples of Hough transform in C# are http://www.koders.com/csharp/fid3A88BC1FF95FCA9D6A182698263A40EE7883CF26.aspx and http://www.shedletsky.com/hough/index.html
If what actually happens is that you scan some cards, and you have some control over the process, then I'd suggest that you ensure there is no overlap between cards, and provide a contrasting background (something very different from the cards). Then any edge-detection will get you close enough to what you've drawn in your example, and after that you can use Hough transform.
Alternatively, you can implement the paper http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.59.4239 which uses Hough transform to detect rectangles directly, without edge detection.
If I did not understand your problem, or you need clarifications, please edit your question further and post a comment on this answer.
Try AForge.NET (if you are using C#). It has DocumentSkewChecker which will calculate the angle of rotated image.
You can try ExhaustiveTemplateMatching class of AForge.Net

Categories

Resources