c# - How to cut triangle from image? - c#

I use C# in my work.
I want to render a border with different weigths on its sides.
Like this:
This pictures are from browser, I want to draw corners the same way.
May be the best and the simplest way to implement it is to cut corners from borders at specified angle, like this:
but I have no idea how to cut triangles from image using c# drawing API, and, unfortunately, google doesn't help with this task, there is information only about cropping rectangles.
Any help greatly appreciated.

You could use GraphicsPath for this. Define a path of a number of points (a shape) and perform garphics operations on it just like it was a rectanble.

Related

Find image within image (object detection)

I do have different images which all have some kind of border around the "real" image. What I would like to achieve is to find the "real" image (size and location in pixels).
For me the challenge is that the border is not always black (can be any kind of black or grey with a lot of noise) and the "real" image (water with shark in this example) can have any combination of color, saturation, ...
Now in general I'm aware of algorithms like Canny, Blob detection, hough lines, ..., but I have just started using them. So far I managed to find the border for a specific image, but as soon as I try to apply the same algorithms and parameters to the next image it doesn't work. My current approach looks like this (pseudo code):
convert to gray CvInvoke.CvtColor(_processedImage, tempMat, CvEnum.ColorConversion.Rgb2Gray)
downsample with CvInvoke.PyrDown(srcImage, targetImage) and CvInvoke.PyrUp(srcImage, targetImage)
blur image with CvInvoke.GaussianBlur(_processedImage, bluredImage, New Drawing.Size(5, 5), 0)
Binarize with CvInvoke.Threshold(_processedImage, blackWhiteImage, _parameters.BinarizeThreshold, 255, CvEnum.ThresholdType.Binary)
Detect Edges with CvInvoke.Canny(_processedImage, imgEdges, 60, 100)
Find Contours with CvInvoke.FindContours(_processedImage, contours, Nothing, CvEnum.RetrType.External, CvEnum.ChainApproxMethod.ChainApproxSimple)
Assume that largest contour is the real image
I already tried different approaches based on for example:
Thresholding saturation channel and bounding box
Thresholding, canny edge and finding contours
Any hint especially on how to find proper parameters (that apply for all images) for algorithms like (adaptive) threshold and canny as well as ideas for improving the processing pipeline would be highly appreciated.
you can try to subtract black image from this image , and you will get the inside image , way to do this:
Use image subtraction to compare images in C# ,
If the border was uniform, this would be easy. Use cv::reduce to find MIN and MAX of each row and column; then count the top,left,bottom,right rows/columns whose MIN and MAX are equal (or very close) to the pixel value in a nearby corner. For sanity, maybe check the border colour is the same on all sides.
In your example the border contains faint red stuff, but a row/column approach might still be a useful way to simplify the problem. Maybe, as Nofar suggests, take an absolute difference with what you think is the background colour; square it, convert to grey, then reduce to Sums of rows and columns. You still need to find edges, but have reduced the data from two dimensions to one.
If there's a large border and lots of noise, maybe iterate: in the second pass, exclude the rows you think comprise the border, from statistics on columns (and vice versa).
EDIT: The above only works for an upright rectangle! If it could be rotated then the row/column projection method won't work. In that case I might go for sum-of-squared differences as above (don't start by converting to grey as it could throw away information), followed by blurring or some morphology, edge detection then some kind of Hough transform to find straight edges.

OpenCV C# - Detecting simple object in static image

I have no experience with images. I have to detect simple object in static image. For example I have image like:
I want to detect edges and remove background. Just to compare them.
Something like this.
Do u have any solutions of this problem? Images have often white backgrounds.
I've just thought about detect edges, and take everything what they contains.
To segment out the shoe-
Anadptive Threshold to remove the smooth changing background.
Sobelx, which removes the apparent background line, which i assume is
common for images of this setup.
dilate, closing operation to separate out the shoe.
Find contours, bounding box etc as per your choice.
Do an additional threshold if you want to remove the shadow at the bottom.

Plot Point in ZedGraph C#?

Well this is my question, I have a ZedGraph, now I want to put some points in the ZedGraph, I have my simple class Point wich it have, the X & Y values, fist I check this question, but not answered, at the moment don't work, anyone know how to put just a simple point, my goal is drawing shapes like this one Secciones but I dont know how make this
I believe ZedGraph is the wrong tool for what you want to achieve. You should be using GDI+ drawing do draw your points, lines, rectangles and other shapes. It forms part of C#.NET.

Find then hide drawn shape in image?

This may seem like a strange question, but I have a set of pictures I want to use as a fading screen saver, and I want each picture to have an accompanying quote, but each quote will be in a different place, relative to the picture.
Rather than coding a Rectangle for the area of each image, it would be easier just to draw a rectangle in the image, and have it drawn in there.
Now, the drawn shape would be a stark, uniform coloured border (lime green, for instance) because the colour doesn't appear in the pictures, and it would be on a solid coloured background, like black for instance.
My question is: If I draw a lime green rectangle on each image, how could I then, using C#, find that rectangle in the image, get the dimensions of it, and replace the lime green with the background colour, so in the end product, it'd look like the shape was never there to begin with?
I have not tried anything, I have no code to show, because it's an idea I had and though I'm sure it must be possible, I don't even know what to start searching for.
I hope this is possible, if it isn't, then I'll just draw a rectangle for each one, but that's a last resort. :)
Have you thought about using either the emgucv or aforge libraries? They are able to detect shapes in images quite easily. Though they don't detect edges perfectly, if all you want to detect is a rectangle, either one should work well.
Here are two tutorials on shape detection for emgu cv and aforge. Once you have the shape detected, then you can easily cut it out for the background. Say, for example, that you used the aforge Detection of quadrilaterals (in the link), then you could easily get the rectangles position and size by the calling of blobs[i].Rectangle; and create a rectangle with same size and position with picture background color.
If you need more clarification please feel free to comment. Nice idea!

Any way to snap animated TranslateTransform to pixel grid?

Is there any way to snap animated TranslateTransform to pixel grid?
There is a very bad jittering, when moving text using animation. I guess it's because of subpixel positioning. I need to avoid this jittering. Suggest possible ways.
It sounds like you want TextOptions.TextHintingMode="Animated" in your XAML. See http://msdn.microsoft.com/en-us/library/system.windows.media.textoptions.texthintingmode(v=VS.95).aspx for more details.
Dave Relyea posted an article on how to implement a pixel snapping control in Silverlight. This is a control which listens to the LayoutUpdated event to perform pixel snapping on child elements. Perhaps this is what you're looking for; hopefully without too much modification :)
Why won't you render thit text to WritableBitmap like this:
WriteableBitmap wb = new WriteableBitmap(textToTranslate, null);
Then place this bitmap into Image and translate image instead?
What are you trying to do exactly? Do pixel snapping using drag'n'drop? If so, you just could call the method that does the translate if the coordinate is a multiple of a certain number.
A small example of what you are trying to do would also be helpful.

Categories