C# Xna interpolate edges on 2d Image like a 1d Graph - c#

I generated some caves with random walk. The problem is that the output is far too small and i want to scale it up about 10-20 times. When i do so every pixel becomes visible so i need some algorithm to solve this. I thought about some sinus or cubic interpolation as it is in 1 dimension, that goes along the edges and interpolates between the centers of the pixels... So basicly the height of each pixel would be the Y axis of the graph. The image itself has only 2 "colors" wich are black and white.
The black dot is the center of each pixel and the red line the Interpolation i would like to archive:
Here is how the whole cave looks like:
Is there a way to realise that? Or is it impossible? I wonder how i could solve it when the caves edge goes back on the X axis, since the graph couldnt have 2 dots for each X.

You can blur or antialias and then posterize to BW again. Basically this is going to smooth the edges, as if you applied an exponential smoothing function.

Related

Unity3D- Is it possible to draw a circle / ellipse based on two vertices using a linerenderer?

I would like to ask if it is possible to generate and draw a circle or ellipse using a linerenderer based on two points in the scene. Specifically, these are the vertices of the mesh. For example, I would like to draw a circle / ellipse around the neck of a given humanoid.
I need something like this:
I need this circle to enlarge and shrink based on the properties of the blendshapes. If I widen the neck with blendshape, I need this circle to enlarge as well. I can draw this circle by finding the id of all the vertices around the neck and entering these vertices into the LineRenderer. But it's a very impractical way that I don't want to use. So I would like to ask if it is possible to draw such a circle that would be connected only to two points and not to all / many.
I will be very grateful for any advice.
EDIT:
I was hoping that it would be enough to connect 4 vertices in the worldspace using LineRenderer, where I would get a drawn square. And I was hoping that some rounding would be used on the edges of this square to create an ellipse or circle. For a better idea, I also added a picture to describe what I thought would be enough to use.

How to create Heatmap of eyetracking points in c# windows forms

I have a database that holds data of eyetracking on some videos.
I export those data to an int[,] input matrix for this issue. And then try to create a heatmap.
What I get so far is something like this:
But this is not actually what I want it to be. I want something like the heatmaps that you see when you google it, e.g.:
Treat each spot as an artificial circle with the center at that spot. A circle that has, say, 50 pixel radius. Now, go over all pixels of the image and for each one count all circles that cover that pixels. This is your score for that pixel. Translate it into color, i.e 0: black/transparent, 10: light green, 20: yelow, and so on. After analyzing all pixels you will get a color for each pixel. Write a bitmap, look at it. It should be something close to what you want.
Of course, circle radius, color mappings, etc, need adjusting to your needs. Also, that's probably not the best/simplest/fastest algorithm.
Different approach would be to store the "heat" in the pixels greyvalue.
Just create a second image with the same size as the original one and count up the greyvalue of a pixel everytime it was looked at.
Later you can use that value to calculate a size and color for the circle you want to draw.
You can then lay the heatmap image on top of the original one and you are done (dont forget to set transparency).

Detecting an objects position and direction inside an image

I am trying to gather a position and a direction of an object inside an image.
The image can look like this for example:
http://i.stack.imgur.com/4ehUy.jpg
The object is shown as a blue circle.
What I've tried so far is using a basic pixel search, but it seems like the circles blue isnt always the same (maybe because of the shapes and the enviroment) and when I give it a color range (e.g. red 130 - 150, green 110 - 120 and blue 90 - 100), it isnt reliable, because sometimes the pixel is recogniced on top of the hole, sometimes on the right site and so on. Further more the next step would be getting the direction of the object, which is even more difficult, because of the enviroment, which can be very similar to the light infront of the object.
Again, what I'd like to know is the current center of the circle and the angle it is aiming atm...
Is there a library or a way to do this? I am using C# / WPF to program my application.
I found a solution on my own:
All you need is the AForge library. With the AForge library you can do some experiments with color filtering (I used a blue) and after some calculations you will get the center position of the player. :)

Cut holes in a Texture2D

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

Detect Rotation of a scanned image in C#

We want a c# solution to correct the scanned image because it is rotated. To solve this problem we must detect the rotation angle first and then rotate the image. This was our first thought for our problem. But then we thought image warping would be more accurate as I think it would make the scanned image like our template. Then we can process it as we know all the coordinates of our template... I searched for a free SDK or a free solution in c#. Helping me in this will be great as it is the last task in our work. Really, thanks for all.
We used the PrimeOCR product to do this. It's not free, but we couldn't find a free program that was comparable.
So, the hard part is to detect the angle of the page.
If you have full control over the template, the simplest way to do this is probably to come up with an easily-detectable symbol (e.g. a solid black circle) and stick 3 of them on the template. Then, detect them (just look for big blocks of pixels with high saturation, in the case of a solid black circle).
So, you'll then have 3 sets of coordinates. If you have a top circle, a left circle, and a right circle with all 3 circles at difference distances from one another, detecting which circle is the top circle should be pretty easy.
Then just call a rotation function. This part is easy and has been done before (e.g. http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate ).
Edit:
I suggested a circle because it's easier to find the center, but a rectangle should work, too.
To be more explicit about how to actually locate the rectangles/circles, take the average Brightness value of every a × a group of pixels. If that value is greater than b, then that a × a group of pixels is part of a rectangle. a and b are varables you'll want to come up with yourself.
Use flood-fill (or, more precisely, Connected Component Labeling) group the resulting pixels together. The end result should give you your rectangles.

Categories