//-------------------------------------------------------------------------------------------------------------- //Приведение матрицы фаз к диапазону 0..255 ( уровень серого ) public static RealMatrix TrnsformPhaseMatrixToGrayScaleMatrix(RealMatrix matrix) { Interval <double> startInterval = new Interval <double>(0, 2 * Math.PI); Interval <double> finishInterval = new Interval <double>(0, 255); RealIntervalTransform intervalTransform = new RealIntervalTransform(startInterval, finishInterval); RealMatrix scaledMatrix = RealMatrixValuesTransform.TransformMatrixValues(matrix, intervalTransform); return(scaledMatrix); }
private ZArrayDescriptor GenerateWedge(int mValue, int width, int imageHeight, int imageWidth, double?mRatio = null) { ZArrayDescriptor arrayDescriptor = new ZArrayDescriptor(imageWidth + BLACK_SIDE_WIDTH, imageHeight); double maxIntensity = WEDGE_MAX_INTENSITY_VALUE; if (mRatio.HasValue) { maxIntensity = mRatio.Value * (WEDGE_MAX_INTENSITY_VALUE - WEDGE_MIN_INTENSITY_VALUE) + WEDGE_MIN_INTENSITY_VALUE; } Interval <double> interval1 = new Interval <double>(0, mValue - 1); Interval <double> interval2 = new Interval <double>(WEDGE_MIN_INTENSITY_VALUE, maxIntensity); RealIntervalTransform intervalTransform = new RealIntervalTransform(interval1, interval2); int[] array = new int[width]; int currentValue = 0; //Create wedge 0..m for (int j = 0; j < width; j++) { if (currentValue >= mValue - 1) { currentValue = 0; } array[j] = currentValue; currentValue++; } CorrectBr correctBr = new CorrectBr(); double[] interpolatedClin = correctBr.InterpolateClin(clin); int qq = Convert.ToInt32(maxIntensity); //Stretch wedge to image width int k = imageWidth / (array.Length) + 1; for (int x = 0; x < imageWidth - 1; x++) { int i = x / k; for (int y = 0; y < imageHeight - 1; y++) { double value = intervalTransform.TransformToFinishIntervalValue(array[i]); //double correctedValue = CorrectBr.CorrectValueByClin(value, interpolatedClin, qq); double correctedValue = value; arrayDescriptor.array[x, y] = correctedValue; } } return(arrayDescriptor); }
private void CalcWedgeIntensityDistribution() { ZArrayDescriptor arrayDescriptor1 = Form1.zArrayDescriptor[0]; ZArrayDescriptor arrayDescriptor2 = Form1.zArrayDescriptor[1]; Interval <double> intervalInt = new Interval <double>(0, 225); Interval <double> intervalM1 = new Interval <double>(0, WEDGE_M1); Interval <double> intervalM2 = new Interval <double>(0, WEDGE_M2); RealIntervalTransform intervalTransformM1 = new RealIntervalTransform(intervalInt, intervalM1); RealIntervalTransform intervalTransformM2 = new RealIntervalTransform(intervalInt, intervalM2); int width = arrayDescriptor1.width; int startY = 0; int height = 2; List <Point2D> pointsList = new List <Point2D>(); for (int x = 0; x < width - 1; x++) { for (int y = startY; y < height - 1; y++) { double intensity1 = arrayDescriptor1.array[x, y]; double intensity2 = arrayDescriptor2.array[x, y]; intensity1 = intervalTransformM1.TransformToFinishIntervalValue(intensity1); intensity2 = intervalTransformM2.TransformToFinishIntervalValue(intensity2); int b1 = Convert.ToInt32(intensity1); int b2 = Convert.ToInt32(intensity2); pointsList.Add(new Point2D(b1, b2)); } } RangeExtensionModelForm decisionTableForm = new RangeExtensionModelForm(); IList <Point2D> decisionTablePointsList = decisionTableForm.BuildTable(WEDGE_M1, WEDGE_M2, WEDGE_WIDTH); GraphInfo idealGraphInfo = new GraphInfo("Ideal graph", System.Windows.Media.Colors.Green, decisionTablePointsList.ToArray(), true, false); GraphInfo graph = new GraphInfo("Graphic", System.Windows.Media.Colors.Red, pointsList.ToArray(), false, true); IList <GraphInfo> graphCollection = new List <GraphInfo>() { idealGraphInfo, graph }; ShowGraphic(graphCollection); }
//---------------------------------------------------------------------------------------------- //Привести матрицы от диапазона к диапазону public static RealMatrix[] TransformMatrices( Interval <double> startInterval, Interval <double> finishInterval, params RealMatrix[] matrices ) { RealIntervalTransform intervalTransformer = new RealIntervalTransform(startInterval, finishInterval); RealMatrix[] newMatrices = new RealMatrix[matrices.Length]; for (int index = 0; index < matrices.Length; index++) { RealMatrix matrix = matrices[index]; RealMatrix newMatrix = RealMatrixValuesTransform.TransformMatrixValues(matrix, intervalTransformer); newMatrices[index] = newMatrix; } return(newMatrices); }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------ /* * //Создание изображения из файла * public static WriteableBitmap CreateWriteableBitmapFromFile( string fileName, double dpiX, double dpiY ) { * System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( fileName ); * * //System.Windows.Media.PixelFormat targetPixelFormat = PixelFormats.Rgba64; * System.Windows.Media.PixelFormat targetPixelFormat = PixelFormats.Pbgra32; * * WriteableBitmap writeableBitmap = * new WriteableBitmap( bitmap.Width, bitmap.Height, dpiX, dpiY, targetPixelFormat, null ); * * //WriteableBitmap writeableBitmap = * // new WriteableBitmap( bitmap.Width, bitmap.Height, dpiX, dpiY, PixelFormats.Rgba64, null ); * * System.Drawing.Rectangle rect = new System.Drawing.Rectangle( 0, 0, bitmap.Width, bitmap.Height ); * System.Drawing.Imaging.ImageLockMode lockMode = System.Drawing.Imaging.ImageLockMode.ReadOnly; * * System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb; * //System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.Format64bppArgb; * //System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.Format16bppGrayScale; * * System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits( rect, lockMode, pixelFormat ); * Int32Rect int32Rect = new System.Windows.Int32Rect( 0, 0, bitmapData.Width, bitmapData.Height ); * * writeableBitmap.WritePixels * ( int32Rect, bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride ); * bitmap.UnlockBits( bitmapData ); * bitmap.Dispose(); * * return writeableBitmap; * } */ //------------------------------------------------------------------------------------------------ public static ExtraImageInfo CreateWriteableBitmapFromFile(string fileName, double dpiX, double dpiY) { //public static WriteableBitmap CreateWriteableBitmapFromFile( string fileName, double dpiX, double dpiY ) { /* * if ( fileName.ToUpper().EndsWith( "CR2" ) ) { * * MagickImage magicImage = new MagickImage( fileName ); * * int width = magicImage.Width; * int height = magicImage.Height; * PixelFormat pixelFormat = PixelFormats.Bgra32; * * WriteableBitmap resultWriteableBitmap = * WriteableBitmapCreator.CreateWriteableBitmap( width, height, (int)dpiX, (int)dpiY, pixelFormat ); * WriteableBitmapWrapper imageWrapper = WriteableBitmapWrapper.Create( resultWriteableBitmap ); * * PixelCollection pixelCollection = magicImage.GetPixels(); * * Interval<double> interval1 = new Interval<double>( 0, ushort.MaxValue ); * Interval<double> interval2 = new Interval<double>( 0, byte.MaxValue ); * RealIntervalTransform intervalTransform = new RealIntervalTransform( interval1, interval2 ); * * RealMatrix redMatrix = new RealMatrix( height, width ); * * for ( int x = 0; x < width; x++ ) { * for ( int y = 0; y < height; y++ ) { * Pixel pixel = pixelCollection.GetPixel(x, y); * MagickColor magicColor = pixel.ToColor(); * * redMatrix[ y, x ] = intervalTransform.TransformToFinishIntervalValue(magicColor.R); * * byte a = Convert.ToByte( intervalTransform.TransformToFinishIntervalValue( magicColor.A ) ); * byte r = Convert.ToByte( intervalTransform.TransformToFinishIntervalValue( magicColor.R ) ); * byte g = Convert.ToByte( intervalTransform.TransformToFinishIntervalValue( magicColor.G ) ); * byte b = Convert.ToByte( intervalTransform.TransformToFinishIntervalValue( magicColor.B ) ); * * Color color = Color.FromArgb( a, r, g, b ); * * imageWrapper.SetPixelColor( x, y, color ); * } * } * * ExtraImageInfo extraImageInfo = new ExtraImageInfo(); * extraImageInfo.RedMatrix = redMatrix; * extraImageInfo.Image = resultWriteableBitmap; * * //return resultWriteableBitmap; * return extraImageInfo; * * } */ /* * if ( fileName.ToUpper().EndsWith( "CR2" ) ) { * * * //System.GC.Collect(); * * //BitmapDecoder bitmapDecoder = * // BitmapDecoder.Create( new Uri( fileName ), * // BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None ); * * //BitmapFrame frame = bitmapDecoder.Frames[ 0 ]; * * //WriteableBitmap bitmap = new WriteableBitmap( frame ); * //WriteableBitmapWrapper wrapper = WriteableBitmapWrapper.Create( bitmap ); * * //Color c = wrapper.GetPixelColor( 300, 300 ); * * * System.GC.Collect(); * * uint error; * * IntPtr imgRef; * //Open image * IntPtr inStream; * error = EDSDK.EdsCreateFileStream(fileName, EDSDK.EdsFileCreateDisposition.OpenExisting, EDSDK.EdsAccess.Read, out inStream); * EDSDK.EdsCreateImageRef(inStream, out imgRef); * EDSDK.EdsRelease(inStream); * * string convertedFileName = Path.ChangeExtension(fileName, "TIFF"); * * //Save image * IntPtr outStream; * var settings = new EDSDK.EdsSaveImageSetting(); * error = EDSDK.EdsCreateFileStream(convertedFileName, EDSDK.EdsFileCreateDisposition.CreateAlways, EDSDK.EdsAccess.Write, out outStream); * error = EDSDK.EdsSaveImage(imgRef, EDSDK.EdsTargetImageType.TIFF16, settings, outStream); * EDSDK.EdsRelease(outStream); * * ExtraImageInfo extraImageInfo = new ExtraImageInfo(); * return extraImageInfo; * * } */ if (fileName.ToUpper().EndsWith("CR2")) { Interval <double> finishInterval = new Interval <double>(0, 255); IntegerMatrix matrix = RawReader.ReadImageFromFile(fileName); //matrix = matrix.GetSubMatrix(0, 2640 - 1, matrix.RowCount - 1, matrix.ColumnCount - 1); int min = matrix.GetMinValue(); int max = matrix.GetMaxValue(); IntegerMatrix redMatrix = InterpolationHelper.GetRedMatrix(matrix); int minRed = redMatrix.GetMinValue(); int maxRed = redMatrix.GetMaxValue(); IntegerMatrix greenMatrix = InterpolationHelper.GetGreenMatrix(matrix); int minGreen = greenMatrix.GetMinValue(); int maxGreen = greenMatrix.GetMaxValue(); IntegerMatrix blueMatrix = InterpolationHelper.GetBlueMatrix(matrix); int minBlue = blueMatrix.GetMinValue(); int maxBlue = blueMatrix.GetMaxValue(); int minValue = (new int[] { minRed, minGreen, minBlue }).Min(); int maxValue = (new int[] { maxRed, maxGreen, maxBlue }).Max(); RealIntervalTransform redIntervalTransform = new RealIntervalTransform(new Interval <double>(minValue, maxValue), finishInterval); IntegerMatrix resRedMatrix = IntegerMatrixValuesTransform.TransformMatrixValues(redMatrix, redIntervalTransform); RealIntervalTransform greenIntervalTransform = new RealIntervalTransform(new Interval <double>(minValue, maxValue), finishInterval); IntegerMatrix resGreenMatrix = IntegerMatrixValuesTransform.TransformMatrixValues(greenMatrix, greenIntervalTransform); RealIntervalTransform blueIntervalTransform = new RealIntervalTransform(new Interval <double>(minValue, maxValue), finishInterval); IntegerMatrix resBlueMatrix = IntegerMatrixValuesTransform.TransformMatrixValues(blueMatrix, blueIntervalTransform); WriteableBitmap resImage = WriteableBitmapCreator.CreateWriteableBitmapFromMatricesRGB (resRedMatrix, resGreenMatrix, resBlueMatrix, OS.OS.IntegerSystemDpiX, OS.OS.IntegerSystemDpiY); /* * IntegerMatrix resMatrix = * IntegerMatrixValuesTransform.TransformMatrixValuesToFinishIntervalValues(matrix, finishInterval); * * WriteableBitmap resImage = * WriteableBitmapCreator.CreateGrayScaleWriteableBitmapFromMatrix * (resMatrix, OS.OS.IntegerSystemDpiX, OS.OS.IntegerSystemDpiY); */ ExtraImageInfo extraImageInfo = new ExtraImageInfo(); extraImageInfo.Image = resImage; return(extraImageInfo); } else { Stream imageStreamSource = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); BitmapDecoder decoder = BitmapDecoder.Create(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; WriteableBitmap resultWriteableBitmap = new WriteableBitmap(bitmapSource); ExtraImageInfo extraImageInfo = new ExtraImageInfo(); extraImageInfo.Image = resultWriteableBitmap; return(extraImageInfo); } }
private void btnIntensityIncrease_Click(object sender, EventArgs e) { int count = 1000; double step = GetStep(); List <double> valuesList = new List <double>(); double x = 0; for (int k = 0; k < count; k++) { double value = Math.Cos(x); valuesList.Add(value); x += step; } List <ChartPoint> points = new List <ChartPoint>(); for (int k = 0; k < count; k++) { ChartPoint p = new ChartPoint(k, valuesList[k]); points.Add(p); } Chart chart1 = new Chart() { SeriesCollection = new List <ChartSeries>() { new ChartSeries() { Name = "Graph", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(255, 0, 0), Points = points } } }; MemoryWriter.Write <Chart>(chart1, new ChartSerialization()); ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false); Thread.Sleep(2000); Interval <double> startInterval = new Interval <double>(-1, 1); Interval <double> finishInterval = new Interval <double>(0, MAX_RANGE_VALUE); RealIntervalTransform transform = new RealIntervalTransform(startInterval, finishInterval); List <ChartPoint> points2 = new List <ChartPoint>(); for (int k = 0; k < count; k++) { double newValue = transform.TransformToFinishIntervalValue(valuesList[k]); ChartPoint p = new ChartPoint(k, newValue); points2.Add(p); } List <ChartPoint> points3 = new List <ChartPoint>(); for (int k = 0; k < points2.Count; k++) { ChartPoint p = points2[k]; double v = p.Y % M1; ChartPoint newPoint = new ChartPoint(p.X, v); points3.Add(newPoint); } List <ChartPoint> points4 = new List <ChartPoint>(); for (int k = 0; k < points2.Count; k++) { ChartPoint p = points2[k]; double v = p.Y % M2; ChartPoint newPoint = new ChartPoint(p.X, v); points4.Add(newPoint); } Chart chart2 = new Chart() { SeriesCollection = new List <ChartSeries>() { new ChartSeries() { Name = "Graph", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(0, 0, 0), Points = points2 }, new ChartSeries() { Name = "M1", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(0, 255, 0), Points = points3 }, new ChartSeries() { Name = "M2", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(255, 0, 0), Points = points4 } } }; MemoryWriter.Write <Chart>(chart2, new ChartSerialization()); ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false); Thread.Sleep(2000); List <ChartPoint> points5 = new List <ChartPoint>(); for (int k = 0; k < points3.Count; k++) { ChartPoint m1Point = points3[k]; ChartPoint m2Point = points4[k]; ChartPoint point = new ChartPoint(m1Point.Y, m2Point.Y); //ChartPoint point = new ChartPoint(m1Point.Y - M1, M2 - m2Point.Y); points5.Add(point); } List <Point2D> pointsDiagonal = ModularArithmeticHelper.BuildTable(M1, M2, MAX_RANGE_VALUE); List <ChartPoint> points6 = new List <ChartPoint>(); for (int k = 0; k < pointsDiagonal.Count; k++) { Point2D p = pointsDiagonal[k]; ChartPoint p1 = new ChartPoint(p.X, p.Y); //ChartPoint p1 = new ChartPoint(p.X - M1, M2 - p.Y); points6.Add(p1); } Chart chart5 = new Chart() { //InvertAxisX = true, //InvertAxisY = true, SeriesCollection = new List <ChartSeries>() { new ChartSeries() { Name = "Diagonal", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(0, 255, 0), Points = points6 }, new ChartSeries() { Name = "Points", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Bubble, ColorDescriptor = new ColorDescriptor(0, 0, 0), Points = points5 } } }; MemoryWriter.Write <Chart>(chart5, new ChartSerialization()); ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false); Thread.Sleep(2000); }
private void btnGraphFromImages_Click(object sender, EventArgs e) { string directoryPath = @"D:\Images\!"; int x = 2690; int y = 1990; if (Directory.Exists(directoryPath)) { string[] files = Directory.GetFiles(directoryPath); IEnumerable <string> sortedFiles = files.OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f))); int n = 0; int minIntensity = 255; int maxIntensity = 0; List <ChartPoint> points = new List <ChartPoint>(); foreach (string file in sortedFiles) { using (Bitmap bitmap = new Bitmap(file)) { System.Drawing.Color color = bitmap.GetPixel(x, y); int intensity = ColorWrapper.GetGrayIntensity(color); if (intensity < minIntensity) { minIntensity = intensity; } if (intensity > maxIntensity) { maxIntensity = intensity; } ChartPoint chartPoint = new ChartPoint(n, intensity); points.Add(chartPoint); n++; } } Chart chart1 = new Chart() { SeriesCollection = new List <ChartSeries>() { new ChartSeries() { Name = "Grpah", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(255, 0, 0), Points = points } } }; MemoryWriter.Write <Chart>(chart1, new ChartSerialization()); ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false); Thread.Sleep(2000); Interval <double> startInterval = new Interval <double>(minIntensity, maxIntensity); Interval <double> finishInterval = new Interval <double>(-1, 1); RealIntervalTransform transform = new RealIntervalTransform(startInterval, finishInterval); List <ChartPoint> points2 = new List <ChartPoint>(); foreach (ChartPoint p in points) { double newValue = transform.TransformToFinishIntervalValue(p.Y); ChartPoint point = new ChartPoint(p.X, newValue); points2.Add(point); } Chart chart2 = new Chart() { SeriesCollection = new List <ChartSeries>() { new ChartSeries() { Name = "Grpah2", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(0, 255, 0), Points = points2 } } }; MemoryWriter.Write <Chart>(chart2, new ChartSerialization()); ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false); Thread.Sleep(2000); List <ChartPoint> points3 = new List <ChartPoint>(); foreach (ChartPoint p in points2) { double newValue = Math.Acos(p.Y); ChartPoint point = new ChartPoint(p.X, newValue); points3.Add(point); } Chart chart3 = new Chart() { SeriesCollection = new List <ChartSeries>() { new ChartSeries() { Name = "Grpah3", Type = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear, ColorDescriptor = new ColorDescriptor(0, 0, 0), Points = points3 } } }; MemoryWriter.Write <Chart>(chart3, new ChartSerialization()); ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false); Thread.Sleep(2000); } }