public static short[] ImageFormatTranslate(int[] SrcImage, enumImgFormat f, int max, int min) { short[] tmpImage = new short[SrcImage.Length]; short[] tmpRet = new short[SrcImage.Length / 2]; //将SrcImage归一化到short格式 double tmpDbl = (Math.Abs(max) > Math.Abs(min)) ? Math.Abs(max) : Math.Abs(min); if (tmpDbl > 16383) { double scale = Math.Ceiling(Math.Log(tmpDbl, 2) - 15); for (int i = 0; i < SrcImage.Length; i++) { tmpImage[i] = (short)(SrcImage[i] / scale); } } else { for (int i = 0; i < SrcImage.Length; i++) { tmpImage[i] = (short)SrcImage[i]; } } if (f == enumImgFormat.AbsLinear) { for (int i = 0; i < tmpRet.Length; i++) { tmpRet[i] = (short)Math.Sqrt(tmpImage[2 * i] * tmpImage[2 * i] + tmpImage[2 * i + 1] * tmpImage[2 * i + 1]); } } else if (f == enumImgFormat.AbsLog) { for (int i = 0; i < tmpRet.Length; i++) { tmpRet[i] = (short)(20 * Math.Log10(Math.Sqrt(tmpImage[2 * i] * tmpImage[2 * i] + tmpImage[2 * i + 1] * tmpImage[2 * i + 1]))); } } else if (f == enumImgFormat.Phase) { for (int i = 0; i < tmpRet.Length; i++) { tmpRet[i] = (short)(100 * Math.Atan2(tmpImage[2 * i + 1], tmpImage[2 * i])); } } else if (f == enumImgFormat.Real) { for (int i = 0; i < tmpRet.Length; i++) { tmpRet[i] = tmpImage[2 * i]; } } else { for (int i = 0; i < tmpRet.Length; i++) { tmpRet[i] = tmpImage[2 * i + 1]; } } return(tmpRet); }
public static short[] ImageFormatTranslate(short[] SrcImage, enumImgFormat f) { short[] tmpImage = new short[SrcImage.Length / 2]; if (f == enumImgFormat.AbsLinear) { for (int i = 0; i < tmpImage.Length; i++) { tmpImage[i] = (short)Math.Sqrt(SrcImage[2 * i] * SrcImage[2 * i] + SrcImage[2 * i + 1] * SrcImage[2 * i + 1]); } } else if (f == enumImgFormat.AbsLog) { for (int i = 0; i < tmpImage.Length; i++) { tmpImage[i] = (short)(20 * Math.Log10(Math.Sqrt(SrcImage[2 * i] * SrcImage[2 * i] + SrcImage[2 * i + 1] * SrcImage[2 * i + 1]))); } } else if (f == enumImgFormat.Phase) { for (int i = 0; i < tmpImage.Length; i++) { tmpImage[i] = (short)(100 * Math.Atan2(SrcImage[2 * i + 1], SrcImage[2 * i])); } } else if (f == enumImgFormat.Real) { for (int i = 0; i < tmpImage.Length; i++) { tmpImage[i] = SrcImage[2 * i]; } } else { for (int i = 0; i < tmpImage.Length; i++) { tmpImage[i] = SrcImage[2 * i + 1]; } } return(tmpImage); }