2016-06-12 12 views
0

変換の仕方ビットマップ複合番号?ことを考えるとどのようにしてビットマップオブジェクトを複素数に変換できますか?

 public static COMPLEX [,] BitmapToComplex2D(Bitmap bmp) 
     { 
      COMPLEX[,] comp = new COMPLEX[bmp.Width, bmp.Height]; 

      int [,] array2D = BitmapToArray2D(bmp); 

      for (int i = 0; i <= bmp.Width - 1; i++) 
      { 
       for (int j = 0; j <= bmp.Height - 1; j++) 
       { 
        comp[i,j].RealPart = ???; 
        comp[i,j].ImaginaryPart = ???; 
       } 
      } 

      return comp; 
     } 

...をビットマップに

ビットマップコンバータに2次元配列

public static Bitmap Array2DToBitmap(int[,] image) 
     { 
      int i, j; 
      Bitmap output = new Bitmap(image.GetLength(0), image.GetLength(1)); 
      BitmapData bitmapData1 = output.LockBits(new Rectangle(0, 0, image.GetLength(0), image.GetLength(1)), 
            ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); 
      unsafe 
      { 
       byte* imagePointer1 = (byte*)bitmapData1.Scan0; 
       for (i = 0; i < bitmapData1.Height; i++) 
       { 
        for (j = 0; j < bitmapData1.Width; j++) 
        { 
         imagePointer1[0] = (byte)image[j, i]; 
         imagePointer1[1] = (byte)image[j, i]; 
         imagePointer1[2] = (byte)image[j, i]; 
         imagePointer1[3] = 255; 
         //4 bytes per pixel 
         imagePointer1 += 4; 
        }//end for j 
        //4 bytes per pixel 
        imagePointer1 += (bitmapData1.Stride - (bitmapData1.Width * 4)); 
       }//end for i 
      }//end unsafe 
      output.UnlockBits(bitmapData1); 

      return output;// col; 
     }   

2D複素数は(それは正しいですか?)

 public static Bitmap Complex2DToBitmap(COMPLEX[,] comp) 
     { 
      Bitmap output = new Bitmap(comp.GetLength(0), comp.GetLength(1)); 

      int[,] GreyscaleImage2DArray = new int[output.Width, output.Height]; 

      for (int i = 0; i <= output.Width - 1; i++) 
      { 
       for (int j = 0; j <= output.Height - 1; j++) 
       { 
        GreyscaleImage2DArray[i, j] = (int)comp[i, j].Magnitude(); 
       } 
      } 

      output = ImageConverter.Array2DToBitmap(GreyscaleImage2DArray); 

      return output; 
     } 
+0

'Array2DToBitmap'では' int'を 'byte'にキャストしますが、' image'のすべての値は0と255の間にあるのでしょうか? – Shago

+0

私はグレースケールでしか作業していません。 – anonymous

答えて

0

magnituをencondingする代わりに各複素数Iのdeは、実数部と虚数部を別々の画素に分離して符号化する。

public static Bitmap Complex2DToBitmap(COMPLEX[,] comp) 
{ 
    Bitmap output = new Bitmap(comp.GetLength(0), comp.GetLength(1)); 

    // Double the width for storing real and imaginary parts on different pixels. 
    int[,] GreyscaleImage2DArray = new int[output.Width * 2, output.Height]; 

    // Increase the step to 2, and decrease the limit by 1. 
    for (int i = 0; i <= output.Width - 2; i+=2) 
    { 
     for (int j = 0; j <= output.Height - 1; j++) 
     { 
      // Store RealPart and ImaginaryPart on different pixels. 
      GreyscaleImage2DArray[i, j] = (int)comp[i, j].RealPart; 
      GreyscaleImage2DArray[i+1, j] = (int)comp[i, j].ImaginaryPart; 
     } 
    } 

    output = ImageConverter.Array2DToBitmap(GreyscaleImage2DArray); 

    return output; 
} 

public static COMPLEX [,] BitmapToComplex2D(Bitmap bmp) 
{ 
    // Halve the width, each complex is stored in 2 pixels. 
    COMPLEX[,] comp = new COMPLEX[(int)(bmp.Width/2), bmp.Height]; 

    int [,] array2D = BitmapToArray2D(bmp); 

    for (int i = 0; i <= bmp.Width - 1; i++) 
    { 
     for (int j = 0; j <= bmp.Height - 1; j++) 
     { 
      comp[i, j].RealPart = array2D[i * 2, j]; 
      comp[i, j].ImaginaryPart = array2D[i * 2 + 1, j]; 
     } 
    } 

    return comp; 
} 
関連する問題