Click here to Skip to main content
15,886,519 members
Home / Discussions / C#
   

C#

 
GeneralRe: help me in c# Pin
Killzone DeathMan16-May-12 0:27
Killzone DeathMan16-May-12 0:27 
GeneralRe: help me in c# Pin
Pete O'Hanlon16-May-12 0:27
mvePete O'Hanlon16-May-12 0:27 
GeneralRe: help me in c# Pin
ri198716-May-12 0:57
ri198716-May-12 0:57 
GeneralRe: help me in c# Pin
Dave Kreskowiak16-May-12 1:38
mveDave Kreskowiak16-May-12 1:38 
GeneralRe: help me in c# Pin
Pete O'Hanlon16-May-12 1:43
mvePete O'Hanlon16-May-12 1:43 
GeneralRe: help me in c# Pin
Dave Kreskowiak16-May-12 7:59
mveDave Kreskowiak16-May-12 7:59 
GeneralRe: help me in c# Pin
Pete O'Hanlon16-May-12 1:41
mvePete O'Hanlon16-May-12 1:41 
Questionhelp me Pin
ri198715-May-12 23:35
ri198715-May-12 23:35 
i have a multi programs in c# that does not execute plz help me,,,i want to know the error in this programs
first:
/* SIFT.cs
* The SIFT algorithm class
* where all the algorithm specific methods
* are implemented
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
class SIFT
{ static double initDev = 1.6; // initial standard deviation variable
static public int OctavesCount = 2; // Octaves count for pyramid
static public int scalesPerOctave = 4; // scales(blurred images) count per octave
static double minDoG = 0.01; // minimal threshold of keypoint value
static public double norm; // normalization factor for kp coordinates
static double edgeRatio = 10; // minimal edge ratio for kp localization
public static double[][,] BuildGaussianBlurPyramid(Bitmap image) // method to build the Gaussian pyramid with bitmap input
{ int ind=1; // index variable to help for image indexing in pyramid
int imgCount = scalesPerOctave * OctavesCount; // calculate total image count
double deviation = initDev; // local initial deviation variable
double[][,] imgMatrix=new double[imgCount][,]; // array to store values of each image matrix in the pyramid
imgMatrix[0]=new double[image.Width,image.Height]; // image matrix initial dimension
imgMatrix[0]=ImageProcessing.BitmapToGrayscaleMatrix(image); // create grayscale image matrix from bitmap coloured image
for (int i = 0; i < OctavesCount; i++){
for (int j = 1; j < scalesPerOctave; j++){ // Build Gaussian blur with given image mtrx and deviation
imgMatrix[ind]=ImageProcessing.GaussianBlurBWMat(imgMatrix[ind-1], deviation);
deviation *= 2; // double the previous deviation
ind++; // increment current image index
}
if (ind<imgcount-1) check="" for="" current="" image="" index="" and="" build="" next="" octave
="" imgmatrix[ind]="ImageProcessing.SubSample(imgMatrix[ind-2]);" down-sample="" the="" by="" factor="" of="" 2="" octave=""
="" deviation="" =="" 3.2;="" divide="" to="" start="" from="" twice="" initial
="" ind++;="" increment="" index
="" }
="" return="" imgmatrix;="" resulting="" matrix="" pyramid="" array
="" }="" method="" dog="" pyramid
="" public="" static="" double[][,]="" builddogpyramid(double[][,]="" gaussianpyr)="" {="" int="" ind="0;" value="" controlling="" indxes="" resdog="new" double[(scalesperoctave="" -="" 1)="" *="" octavescount][,];
="" (int="" i="0;" <="" gaussianpyr.getlength(0)="" 1;="" +="1){
" if="" ((i="" %="" (scalesperoctave)="=" 0){="" go="" continue;
="" calculate="" matrix
="" resdog[ind]="ImageProcessing.CalculateDoGMatrix(gaussianPyr[i]," gaussianpyr[i="" 1]);
="" }

="" resdog;="" arraylist="" findkeypoints(double[][,]="" imgmatrixpyr)="" find="" keypoints
="" kpl="new" arraylist();="" create="" store="" double[][][,]="" imgmatrix="new" double[2][][,];="" array="" three="" level="" pyr="" img="" norm="3.0" (initdev="" 2);="" normalization="" factor
="" dogcount="(scalesPerOctave" octavescount;="" count="" total="" number="" images="" imgmatrix[0]="new" double[3][,];="" first="" imgmatrix[1]="new" second="" pyrl="0;" layer="" pyrim="0;" in="" layer
="" dogcount;="" i++){="" (i="=" 3){
="" pyrl++;="" assign="" zero="" dimension="" imgmatrix[pyrl][pyrim]="imgMatrixPyr[i];" copy="" pyr.="" 1="" dim="" dim.
="" pyrim++;="" min="1," max="1;" initialization
="" l="0;" imgmatrix.getlength(0);="" l++){
="" y="1;" imgmatrix[l][1].getlength(1)="" y++)
="" x="1;" imgmatrix[l][1].getlength(0)="" x++){
="" double="" point="imgMatrix[l][1][x," y];="" pick="" one="" central="" (math.abs(point)="" keypoint="" threshold
="" imgmatrix[l].getlength(0);="" i++){
="" maximum="" (max="=" &="" imgmatrix[l][i][x="" 1,="" 1]="" y]="" imgmatrix[l][i][x,="" point){
="" else="" minimum
="" (min="="> point & imgMatrix[l][i][x - 1, y] > point &
imgMatrix[l][i][x, y - 1] > point & imgMatrix[l][i][x, y] >= point & imgMatrix[l][i][x + 1, y + 1] > point &
imgMatrix[l][i][x + 1, y] > point & imgMatrix[l][i][x, y + 1] > point & imgMatrix[l][i][x - 1, y + 1] > point &
imgMatrix[l][i][x + 1, y - 1] > point){
min = 1; }
else min = 0;
}
if (max == 1 || min == 1){ // check if the point is max or min
Keypoint kp = new Keypoint(); // create keypoint object to
kp.x = x; // assign x coordinate of extreme point
kp.y = y; // assign y coordinate of extreme point
kp.value = point; // assign extreme point value
kp.layer = l; // assign layer of extreme point
KpL.Add(kp); } // add keypoint to arraylist
min = 1; max = 1; // reinitialize min and max values
}
}
return KpL; // return keypoint list
}
// method to localize keypoints for the given edge ratio
public static ArrayList KeypointLocalization(ArrayList initKpList, double[][,] DoGMatrix, int edgeRatio)
{ Keypoint initKp; // Keypoint object to store initial keypoints
ArrayList retKp = new ArrayList(); // create Arraylist to store refined keypoints
double Dxx, Dyy, Dxy, Trace, Det; // variables to store elements, trace and Det. of Hessian
double r = ((edgeRatio + 1) * (edgeRatio + 1)) / 2; // calculate the threshold from the edgratio
for (int i = 0; i < initKpList.Count; i++){
initKp = (Keypoint)initKpList[i]; // cast the value from Arraylist object to the Keypoint
int l = initKp.layer == 0 ? 1 : 4; // identify the current layer
if (initKp.x <= 0 || initKp.y <= 0 || // drop keypoints which are on the borders
initKp.x >= DoGMatrix[l].GetLength(0) - 1
|| initKp.y >= DoGMatrix[l].GetLength(0) - 1)
continue;
Dxx = DoGMatrix[l][initKp.x + 1, initKp.y] // calculate the x,x derivative by pixel differences
+ DoGMatrix[l][initKp.x - 1, initKp.y]
- 2.0 * DoGMatrix[l][initKp.x, initKp.y];
Dyy = DoGMatrix[l][initKp.x, initKp.y + 1] //calculate the y,y derivative by pixel differences
+ DoGMatrix[l][initKp.x, initKp.y - 1]
- 2.0 * DoGMatrix[l][initKp.x, initKp.y];
Dxy = 0.25 * ((DoGMatrix[l][initKp.x + 1, initKp.y + 1] // calculate the x,y derivative by pixel differences
- DoGMatrix[l][initKp.x + 1, initKp.y - 1]) -
(DoGMatrix[l][initKp.x - 1, initKp.y + 1]
- DoGMatrix[l][initKp.x - 1, initKp.y - 1]));
Trace = Dxx + Dyy; // calculate the trace of Hessian
Det = Dxx * Dyy - (Dxy * Dxy); // calculate the determinant of Hessian
if ((Trace * Trace) / Det > r) // drop the keypoints which contradict the given ratio
continue;
else
retKp.Add(initKp); // add the remaining keypoints
}
return retKp; // return the resulting Arraylist with localized keypoints
}
// method for orientation assignment
public static ArrayList AssignOrientations(ArrayList finKpList, double[][,] blurredMatrix)
{ Keypoint finKp; // keypoint variable to store localized keyoints
ArrayList orKp=new ArrayList(); // create arraylist to store keypoints with orientations
double binVal = 2 * Math.PI / 36; // calculate the angle value of one histogram bin
for (int i = 0; i < finKpList.Count; i++){
finKp = (Keypoint)finKpList[i]; // cast from array list object to keypoint object
finKp.scale = initDev*(finKp.layer + 1); // caclulate the keypoint scale
double[] histBin = new double[36]; // create the double array as a colour histogram
int kpReg=(int)(1.5*finKp.scale/2+0.5); // calculate the radius of the region around the keypoint
double SigmaFact=2*2.25*finKp.scale*finKp.scale; // caclutate the sigma factor for gaussian weight
int layer=finKp.layer==0?1:5; // identify the current keypoint layer
int regXSt=finKp.x-kpReg<1?1:finKp.x-kpReg; // calculate the x coordinate of the region start and end
int regXEnd = finKp.x + kpReg > blurredMatrix[layer].GetLength(0) ? blurredMatrix[layer].GetLength(0) : finKp.x + kpReg;
int regYSt = finKp.y - kpReg < 1 ? 1 : finKp.y - kpReg; // calculate the x coordinate of the region start and end
int regYEnd = finKp.y + kpReg > blurredMatrix[layer].GetLength(1) ? blurredMatrix[layer].GetLength(1) : finKp.y + kpReg;
for (int y=regYSt; y<regyend; y++)
="" for="" (int="" x="regXSt;" x<regxend;="" x++){="" calculate="" the="" gaussian="" wight=""
="" double="" gaussianwight="Math.Exp(-(Math.Pow(x" -="" finkp.x,="" 2)="" +="" math.pow(y="" finkp.y,="" sigmafact));
="" portion="" of="" direction="" angle="" in="" histogram
="" portinhist="(CalMagnitudeAndDirection(x,y," blurredmatrix[layer]).direction="" math.pi)="" (2="" *="" math.pi);
="" identify="" bin="" index="" current="" keypoint="" int="" ind="(int)(portInHist" 36="=" ?="" 0="" :="" 36);="" add="" magnitude="" weightened="" by="" to="" respective="" bin
="" histbin[ind]+="CalMagnitudeAndDirection(x,y,blurredMatrix[layer]).magnitude*gaussianWight;
" }
="" max="0.0;" initialize="" maximal="" value
="" maxbin="0;" index
="" bi="0;" <="" histbin.getlength(0);="" ++bi){
="" if="" (histbin[bi]=""> max){ // check if the next bin is bigger
max = histBin[bi]; // store new bin as the maximal
maxBin = bi; } // mark the new bin index as the index of the maximal bin
}
max = maxBin * binVal - Math.PI; // change angle range from [0, 2PI] to [-PI,PI]
max=max<-Math.PI?2*Math.PI+max:max; // check if angle is outside [-PI,PI]
max = max > Math.PI ? max - 2 * Math.PI : max; // check if angle is outside [-PI,PI]
finKp.orientation = max; // assign maximal bin direction as keypoint orientation
orKp.Add(finKp); // add keypoint with assign orientation
}
return orKp; // return keypoint list of keypoints with their orientations
}
// method to calculate keypoint magnitude and direction
static KpOrientPar CalMagnitudeAndDirection(int x, int y, double[,] blurredMatrix)
{ KpOrientPar kpO=new KpOrientPar(); // create orientation object for magnitude and direction pair
// calculate the keypoint magnitude by pixel differences
kpO.magnitude = Math.Sqrt (Math.Pow (blurredMatrix[x + 1, y] - blurredMatrix[x - 1, y], 2.0) +
Math.Pow (blurredMatrix[x, y + 1] - blurredMatrix[x, y - 1], 2.0));
// calculate the keypoint direction by pixel differences
kpO.direction = Math.Atan2(blurredMatrix[x, y + 1] - blurredMatrix[x, y - 1],
blurredMatrix[x + 1, y] - blurredMatrix[x - 1, y]);
return kpO; // return orientation object with magnitude and direction
}
public static ArrayList CreateDescriptor(ArrayList finKpList, double[][,] blurredMatrix)
{ int kpReg = 16; // region size around the keypoint
Keypoint finKp; // keypoint object to store input keypoint
ArrayList descKp=new ArrayList(); // arraylist keypoint to store descriptor assigned keypoints
double SigmaFact = 2*(kpReg / 2) * (kpReg / 2); // calculate the sigma factor for gaussian weight
for (int kpi = 0; kpi < finKpList.Count; kpi++){
finKp = (Keypoint)finKpList[kpi]; // cast from arraylist object to keypoint object
int regXSt = finKp.x - kpReg < 1 ? 1 : finKp.x - kpReg; // calculate x coordinate of keypoint region start
int regYSt = finKp.y - kpReg < 1 ? 1 : finKp.y - kpReg; // calculate y coordinate of keypoint region start
int regXEnd = regXSt + 4; // calculate x coordinate of keypoint region end
int regYEnd = regXSt + 4; // calculate y coordinate of keypoint region end
double[,][] desc = new double[4, 4][]; // create double array to store descriptor
for (int jj = 0; jj < 4; jj++)
for (int ii = 0; ii < 4; ii++ )
desc[ii,jj] = new double[8]; // initialize double array of descriptor
int layer = finKp.layer == 0 ? 1 : 5;
for (int i = 0; i <= 3; i++)
for (int j =0 ; j <= 3; j++)
for (int xi = regXSt; xi < regXEnd; xi++)
for (int yi = regYSt; yi < regYEnd; yi++){ // calculate current value of x and y coordinates
int x =xi+j*4 >= blurredMatrix[layer].GetLength(0)-1 ? blurredMatrix[layer].GetLength(0)-2 : xi+j*4;
int y = yi+i*4 >= blurredMatrix[layer].GetLength(1)-1 ? blurredMatrix[layer].GetLength(1)-2 : yi+i*4;
double yRot = Math.Sin(-finKp.orientation) * (x - finKp.x) +
Math.Cos(-finKp.orientation) * (y - finKp.y); // rotate x coordinate by keypoint orientation value
double xRot = Math.Cos(-finKp.orientation) * (x - finKp.x) -
Math.Sin(-finKp.orientation) * (y - finKp.y); // rotate y coordinate by keypoint orientation value
// calculate gaussian weight
double gaussianWight = Math.Exp(-(Math.Pow(xRot, 2) + Math.Pow(yRot, 2) / SigmaFact));
// calculate direction and rotate by keypoint orientation
double direction = CalMagnitudeAndDirection(x, y, blurredMatrix[layer]).direction - finKp.orientation;
if (direction < 0) // check if direction degree is out of [0,2PI] range
direction += 2.0 * Math.PI;
else if (direction > 2.0 * Math.PI)
direction -= 2.0 * Math.PI;
double portInHist = direction / (2 * Math.PI); // calculate the protion of the direction in the histogram
// idetify the index of orientation bin
int ind = (int)(portInHist * 8 == 8 ? 0 : portInHist * 8);
// add magn. weighted by gaussian to the resp.direction bin
desc[i, j][ind] += CalMagnitudeAndDirection(x, y, blurredMatrix[layer]).magnitude * gaussianWight;
}
finKp.descriptor=desc; // assign descriptor to keypoint object
descKp.Add(finKp); // add keypoint to the resulting arraylist object
}
return descKp; // return arraylist of keypoints with descriptors
}
}
class KpOrientPar // helper class to store magnitude and direction
{
public double magnitude; // double variable to store keypoint magnitude
public double direction; // double variable to store keypoint direction
}
AnswerRe: help me Pin
Pete O'Hanlon15-May-12 23:47
mvePete O'Hanlon15-May-12 23:47 
GeneralRe: help me Pin
ri198716-May-12 0:07
ri198716-May-12 0:07 
GeneralRe: help me Pin
ri198716-May-12 0:09
ri198716-May-12 0:09 
GeneralRe: help me Pin
Killzone DeathMan16-May-12 0:23
Killzone DeathMan16-May-12 0:23 
Questiondefines Pin
columbos1492715-May-12 22:42
columbos1492715-May-12 22:42 
AnswerRe: defines Pin
Pete O'Hanlon15-May-12 22:52
mvePete O'Hanlon15-May-12 22:52 
AnswerRe: defines Pin
Andy41115-May-12 23:29
Andy41115-May-12 23:29 
AnswerRe: defines Pin
PIEBALDconsult16-May-12 3:29
mvePIEBALDconsult16-May-12 3:29 
QuestionUpdate database SQL via C# Pin
jojoba201115-May-12 22:32
jojoba201115-May-12 22:32 
AnswerRe: Update database SQL via C# Pin
Pete O'Hanlon15-May-12 23:21
mvePete O'Hanlon15-May-12 23:21 
QuestionRe: Update database SQL via C# Pin
jojoba201116-May-12 5:52
jojoba201116-May-12 5:52 
AnswerRe: Update database SQL via C# Pin
Pete O'Hanlon16-May-12 6:04
mvePete O'Hanlon16-May-12 6:04 
AnswerRe: Update database SQL via C# Pin
Dave Kreskowiak16-May-12 7:17
mveDave Kreskowiak16-May-12 7:17 
QuestionProject Ideas Pin
solomon20115-May-12 20:12
solomon20115-May-12 20:12 
AnswerRe: Project Ideas Pin
Mycroft Holmes15-May-12 21:22
professionalMycroft Holmes15-May-12 21:22 
Question......... Pin
Qismet15-May-12 19:38
Qismet15-May-12 19:38 
AnswerRe: HOW USE GMap.NET.WindowsForms EXE FILE IN MY PROJECT Pin
Mycroft Holmes15-May-12 21:19
professionalMycroft Holmes15-May-12 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.