Beispiel #1
0
        public MainViewModel()
        {
            //Setup the audio input
            if (NAudio.Wave.WaveIn.DeviceCount == 0)
            {
                //TODO: set NoDevice app state
            }
            else
            {
                DeviceCapabilities = new List <WaveInCapabilities>();
                for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
                {
                    DeviceCapabilities.Add(NAudio.Wave.WaveIn.GetCapabilities(i));
                }
                SelectedDevice = DeviceCapabilities[0];
            }

            //Setup FFT size
            FftSizes = new List <int>()
            {
                512, 1024, 2048, 4096, 8192, 16384, 32768
            };
            SelectedFftSize = FftSizes[1];

            ColorMaps        = Colormap.GetColormaps().ToList();
            SelectedColorMap = ColorMaps.Where(c => c.Name == "Viridis").FirstOrDefault();
            Brightness       = 5;

            timer           = new DispatcherTimer();
            timer.Interval  = TimeSpan.FromMilliseconds(100);
            timer.IsEnabled = true;
            timer.Tick     += Timer_Tick;
            timer.Start();
        }
Beispiel #2
0
        /// <summary>
        /// Compares the decrease in values from the reference Nifti (prior) to the input Nifti (current).
        /// The inputs should be pre-registered and normalised.
        /// </summary>
        /// <param name="input">Current example</param>
        /// <param name="reference">Prior example</param>
        /// <returns>Nifti who's values are the meaningful decrease (less than 0) between prior and current.</returns>
        public static INifti <float> CompareMSLesionDecrease(INifti <float> input, INifti <float> reference)
        {
            INifti <float> output = Compare.GatedSubract(input, reference, backgroundThreshold: 10, minRelevantStd: -1, maxRelevantStd: 5, minChange: 0.8f, maxChange: 5);

            for (int i = 0; i < output.Voxels.Length; ++i)
            {
                if (output.Voxels[i] > 0)
                {
                    output.Voxels[i] = 0;
                }
            }
            output.RecalcHeaderMinMax(); // This will update the header range.
            output.ColorMap = ColorMaps.ReverseGreenScale();

            return(output);
        }
        public ColorMapPlateMap(double[] DataForColors)
        {
            cData  = DataForColors;
            Colors = new Color[DataForColors.Length];
            var    Data     = from x in cData where SimpleFunctions.IsARealNumber(x) select x;
            var    realData = Data.ToArray();
            double min      = SimpleFunctions.MinNotZero(realData);
            double max      = realData.Max();

            //Cmap = new ColorMap(SimpleFunctions.MinNotZero(realData), SimpleFunctions.Max(realData), true);
            for (int i = 0; i < DataForColors.Length; i++)
            {
                if (!SimpleFunctions.IsARealNumber(DataForColors[i]))
                {
                    DataForColors[i] = 0.0;
                }
                Colors[i] = ColorMaps.SpringColorFn(DataForColors[i], min, max);
            }
            makeSquares();
            this.Refresh();
        }
Beispiel #4
0
        /// <summary>
        /// 监听回调函数
        /// </summary>
        /// <param name="data"></param>
        public void onData(KObject data)
        {
            if (File.Exists(strFileSave))
            {
                File.Delete(strFileSave);
            }
            bool length_incr = true;

            lst_ImagSur.Clear();
            GoDataSet   dataSet = (GoDataSet)data;
            DataContext context = new DataContext();

            for (UInt32 i = 0; i < dataSet.Count; ++i)
            {
                GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);
                switch (dataObj.MessageType)
                {
                case GoDataMessageType.Stamp:
                {
                    Console.WriteLine("GoDataMessageType.Stamp");
                    //GoStampMsg stampMsg = (GoStampMsg)dataObj;
                    //for (UInt32 j = 0; j < stampMsg.Count; j++)
                    //{
                    //    GoStamp stamp = stampMsg.Get(j);
                    //    Console.WriteLine("Frame Index = {0}", stamp.FrameIndex);
                    //    Console.WriteLine("Time Stamp = {0}", stamp.Timestamp);
                    //    Console.WriteLine("Encoder Value = {0}", stamp.Encoder);
                    //}
                }
                break;

                case GoDataMessageType.UniformSurface:    //case GoDataMessageType.Surface:
                {
                    Console.WriteLine("GoDataMessageType.UniformSurface");
                    GoUniformSurfaceMsg surfaceMsg = (GoUniformSurfaceMsg)dataObj;
                    long   width         = surfaceMsg.Width;
                    long   height        = surfaceMsg.Length;
                    long   bufferSize    = width * height;
                    IntPtr bufferPointer = surfaceMsg.Data;

                    short[] ranges = new short[bufferSize];
                    Marshal.Copy(bufferPointer, ranges, 0, ranges.Length);

                    context.xResolution = (double)surfaceMsg.XResolution / 1000000.0;
                    context.zResolution = (double)surfaceMsg.ZResolution / 1000000.0;
                    context.yResolution = (double)surfaceMsg.YResolution / 1000000.0;
                    context.yOffset     = (double)surfaceMsg.YOffset / 1000.0;
                    context.xOffset     = (double)surfaceMsg.XOffset / 1000.0;
                    context.zOffset     = (double)surfaceMsg.ZOffset / 1000.0;

                    double phy_x;
                    double phy_y;
                    double phy_z;

                    FileStream   fs = new FileStream(strFileSave, FileMode.Create);
                    StreamWriter sw = new StreamWriter(fs);

                    for (int m = 0; m < height; m++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            phy_z = ranges[m * width + j] * context.zResolution + context.zOffset;
                            if (true)             //   /*phy_z > 20*/   这个过滤阈值根据实际情况选取
                            {
                                phy_x = j * context.xResolution + context.xOffset;
                                phy_y = m * context.yResolution + context.yOffset;

                                string strWrite = string.Format("{0} {1} {2}", phy_x, phy_y, phy_z);
                                sw.WriteLine(strWrite);
                                lst_ImagSur.Add(new Vector4((float)phy_x, (float)phy_y, (float)phy_z, 1.0f));
                            }
                        }
                    }
                    sw.Flush();
                    //关闭流
                    sw.Close();
                    fs.Close();
                }
                break;

                case GoDataMessageType.Measurement:
                {
                    Console.WriteLine("GoDataMessageType.Measurement");
                    //GoMeasurementMsg measurementMsg = (GoMeasurementMsg)dataObj;
                    //for (UInt32 k = 0; k < measurementMsg.Count; ++k)
                    //{
                    //    GoMeasurementData measurementData = measurementMsg.Get(k);
                    //    mPoint.X = measurementData.Value;
                    //    mPoint.Y = measurementData.Value;
                    //    mPoint.Z = measurementData.Value;
                    //}
                }
                break;

                case GoDataMessageType.ProfilePointCloud:    //case GoDataMessageType.Profile:
                {
                    Console.WriteLine("GoDataMessageType.Profile");
                    //StreamWriter write = new StreamWriter(strFileSave, true);
                    //GoProfilePointCloudMsg profileMsg = (GoProfilePointCloudMsg)dataObj;
                    //Console.WriteLine("  Profile Message batch count: {0}", profileMsg.Count);
                    //for (UInt32 k = 0; k < profileMsg.Count; ++k)
                    //{
                    //    //int validPointCount = 0;
                    //    long profilePointCount = profileMsg.Width;
                    //    Console.WriteLine("  Item[{0}]: Profile data ({1} points)", i, profileMsg.Width);
                    //    context.xResolution = (profileMsg.XResolution / 1000000.0);
                    //    context.zResolution = profileMsg.ZResolution / 1000000.0;
                    //    context.xOffset = profileMsg.XOffset / 1000.0;
                    //    context.zOffset = profileMsg.ZOffset / 1000.0;
                    //    GoPoints[] points = new GoPoints[profilePointCount];
                    //    //point[] point111 = new point[profilePointCount];
                    //    ProfilePoint[] profileBuffer = new ProfilePoint[profilePointCount];
                    //    int structSize = Marshal.SizeOf(typeof(GoPoints));
                    //    IntPtr pointsPtr = profileMsg.Data;
                    //    for (UInt32 array = 0; array < profilePointCount; ++array)
                    //    {
                    //        IntPtr incPtr = new IntPtr(pointsPtr.ToInt64() + array * structSize);
                    //        points[array] = (GoPoints)Marshal.PtrToStructure(incPtr, typeof(GoPoints));

                    //        double real_x = (context.xOffset + context.xResolution * points[array].x);
                    //        double real_z = (context.zOffset + context.zResolution * points[array].y);

                    //        if (length_incr == true)
                    //        {
                    //            length += 1;//ReadIniSettings.ReadIni.objIniValue.iniScanner.step;
                    //            length_incr = false;
                    //        }

                    //        if (/*(real_z > 15 && real_x > -500.0 && real_z < 400*/true)
                    //        //if (real_z > 5.0  && real_z < 25 && length >100 && length < 2000)
                    //        {
                    //            write.WriteLine(real_x + " " + length + " " + real_z);
                    //        }
                    //    }
                    //    write.Flush();
                    //}
                    //write.Close();
                }
                break;

                case GoDataMessageType.ProfileIntensity:
                {
                    Console.WriteLine("GoDataMessageType.ProfileIntensity");
                    //GoProfileIntensityMsg profileMsg = (GoProfileIntensityMsg)dataObj;
                    //Console.WriteLine("  Profile Intensity Message batch count: {0}", profileMsg.Count);
                    //for (UInt32 k = 0; k < profileMsg.Count; ++k)
                    //{
                    //    byte[] intensity = new byte[profileMsg.Width];
                    //    IntPtr intensityPtr = profileMsg.Data;
                    //    Marshal.Copy(intensityPtr, intensity, 0, intensity.Length);
                    //}
                }
                break;

                case GoDataMessageType.Alignment:
                    Console.WriteLine("GoDataMessageType.Alignment");
                    break;

                case GoDataMessageType.BoundingBoxMatch:
                    Console.WriteLine("GoDataMessageType.BoundingBoxMatch");
                    break;

                case GoDataMessageType.EdgeMatch:
                    Console.WriteLine("GoDataMessageType.EdgeMatch");
                    break;

                case GoDataMessageType.EllipseMatch:
                    Console.WriteLine("GoDataMessageType.EllipseMatch");
                    break;

                case GoDataMessageType.Event:
                    Console.WriteLine("GoDataMessageType.Event");
                    break;

                case GoDataMessageType.ExposureCal:
                    Console.WriteLine("GoDataMessageType.ExposureCal");
                    break;

                case GoDataMessageType.Generic:
                    Console.WriteLine("GoDataMessageType.Generic");
                    break;

                case GoDataMessageType.Health:
                    Console.WriteLine("GoDataMessageType.Health");
                    break;

                case GoDataMessageType.Range:
                    Console.WriteLine("GoDataMessageType.Range");
                    break;

                case GoDataMessageType.RangeIntensity:
                    Console.WriteLine("GoDataMessageType.RangeIntensity");
                    break;

                case GoDataMessageType.ResampledProfile:    //case GoDataMessageType.UniformProfile:
                    Console.WriteLine("GoDataMessageType.ResampledProfile");
                    break;

                case GoDataMessageType.Section:
                    Console.WriteLine("GoDataMessageType.Section");
                    break;

                case GoDataMessageType.SectionIntensity:
                    Console.WriteLine("GoDataMessageType.SectionIntensity");
                    break;

                case GoDataMessageType.SurfaceIntensity:
                    Console.WriteLine("GoDataMessageType.SurfaceIntensity");
                    break;

                case GoDataMessageType.SurfacePointCloud:
                    Console.WriteLine("GoDataMessageType.SurfacePointCloud");
                    break;

                case GoDataMessageType.Tracheid:
                    Console.WriteLine("GoDataMessageType.Tracheid");
                    break;

                case GoDataMessageType.Unknown:
                    Console.WriteLine("GoDataMessageType.Unknown");
                    break;

                case GoDataMessageType.Video:
                    Console.WriteLine("GoDataMessageType.Video");
                    break;
                }
            }
            dataSet.Dispose();
            if (ActGetBit != null && lst_ImagSur.Count > 0)
            {
                int      imgWidth, imgHeight;
                int      rowNum = lst_ImagSur.Count;
                double[] xVal   = new double[rowNum];
                double[] yVal   = new double[rowNum];
                ushort[] zVal   = new ushort[rowNum];

                for (int m = 0; m < rowNum; m++)
                {
                    xVal[m] = Math.Round(lst_ImagSur[m].x / pixelPitch);
                    yVal[m] = Math.Round(lst_ImagSur[m].y / pixelPitch);
                    zVal[m] = (ushort)lst_ImagSur[m].z;
                }
                ArrayList list_x = new ArrayList(xVal);
                list_x.Sort();
                if (list_x.Count == 0)
                {
                    double minVal_x = 0;        // Convert.ToInt32(list[0]);
                    double maxVal_x = 0;
                    ActGetBit(null);
                }
                else
                {
                    double minVal_x = Convert.ToDouble(list_x[0]); // Convert.ToInt32(list[0]);
                    double maxVal_x = Convert.ToDouble(list_x[list_x.Count - 1]);

                    ArrayList list_y = new ArrayList(yVal);
                    list_y.Sort();
                    double minVal_y = Convert.ToDouble(list_y[0]); // Convert.ToInt32(list[0]);
                    double maxVal_y = Convert.ToDouble(list_y[list_y.Count - 1]);

                    ArrayList list_z = new ArrayList(zVal);
                    list_z.Sort();
                    double minVal_z = Convert.ToDouble(list_z[0]); // Convert.ToInt32(list[0]);
                    double maxVal_z = Convert.ToDouble(list_z[list_z.Count - 1]);

                    imgHeight = Convert.ToInt32(Math.Round(maxVal_x - minVal_x)) + 1;
                    imgWidth  = Convert.ToInt32(Math.Round(maxVal_y - minVal_y)) + 1;

                    double scale = (double)imgHeight / imgWidth;
                    double[,] imgTemp = new double[imgHeight, imgWidth];

                    for (int m = 0; m < rowNum; m++)
                    {
                        xVal[m] = xVal[m] - minVal_x;
                        yVal[m] = yVal[m] - minVal_y;
                    }
                    for (int n = 0; n < rowNum; n++)
                    {
                        imgTemp[Convert.ToInt32(xVal[n]), Convert.ToInt32(yVal[n])] = zVal[n];
                    }

                    // 将imgTemp转成一维图像
                    ushort[] ZValues = new ushort[imgHeight * imgWidth];
                    for (int i = 0; i < ZValues.Length; i++)
                    {
                        ZValues[i] = (ushort)imgTemp[i / imgWidth, i % imgWidth];
                    }

                    ColorMaps MapColor = new ColorMaps();
                    ushort    minValue = 0, maxValue = 0;
                    MapColor.FindMinMaxForColor(ZValues, (UInt32)(imgHeight * imgWidth), 0, ref minValue, ref maxValue);
                    Color[] colors = new Color[imgHeight * imgWidth];
                    MapColor.ToColors(ZValues, minValue, maxValue, 0, ref colors, (UInt32)(imgHeight * imgWidth));

                    Bitmap     Bimage = new Bitmap(imgWidth, imgHeight);
                    BitmapData bmdata = Bimage.LockBits(new Rectangle(0, 0, imgWidth, imgHeight), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                    //IntPtr intptr = bmdata.Scan0;
                    byte[] Pixlemaps = new byte[bmdata.Stride * bmdata.Height];
                    // int offset = bmdata.Stride - bmdata.Width * 3;

                    unsafe
                    {
                        byte *pp = (byte *)(void *)bmdata.Scan0;

                        for (int k = 0; k < bmdata.Height; k++)
                        {
                            for (int m = 0; m < bmdata.Width; m++)
                            {
                                pp[0] = (byte)(colors[k * bmdata.Width + m].R);
                                pp[1] = (byte)(colors[k * bmdata.Width + m].G);
                                pp[2] = (byte)(colors[k * bmdata.Width + m].B);
                                pp   += 3;
                            }
                            pp += bmdata.Stride - bmdata.Width * 3;
                        }
                    }
                    Bimage.UnlockBits(bmdata);
                    Bitmap aBM2 = Bimage.Clone(new RectangleF(0, 0, Bimage.Width, Bimage.Height), PixelFormat.Format24bppRgb);
                    ActGetBit(aBM2);
                    //pbxImage.Width = 150;
                    //pbxImage.Height = Convert.ToInt32(pbxImage.Width * scale);
                    //Bitmap imgShow_scale = new Bitmap(aBM2, pbxImage.Width, pbxImage.Height);
                    //pbxImage.Image = imgShow_scale;
                }
            }
        }
Beispiel #5
0
        private Histogram DoCompare(INifti <float> currentnii, INifti <float> priornii)
        {
            _log.Info("Starting normalization...");
            currentnii = Normalization.ZNormalize(currentnii, priornii);
            _log.Info($@"..done.");

            currentnii.RecalcHeaderMinMax();
            priornii.RecalcHeaderMinMax();

            var tasks     = new List <Task>();
            var histogram = new Histogram
            {
                Prior   = priornii,
                Current = currentnii
            };

            var cs = _recipe.CompareSettings;

            if (cs.CompareIncrease)
            {
                var t = Task.Run(() =>
                {
                    _log.Info("Comparing increased signal...");
                    var increase = Compare.GatedSubract(currentnii, priornii, cs.BackgroundThreshold, cs.MinRelevantStd, cs.MaxRelevantStd, cs.MinChange, cs.MaxChange);
                    for (int i = 0; i < increase.Voxels.Length; ++i)
                    {
                        increase.Voxels[i] = increase.Voxels[i] > 0 ? increase.Voxels[i] : 0;
                    }
                    increase.RecalcHeaderMinMax();
                    increase.ColorMap  = ColorMaps.RedScale();
                    histogram.Increase = increase;
                    var increaseOut    = currentnii.AddOverlay(increase);
                    var outpath        = _currentPath + ".increase.nii";
                    increaseOut.WriteNifti(outpath);
                    Metrics.ResultFiles.Add(new ResultFile()
                    {
                        FilePath = outpath, Description = "Increased Signal", Type = ResultType.CURRENT_PROCESSED
                    });
                });
                tasks.Add(t);
            }
            if (cs.CompareDecrease)
            {
                _log.Info("Comparing decreased signal...");
                // I know the code in these two branches looks similar but there's too many inputs to make a function that much simpler...
                var t = Task.Run(() =>
                {
                    var decrease = Compare.GatedSubract(currentnii, priornii, cs.BackgroundThreshold, cs.MinRelevantStd, cs.MaxRelevantStd, cs.MinChange, cs.MaxChange);
                    for (int i = 0; i < decrease.Voxels.Length; ++i)
                    {
                        decrease.Voxels[i] = decrease.Voxels[i] < 0 ? decrease.Voxels[i] : 0;
                    }
                    decrease.RecalcHeaderMinMax();
                    decrease.ColorMap = ColorMaps.ReverseGreenScale();

                    histogram.Decrease = decrease;
                    var decreaseOut    = currentnii.AddOverlay(decrease);
                    var outpath        = _currentPath + ".decrease.nii";
                    decreaseOut.WriteNifti(outpath);
                    Metrics.ResultFiles.Add(new ResultFile()
                    {
                        FilePath = outpath, Description = "Decreased Signal", Type = ResultType.CURRENT_PROCESSED
                    });
                });
                tasks.Add(t);
            }
            Task.WaitAll(tasks.ToArray());
            _log.Info("...done.");

            return(histogram);
        }
Beispiel #6
0
        public void makeSquares(double[] DataToSquare)
        {
            Graphics g = Graphics.FromImage(TheColoredSquaresBM);

            g.Clear(System.Drawing.Color.White);
            //ColorMap Cmap = new ColorMap(0,1);

            //ColorMap Cmap = new ColorMap(SimpleFunctions.Min(DataToSquare), SimpleFunctions.Max(DataToSquare),false);
            //USE THE ONE UNDERNEATH
            //now going to make data so it excludes NaN
            var    Data     = from x in DataToSquare where SimpleFunctions.IsARealNumber(x) select x;
            var    realData = Data.ToArray();
            double min      = SimpleFunctions.MinNotZero(realData);
            double max      = realData.Max();
            //ColorMap Cmap = new ColorMap(SimpleFunctions.MinNotZero(realData), SimpleFunctions.Max(realData),true);
            //ColorMap Cmap = new ColorMap(0, 1, true);

            //Color[] ColorNums =new Color[96];
            //for(int i=0;i<96;i++)
            //{ ColorNums[i]=Cmap.GetColor(i);}
            SolidBrush BlackBrush = new SolidBrush(Color.Black);
            Pen        P          = new Pen(Color.Black, 5);
            SolidBrush sb         = new SolidBrush(Color.Blue);

            try
            {
                int YPos = RoomForText;
                int XPos = RoomForText;

                for (int i = 1; i <= NumCols; i++)
                {
                    g.DrawString(i.ToString(), FontofControl, BlackBrush, ((float)(RoomForText + (SideLength * .25) + SideLength * (i - 1))), 0);
                }
                string Rows = "ABCDEFGH";
                Rows = Rows.Substring(0, NumRows);
                for (int i = 0; i < NumRows; i++)
                {
                    g.DrawString(Rows[i].ToString(), FontofControl, BlackBrush, 0, ((float)(RoomForText + (SideLength * .35) + SideLength * i)));
                }

                int[,] TextPos = new int[NumWells, 2];
                Rectangle[] PlateWells = new Rectangle[NumWells];

                for (int i = 0; i < NumWells; i++)
                {
                    double colToSquare = DataToSquare[i];
                    if (!SimpleFunctions.IsARealNumber(colToSquare))
                    {
                        colToSquare = 0.0;
                    }
                    sb = new SolidBrush(ColorMaps.SpringColorFn(colToSquare, min, max));
                    if (UseBinaryColorScheme)
                    {
                        sb = new SolidBrush(ColorMaps.BinaryColorFunGetColor(colToSquare));
                    }
                    int ColPos  = i % NumCols;
                    int rowPos  = Convert.ToInt32((i / NumCols));
                    int RecYPos = YPos + SideLength * rowPos;
                    int RecXPos = XPos + SideLength * ColPos;
                    TextPos[i, 0] = (int)(RecXPos + SideLength * .15);
                    TextPos[i, 1] = (int)(RecYPos + (SideLength / 2) - (FontofControl.Height / 2));
                    PlateWells[i] = new Rectangle(RecXPos, RecYPos, SideLength, SideLength);
                    g.FillRectangle(sb, PlateWells[i]);
                }
                g.DrawRectangles(P, PlateWells);
                //now to add text over it
                if (AddText)
                {
                    for (int i = 0; i < NumWells; i++)
                    {
                        string toWrite = DataToSquare[i].ToString("n4");
                        if (DataToSquare[i] > 100)
                        {
                            int Value = (int)DataToSquare[i];
                            toWrite = Value.ToString();
                        }
                        g.DrawString(toWrite, FontofControl, BlackBrush, TextPos[i, 0], TextPos[i, 1]);
                    }
                }
            }
            finally { g.Dispose(); BlackBrush.Dispose(); P.Dispose(); sb.Dispose(); }
        }