line detection using hough transform - c#

I am working on c# project ,i am using aforge for line detection of particular color in a bmp image by using hough transform.When i am processing the image i get pixel format not supported exception .my images are 24bpprgb and the docs clearly tells the format supported.trying to convert it to the supported formats always ends up in the above exception.Can anyone enlighten me on this...
or can anyone tell me the necessary steps to convert the bmp 's to any of the supported formats using hough transform for line detection

In your case the image must be grayscale (8-bpp).
You can convert it using AForge Grayscale filter and then apply the Hough transform.
You can also take a look at:
https://github.com/dajuric/accord-net-extensions
The library implements generic image (Image) and it is easily convertible to AForge image.
Also it wrapps algorithms (primary for Accord.NET tough - for now).

Related

Loss of brightness/contrast when converting from Image<Gray,float> to Image<Gray,Byte>

We are using OpenCV with Emgu 2.4.9 wrapper.
When we convert the Image<Gray,float> to Image<Gray,Byte> (using convert<Gray,Byte>()), the brightness/contrast is reduced.
We are using Image<Gray,Byte> for display purposes while Image<Gray,float> is used temporarily for processing (e.g. convolution).
However, when Image<Gray,float> is saved as JPEG, I see the required level of intensities/brightness.
When I checked the Image.Save() method, it looks like it finally ends up calling OpenCV imwrite_() function which in turn converts the Float image to byte format: ‘image.convertTo( temp, CV_8U );’
So, I would expect the intensity level to have reduced when Image<Gray,float> is saved to JPEG. But it does not (even though, the same convertTo() method, which in turn calls OpenCV cvt_() function).
But, when the float image converted to Byte and saved the brightness/contrast is reduced.
In both cases, I believe, saturate_cast<> would be called.
Related questions here: Emgu image conversion from Image<Gray,float> to Image<Gray,Byte> results in intensity loss?
Would someone be able to describe what is going on and how to preserve the brightness/intensity when converting from Image<Gray,float> to Image<Gray,Byte>?

emgu c# object tracking moments

well iam trying to make an object tracker i produced the filtered image which is tracking the object and convert it to white i used this to get the filtered image
CvInvoke.cvInRangeS(HSVimg, low, high, THImg);
now iam trying to get the contours and get the center point so i used this (can't test it yet)
using (Image<Gray, Byte> canny = smoothedRedMask.Canny(100.0, 50.0))
using (MemStorage stor = new MemStorage())
{
Contour<Point> contours = canny.FindContours(
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE,
stor);
}
so i have two questions what does canny method do ?
how do i draw a shape around the tracked object then get the center point using moment or any other method ?
u don't have to write code just give me reference to simple code that i can use
The Canny function is the implementation of an edge detection algorithm ,it uses a multi-stage algorithm to detect a wide range of edges in images.
refer to this wikipedia article or this tutorial/code to understand better.
The other part of the question is a bit more tricky as drawing a shape around the tracked object will depend on the quality of the image received after applying the canny edge detection and also the geometry of the object.
So you might want to adjust values of the canny function to suit your needs.
but you can refer to these youtube video tutorials to better understand/code your object tracking logic.
Video 1
Video 2.
Hoping it helps.

Convert png to high quality ico

Maybe this is a very easy problem to solve but I haven't found the perfect solution yet.
I'm trying to convert a png to ico with C# and found the question converting .PNG to .ICO in C/C# which sort of gives a working solution as below:
using (FileStream stream = File.OpenWrite(#"C:\temp\test.ico"))
{
Bitmap bitmap = (Bitmap)Image.FromFile(#"c:\temp\test.png");
Icon.FromHandle(bitmap.GetHicon()).Save(stream);
}
For my own project I have changed this approach slightly to:
string pngFile = "path/to/pngfile";
using (Bitmap bitmap = new Bitmap(pngFile))
{
using (Icon icon = Icon.FromHandle(bitmap.GetHicon()))
{
using (MemoryStream stream = new MemoryStream())
{
icon.Save(stream);
// something interesting with icon here
}
}
}
The problem that I am experiencing is that the resulting ico is of poor quality, I'm guessing it got resized to 16x16 and lost some of it's color depth, perhaps now only has 16 colors? How can I convert to a higher quality ico file?
I believe you will need a more robust method than GetHIcon(). It is more of a "quick and dirty" option, and by no means loss-less.
Here's an example of a class that can preserve image quality on the way to converting as ICO:
https://gist.github.com/darkfall/1656050
Check http://www.codeproject.com/Tips/627823/Fast-and-high-quality-Bitmap-to-icon-converter
This is a clear and fast solution to convert a bitmap to png
In the referenced question the accepted solution uses imagemagick, which is a great image manipulation tool that gives you have the ability to control size, colour depth etc. when converting from png to ico. I would really suggest trying that solution.
Using the imagemagick utility would look something like
convert -resize x16 -gravity center -crop 16x16+0+0 input.png \
-flatten -colors 256 output/favicon.ico
(you could then control -resize and -colors to achieve what you are looking for.)
The same options should be available programmatically in C# through http://imagemagick.codeplex.com

How to add text to images with the CMYK ColorSpace in .NET 4

I am working on a project that at it's core involves adding text to an image, so as an example given a background image (B) and some text in a specified font, point size and font (A) the two are composited together to produce (C):
The eventual result is to go to print with these images, so the backgrounds are using the CMYK Color Space and I need to keep the whole process within CMYK or the colors look wrong when printed. (note: excellent article on Color Spaces and .NET on CodeProject)
I have tried several different ways of compositing these images together:
System.Drawing implicitly converts everything to RGB
System.Windows.Media.Imaging - no compositing methods
System.XAML/WPF - very promising however RenderTargetBitmap does not work in PixelFormats.Cmyk32 (throws an ArgumentException).
I have looked at but not tried third party commercial components as the prices seem to start high and continue going up:
Graphics Mill (~US$1800 as of 12/2010)
Atalasoft DotImage (~US$3300 as of 12/2010)
Is this possible in .NET 4?
Edit:
Because someone else might want to do something slightly different and just convert any format that Windows.System.Media.Imaging is able to load to CMYK here is the code I have used:
var bitmapConverter = new FormatConvertedBitmap();
bitmapConverter.BeginInit();
bitmapConverter.Source = sourceImage;
bitmapConverter.DestinationFormat = PixelFormats.Cmyk32;
bitmapConverter.EndInit();
To clarify the above code converts an image source to CMYK32 (no transparency) however if you are using certain classes (namely RenderTargetBitmap passing the above ImageSource will throw an exception).
If you have looked much on SO, you have probably already seen these links. But, just in case, here are some links that I found that might be helpful to you.
Here is a link from here on SO about working with CMYK in .NET:
Convert RGB color to CMYK?
Specifically it mentions using Color Profiles and Windows Color Management APIs.
Here is another SO link:
How to convert CMYK to RGB programmatically in indesign
One answerer mentions that there is not an exact conversion between CMYK and RGB.
Here is a link about compositing two CMYK images without converting to RGB:
The are any CMYK graphics library?
The answerer suggests using a commercial product that he is affiliated with.

Image Skeletonization using Medial Axis Transform

My requirement is something like this:
Lets take there is a Bitmap with a big letter 'A'.
The Bitmap is two colors (Either Black or White).
I need to skeletonize the big 'A'. (see: http://en.wikipedia.org/wiki/Topological_skeleton)
Using "Medial Axis Transforming" algorithm.
I tried my best in googling but i ended up being lost in finding a C#, C++ or at least pseudo code implementation of this algorithm.
I would like if someone could help me on this.
This page http://www.cs.sunysb.edu/~algorith/files/thinning.shtml has some sources you may wish to review.
The following two articles are the ones where the Medial Axis Transform was first proposed, so I think that you can find the algorithm to implement there. Do not expect a C++/C# implementation though.
A transformation for extracting new descriptors of shape
Shape description using weighted symmetric axis features
For the first one I was able to find a URL to a pdf. For the second one you will have to have access to ScienceDirect to download.
Another approach that you can use to extract the skeleton of a shape is by the Image Foresting Transform (IFT). It consists in representing the binary image as a graph. I made an implementation of the skeletonization by IFT in Matlab using the following article:
Multiscale skeletons by image foresting transform and its applications to neuromorphometry

Categories

Resources