Aug
13
2009
0

C# equivalent to VB val() function

Although VB had it’s limitations, it was damn easy to filter an input string for a numerical value.

Here is how to do it in C#. You’ll need to use System.Text.RegularExpressions in the header

private static int VBVal(string sInput)
{
        string sOutput = string.Empty;
        MatchCollection oMatches = Regex.Matches(sInput, "\\d+");
        foreach (Match oMatch in oMatches)
        {
                sOutput += oMatch.ToString();
        }
        return (int)sOutput;
}
Written by John in: C# Tips |
Mar
27
2009
0

Image Editing in C# – Contrast

When attempting to get machines to process images you sometimes run into noise problems. Filters are regularly applied first to clean them up.

Editing the contrast of an image changes its dynamic range. In its most basic form, it will move pixel values away from the center (normally 128 if using 8 bits per color).

There are many different ways to to perform contrast adjustment.
(more…)

Written by John in: C# Tips |
Mar
23
2009
0

Image Editing in C# – Greyscale

I’m in the process of writing some code to detect the stars in astromical images. One of the filters I need to apply to an image is to convert it to greyscale.

Conversion to greyscale is relatively straightforward – The red, green and blue values of a pixel all need to be set to the same value.

There is one caveat, and that is that our eyes are sensitive to different colors. This means that color images tend to have lots of blue and red when compared to green.
(more…)

Written by John in: C# Tips |
Mar
13
2009
2

TLEs – Calculation of the Julian Day Number (JDN)

This post is part of a series on understanding the meaning behind the values contained in a Two Line Element set, or Keplerian Elements. The main article is here.

Calculation of the Julian Day Number (JDN)

Julian day numbers are regularly used in astronomy instead of a date.

Julian day numbers are simply the count of days that have elapse since noon on January 1, 4713 BC Greenwich time using the Julian proleptic calendar.
(more…)

Written by John in: Astronomy,C# Tips |
Mar
10
2009
5

Code: Shortest distance between any two line segments

I recently needed to find the shortest distance between any two line segments in 3D space.

I managed to find some C++ code online at http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm which I converted to C#.

It’s fairly easy to use. If you only need it for 2D space, just set the Z values to 0.

Please post a comment if you find this useful.
(more…)

Written by John in: C# Tips |
Jan
29
2009
2

SHA256 and higher in SQL Server

As part of a new project I’m doing, I needed to use hashes.

A good source of information on hashes is available from wikipedia.

SQL has the built in function HASHBYTES but this only supports up to the SHA128 algorithm and I want to use SHA256.

I created myself a CLR in C#.net and in some moment of feeling generous, decided to share the code.

(more…)

Written by John in: C# Tips,SQL Tips,Tips |