Example #1
0
        private void CreateGraph(ZedGraphControl zgc)
        {
            // Get a reference to the GraphPane
            GraphPane myPane = zgc.GraphPane;

            // Set the Titles
            myPane.Title.Text       = "Intensity Histogram";
            myPane.XAxis.Title.Text = "Intensity";
            myPane.YAxis.Title.Text = "Count";

            TileView viewer = this.mosaicWindow.TileView;

            List <Tile> tiles = viewer.GetVisibleTiles();

            if (tiles == null)
            {
                return;
            }

            int[]   total_red_hist   = new int[256];
            int[]   total_green_hist = new int[256];
            int[]   total_blue_hist  = new int[256];
            ulong[] total_hist       = new ulong[256];

            int[]   red_hist    = null;
            int[]   green_hist  = null;
            int[]   blue_hist   = null;
            ulong[] hist        = null;
            bool    colourImage = false;

            if (MosaicWindow.MosaicInfo.ColorDepth >= 24)
            {
                colourImage = true;
            }

            for (int i = 0; i < total_red_hist.Length; i++)
            {
                total_red_hist[i]   = 0;
                total_green_hist[i] = 0;
                total_blue_hist[i]  = 0;
            }

            double max_posible_intensity_in_images = 0.0;

            foreach (Tile tile in tiles)
            {
                if (tile.IsDummy)
                {
                    continue;
                }

                FreeImageAlgorithmsBitmap dib = tile.LoadFreeImageBitmap();

                if (dib.MaximumPossibleIntensityValue > max_posible_intensity_in_images)
                {
                    max_posible_intensity_in_images = dib.MaximumPossibleIntensityValue;
                }

                if (colourImage)
                {
                    dib.GetHistogram(FREE_IMAGE_COLOR_CHANNEL.FICC_RED, out red_hist);
                    dib.GetHistogram(FREE_IMAGE_COLOR_CHANNEL.FICC_GREEN, out green_hist);
                    dib.GetHistogram(FREE_IMAGE_COLOR_CHANNEL.FICC_BLUE, out blue_hist);
                }
                else
                {
                    dib.GetGreyLevelHistogram(256, out hist);
                }

                dib.Dispose();

                for (int i = 0; i < total_red_hist.Length; i++)
                {
                    if (colourImage)
                    {
                        total_red_hist[i]   += red_hist[i];
                        total_green_hist[i] += green_hist[i];
                        total_blue_hist[i]  += blue_hist[i];
                    }
                    else
                    {
                        total_hist[i] += hist[i];
                    }
                }
            }

            double range_per_bin = max_posible_intensity_in_images / 256;

            double        x, y;
            PointPairList red_list   = new PointPairList();
            PointPairList green_list = new PointPairList();
            PointPairList blue_list  = new PointPairList();

            if (colourImage)
            {
                for (int i = 0; i < total_red_hist.Length; i++)
                {
                    x = (double)i;
                    y = (double)total_red_hist[i];
                    red_list.Add(x, y);

                    y = (double)total_green_hist[i];
                    green_list.Add(x, y);

                    y = (double)total_blue_hist[i];
                    blue_list.Add(x, y);
                }

                // Generate a red curve with diamond
                LineItem red_curve = myPane.AddCurve("",
                                                     red_list, Color.Red, SymbolType.None);

                LineItem green_curve = myPane.AddCurve("",
                                                       green_list, Color.Green, SymbolType.None);

                LineItem blue_curve = myPane.AddCurve("",
                                                      blue_list, Color.Blue, SymbolType.None);
            }
            else
            {
                for (int i = 0; i < total_red_hist.Length; i++)
                {
                    x = (double)(i * range_per_bin);
                    y = (double)total_hist[i];
                    red_list.Add(x, y);
                }

                // Generate a red curve with diamond
                // symbols, and "Porsche" in the legend
                BarItem curve = myPane.AddBar("",
                                              red_list, Color.Black);
            }

            zgc.AxisChange();
        }