-1
Hallo Ich schreibe Code für Hough Transformation und der Akku-Speicherplatz wird am Programm angezeigt, aber ich weiß nicht, was falsch mit meinem Code. Bitte HilfeHough Transform-Code für die Schule
public Image<Rgb, Byte> houghTransform(Image<Gray, Byte> input)
{
int width = input.Width, height = input.Height;
//1. create accumulator space
double MaxRho = Math.Sqrt(((width/2) * (width/2)) + ((height/2) * (height/2)));
double MaxTheta = Math.PI * 2;
int[,] accumulator = new int[width * 2,height*2];
for (int i=0;i< width;i++)
for (int j = 0; j < height; j++)
{
accumulator[i, j] = 0;
}
//2. Loop for point in image
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
if (input.Data[j, i, 0] == 0) //0 for black, 255 for white
{
for (int k = 0; k < height; k++)
{
double rho = ((double)(i - (width/2)) * Math.Cos((MaxTheta/height) * (double)k)) + ((double)(j - (height/2)) * Math.Sin((MaxTheta/height) * (double)k));
int newRho = (int)((rho/MaxRho) * width);
if(newRho >= 0 && newRho < width) accumulator[newRho, k]++;
}
}
int maxima = 0;
for (int i = 0; i < width; i++)
for (int j = 0; j < height * 2; j++)
{
if (accumulator[i, j] > maxima)
{ maxima = accumulator[i, j]; }
}
//3. Tresholding the acc
for (int i = 0; i < width; i++)
for (int j = 0; j < height ; j++)
{
int temp = 0;
if(maxima!=0) temp = (accumulator[i, j]/maxima) * 255;
accumulator[i, j] = (byte)temp;
}
//4. Save to Image<Gray, Byte>
Image<Rgb, Byte> output = new Image<Rgb, Byte>((int)width, height*2);
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
{
output.Data[j, i, 0] = (byte)accumulator[i, j];
output.Data[j, i, 1] = (byte)accumulator[i, j];
output.Data[j, i, 2] = (byte)accumulator[i, j];
}
return output;
}
Testing Ergebnis: Mein Akku hat nur 4 Punkte
Was ich erwarte:
Gibt es Fehler? –
gibt es keinen Fehler –
[codereview.se] ist der beste Ort für die Überprüfung von Codes. Wenn Sie wirklich Debugging-Probleme (nicht funktionierende Codes) haben, erklären Sie es im Detail. –