I need an advice in image processing. I have WF application coded in C# which finds me a coordinates by given parameters and based on this coordinates I would like to crop the image to a circle and unfold this circle to a rectangle.
So just to summarize my questions - How should I correctly crop the image in pictureBox to a circle (ellipse) image and how to unfold this circle to a rectangle?
I hope I described my problem well and I will be very grateful for every advice about how should I continue.
I guess you want the image to be cropped to a circle and then have that circle expand to a rectangle?
This would be the way to do it:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip.aspx
You then just animate the EllipseGeometry to make it bigger than the image and then maybe remove the clip if you like.
Related
I started from EMGU Example (Emgu.CV v2.4.10.1939):
http://www.emgu.com/wiki/index.php/CompareImages_-_Difference
Instead of comparing previous video frame and the next one I am dealing with a screen capture of the primary screen at time1 and another screen capture at time2. Second screen capture brings a minimal difference, especially in one part of the captured image and that is: an outline (closed polygon of n vertices). I applied ThresholdBinary method and this code:
Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
to get the shape of the difference (which for me is a white polygon)
I then cropped that polygon to avoid processing unnecessary parts of the image.
In the attached images on the right I tried to depict what I want and don't want based on processing left input image.
I want to find x,y coordinates (in pixels) of all intersections of vertices of the polygon for the cropped image.
When I would later redraw the polygon I would expect to as close match as possible to this input polygon. I would like to have a reasonable number of straight lines detected so the final shape faithfully resembles input shape on the left.
This is a similar question that didn't have a solution.
Find contour of the set of points in OpenCV
My Idea or Project:
I want to develop an application which takes an image as input and returns another image as output.
For example: I have a bitmap image with a circle drawn inside it. What i want to develop is an algorithm that will draw another circle inside it. I know this is rather easy but it should work for any kind of starting image like a triangle or any other shape.
According to me, I have to go through the shape's inside-periphery and draw a line.
However, I am having problems with dynamic shapes. The problem is easy for circles, elipses and rectangles as we know the algorithm but becomes hard for any other shape.
Any thoughts as to how I can achieve this? If I can get tangent line on a particular point of the curve then I could also do what I need.
I want to know how to remove part of a Texture from a Texture2D.
I have a simple game in which I want to blow up a planet piece by piece, when a bullet hits it "digs" into the planet.
The physics are already working but I am stuck on how to cut the texture properly.
I need to create a function that takes a Texture2D a position and a radius as input and returns the new Texture2D.
Here is an example of the Texture2D before and after what I want to accomplish.
http://img513.imageshack.us/img513/6749/redplanet512examplesmal.png
Also note that i drew a thin brown border around the crater hole. If this is possible it would be a great bonus.
After doing alot of googling on the subject it seems the best and fastest way to achieve the effect i want is to use pixel shaders.
More specifically a shader method called 'Alpha mapping'. Alpha mapping is done by using the original texture and another greyscale texture that defines what parts are visible or not.
The idea of the shader is to go through each pixel in the original texture and check how black each pixel in the greyscale image is at the same coordinate. The blacker the pixel in the greyscale picture is the higher the alpha value (more visible) the pixel in the original texture becomes. Since all this is done on the GPU it is lightning fast and leaves the CPU ready to do the actual logic for the game.
For my example I will create a black image to use as my greyscale image and then draw white circles on this corresponding to the parts i want to remove.
I've found a MSDN examples with working source code for XNA 4 that does this (the cat example):
http://create.msdn.com/en-US/education/catalog/sample/sprite_effects
EDIT:
I got this to work quite nicely. Created a small tutorial with source code here: http://syntaxwarriors.com/2012/xna-alpha-mapping-with-pixel-shaders/
A good way of doing this is to render a "hole texture" using alphablend on top of your planet texture. Think of it like drawing an invisibility circle over your original texture.
Take a look at this thread for a few nice links worms-style-destructible-terrain.
To achieve your brown edges I'd guess you'd need to take a similar approach. First render the hole to your terrain with say radius 10px. Then you render another circle from the same origin point but with a slightly larger radius, say 12px. You'd then need to set this circle to a blendmode that results in a brown color.
look at my class here:
http://www.codeproject.com/Articles/328894/XNA-Sprite-Class-with-useful-methods
1.Simply create an object of Sprite class for your planet
Sprite PlanetSprite = new Sprite(PlanetTexture2D , new Vector2(//yourPlanet.X, //yourPlanet.Y));
2.when the bullet hits the planet, make a circle texure2d by the center of collision point using "GetCollisionPoint(Sprite b)" method
-you can have a Circle.png with transparent corners
-or you can create a Circle using math(which is better if you want to have bullet power)
3.then create an Sprite object of your circle
4.now use the "GetCollisionArea(Sprite b)" to get the overlapped area
5.now use the "ChangeBatchPixelColor(List pixels, Color color)" where pixels is the overlapped area and color is Color.FromNonPremultiplied(0, 0, 0, 0)
-note you don't need to draw your circle at all, after using it you can destroy it, or leave it for further use
I have an image on which I may use a ScaleTransform to increase the image size by 25%. I also have a rectangle which sits on top of the image highlighting a particular area. When I scale the image I want the rectangle to scale as well and highlight the same area as before. Scaling the rectangle itself isn't the issue, it's getting the rectangle into the correct position so that it highlights the same area. How do I do this? Is there a mathematical formula of some description that can be used to calculate its correct position?
Apply the same scaling factor to the X and Y offsets of the rectangle.
Any idea how to do it? I am drawing a rectangle that is supposed to be a half-transparent window. I managed to do the transparency by drawing a half-transparent texture, but I also want to blur whatever is under the window.
Normally (eg. using GDI) I would create a bitmap of the area, blur it and paint it as the background of my window. With Direct3D I don't even know how to get the area with whatever is already rendered on it. Or even there can be a different approach, can't it. Please help.
The D3D way is to use a pixel shader to "blur" the area underneath your rect.
This link shows you how to use a pixel shader in C#.
And this link has a guassian blur pixel shader.
It DOES require having your backbuffer as a texture. You can then render the whole thing to a NEW texture and blur the relevant part before putting your semi-trans window over the new texture.
Edit: AFAIK you can't use the Draw function inside a shader. You will need to write your own sprite renderer. The Begin and Draw set up a whole load of states that will break your usage of a vertex shader.