How to Extract Front Shape in an Image in C# - c#

Is it possible to Extract any Shape that's in front of an image?
let's say we have an image of two objects 1 in front, the other is behind and a blank or transparent background.
can we extract the one in front and place it in a new image?
can this be done by detecting edge of frontal shape and then crop it?
This article is doing something near to my question :
Cropping Particular Region In Image Using C#
but i want to do it fully automated.
any help would be highly appreciated.
Thanks in advance.

I think you cannot do this fully automated; however, there are maybe some semi-automated ways, at least, you need some prior information such as how far your object can be placed. Here are some of my suggestions.
First way(you have experience in implementing academic papers, you have some prior information about depth of object's place),
Download a "scene - depth images database" from internet
Get the average value of database
Query K-Nearest-Neighbors of input image according to GISt of scene[1]
Apply SIFT flow to align database scenes according to input scene
Infer the depth
Remove a certain range from image.
It's possible to infer rough depth map of an input image. By using this, you'll try to infer depth map of input image then remove the certain depth range which includes your object. You can check the paper[2] for more detailed explanation.
Example Depth Map from http://www.the.me/wp-content/uploads/2013/09/z-depth_map_expanding_exif_more_powerful_post-processing_2n.jpg
Second way(assumption: human input is allowed at the end of algorithm.),
- Segment the image(you can find state of the art algorithm with a little search)
- Select the contour that you want to remove.
Example Segmented Image from http://vision.ece.ucsb.edu/segmentation/edgeflow/images/garden_edge.gif
References:
[1]Aude Oliva
Gist of the Scene
[2]Karsch, K.; Liu, C.; Kang, S.B.
IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI), 2014.

OpenCV gives option for to extract contours of the objects. So convert your image to gray scale and given to the open CV , detect all the contours in your images. and from that select contours which will be required for your requirement.
Since your project is on C# you can take a look of Emgu CV which is a cross platform .Net wrapper for OpenCV. Pl. refer to the below url where you can download the examples for Emgu CV.
http://sourceforge.net/projects/emguexample/?source=recommended

Related

Is it possible to create isosurfaces using Oxyplot?

I'm using Oxyplot HeatMapSeries for representing some graphical data.
For a new application I need to represent the data with isosurfaces, something looking like this:
Some ideas around this:
I know the ContourSeries can do the isolines, but I can't find any option that allows me to fill the gaps between lines. Does this option exists?
I know the HeatMapSeries can be shown under the contourSeries so I can get a similar result but it does not fit our needs. .
Another option wolud be limiting the HeatMapSeries colours and eliminate the interpolation. Is this possible?
If anyone has another approach to the solution I will hear it!
Thanks in advance!
I'm evaluating whether Oxyplot will meet my needs and this question interests me... from looking at the ContourSeries source code, it appears to be only for finding and rendering the contour lines, but not filling the area between the lines. Looking at AreaSeries, I don't think you could just feed it contours because it is expecting two sets of points which when the ends are connected create a simple closed polygon. The best guess I have is "rasterizing" your data so that you round each data point to the nearest contour level, then plot the heatmap of that rasterized data under the contour. The ContourSeries appears to calculate a level step that does 20 levels across the data by default.
My shortcut for doing the rasterizing based on a step value is to divide the data by the level step you want, then truncate the number with Math.Floor.
Looking at HeatMapSeries, it looks like you can possibly try to turn interpolation off, use a HeatMapRenderMethod.Rectangles render method, or supply a LinearColorAxis with fewer steps and let the rendering do the rasterization perhaps? The Palettes available for a LinearColorAxis can be seen in the OxyPalettes source: BlueWhiteRed31, Hot64, Hue64, BlackWhiteRed, BlueWhiteRed, Cool, Gray, Hot, Hue, HueDistinct, Jet, and Rainbow.
I'm not currently in a position to run OxyPlot to test things, but I figured I would share what I could glean from the source code and limited documentation.

How does template matching work?

I have an array of pixels and I would like to search through it to see if there is a specific template.
But I am unsure how to start - for each pixel run the search for the template image? I cannot imagine how it could work if e.g. First 5 pixels match and the sixth does not, should it move back to second pixel and start over> Also I assume some kind of tolerance must be there.
You can take a look at the Accord.NET Extensions library which implements fast template matching algorithm along with some samples.
Fast template matching algorithm:
Gradient Response Maps for Real-Time Detection of Textureless Objects
Link
The library:
https://github.com/dajuric/accord-net-extensions
source:
https://github.com/dajuric/accord-net-extensions/tree/master/Source/ImageProcessing/FastTemplateMatching
There is an example too.

Calculating the Area of the Hand using Depth Data

Using a Kinect sensor, I am attempting to write an algorithm to detect a clenched fist. I am trying to achieve this by calculating the area occupied by the hand (since clenched fist area < non-clenched fist area).
Here's what I have so far:
Depth information per pixel (from the DepthStream)
Location of the Hand (from the SkeletonStream)
I am having trouble figuring out how to get the depth data that corresponds to the hand. It's easy to get the depth data at the exact location that the Kinect gives for the hand, but I don't know how to get all the depth data for the hand. Any suggestions, pseudocode, and/or link to tutorials would help.
There are events from KinectInteractions that detect whenever the fist is in gripped mode or released mode as it's used for the KinectScrollViewer in the KinectRegion:
The HandPointGrip event
The HandPointGripReleased event
Also this might be a duplicate of this post .
I am not experienced in this field but found this in my search. See if it helps you: https://groups.google.com/forum/#!topic/openni-dev/Kj2JL6K0PBw

How to implement smoothing in frequency domain?

I want to do smoothing to an image in the frequency domain. when i use google to see any articles it gave some Matlab codes which i don't need. i could do FFT to an image but i don't know how to implement any smoothing techniques(ILPF, BLPF, IHPF, BHPF) in frequency domain. if you can provide any code samples for any of the above techniques WITHOUT using any image processing libraries it will be really helpful and C# is preferred.
Thanks,
Could you define what you mean by 'smoothing in the frequency domain'? You can generate a spectrum image using FFT and multiply the image by some function to attenuate particular frequencies, then convert the spectrum back to an image using the inverse-FFT. However, for this kind of filtering (multiplication by some scaling function in frequency), you can achieve the same result more quickly by convolving with the dual function in the spatial domain.
In any case, if you wish to implement this yourself, read up on FFT (the fast Fourier transform) and convolution. You might also check out a signal processing textbook, if you're interested, as the theory behind discrete filtering is fairly deep. The algorithms won't make a whole lot of sense without that theory, though you can certainly apply them without understanding them.
If you want to implement your own DSP algorithms, check out this book online. In particular, Ch 33 describes the math and algorithm behind Butterworth filter design. Ch 12 describes how to implement FFT.
There is a great series on Code Project by Christian Graus which you might find useful, especially part 2 which deals amongst others with smoothing filters:
Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters
Image Processing for Dummies with C# and GDI+ Part 2 - Convolution Filters
Image Processing for Dummies with C# and GDI+ Part 3 - Edge Detection Filters
Image Processing for Dummies with C# and GDI+ Part 4 - Bilinear Filters and Resizing
Image Processing for Dummies with C# and GDI+ Part 5 - Displacement filters, including swirl
Image Processing for Dummies with C# and GDI+ Part 6 - The HSL color space
Keshan, it is simple. Imagine the FFT is another two pictures where low frequencies lie in the middle and high frequencies away from the middle. If the pixels are numbered from -w/2 to w/2 and -h/2 to h/2 you can simply measure the distance from the middle as a(x,y)=sqrt(x^2+y^2). Then take some arbitrary monotonic decreasing function like f(x)=1/(1+x) and multiply each point in the fft with f(a(x,y)). Then transform back using the FFT.
There are different choices for f(x) which will look different. For example a gaussian function or bessel or whatever. I did this for my undergrad and it was great fun. If you send me a mail I will send you my program :-).
One bit caveat is the ordering in output of the fft. The arrays it generates can be ordered in weird ways. It is important that you find out which array index corresponds to which x/y-position in the "analytical" fourier transform!
For all image/signal processing I recommend OpenCV.
This has a managed C# wrapper: Emgu.
http://www.emgu.com/wiki/index.php/Main_Page

filter pornography in a video/picture c# library

How can you filter pornography in a video/picture?
Is there a library I can use? Commercial or open source is OK.
For Video:
You would analyze the sound waves from the video. If there's lot of grunting and moans, find a way to recognize those patterns and label it as porn. However, you might get false tags for women's tennis match.
For Image:
Build a simulation model of a human brain which signals arousal from viewing erotic pictures. Some paramters would be excessive curves, and image recognition of the human anatomy. This is far more difficult.
If it is not a real-time, you could use Amazon's Mechanical Turk to do the work. You'll have to pay the workforce, but it's a very cheap way to get menial jobs like this done.
See, Porn Detection is not a very easy.
But there is surely a range of color that identifies the human skin. And you need to make a threshold of the color to identify the picture as porn. Say you take it as 70 %, so you go through all the pixel on the current screen and determine whether 70% of the pixels comes within the range of human skin color.
There is already few algorithm prepared for Face detection like :
http://www.codeproject.com/KB/cs/Face_Detection_processing.aspx
I hope this would help you to find a way on your point.

Categories