Esempio n. 1
0
        public static int guessFibMaxValue(FreeImageAlgorithmsBitmap fib)
        {
            uint            bpp = FreeImage.GetBPP(fib.Dib);
            FREE_IMAGE_TYPE type = FreeImage.GetImageType(fib.Dib);
            double          min, max;

            if (bpp == 8)
            {
                return(256);
            }

            if (bpp >= 24 && type == FREE_IMAGE_TYPE.FIT_BITMAP)  // colour image
            {
                return(256);
            }

            fib.FindMinMaxIntensity(out min, out max);

            if (max < 256)  // 8 bit
            {
                return(256);
            }
            if (max < 4096)  // 12 bit
            {
                return(4096);
            }
            if (max < 65536)  // 16 bit
            {
                return(65536);
            }

            return(100000);  // who knows!
        }
Esempio n. 2
0
        internal void RegenerateThumbnails(TileLoadInfo info)
        {   // this is never overidden by a TileReader
            double min = Double.MaxValue, max = Double.MinValue;
            double tmp_min = 0.0, tmp_max = 0.0;
            int    count = 0;

            this.threadController.ReportThreadStarted(this, "Creating Thumbnails");

            foreach (Tile tile in info.Items)
            {
                if (this.threadController.ThreadAborted)
                {
                    return;
                }

                using (FreeImageAlgorithmsBitmap fib = tile.LoadFreeImageBitmap())
                {
                    Tile.ResizeToThumbnail(fib);

                    if (info.TotalMaxIntensity == 0.0)
                    {
                        // We have to find the max intensity of all the images then linear scale later
                        fib.FindMinMaxIntensity(out tmp_min, out tmp_max);

                        if (tmp_min < min)
                        {
                            min = tmp_min;
                        }

                        if (tmp_max > max)
                        {
                            max = tmp_max;
                        }

                        info.TotalMinIntensity = min;
                        info.TotalMaxIntensity = max;
                        info.ScaleMinIntensity = min;
                        info.ScaleMaxIntensity = max;
                    }

                    lock (tile.ThumbnailLock)
                    {
                        tile.Thumbnail = new FreeImageAlgorithmsBitmap(fib);

                        if (tile.Thumbnail == null)
                        {
                            MessageBox.Show("Error creating thumbnail.");
                        }

                        if (fib.IsGreyScale)
                        {
                            tile.Thumbnail.LinearScaleToStandardType(info.ScaleMinIntensity, info.ScaleMaxIntensity);
                            tile.Thumbnail.SetGreyLevelPalette();
                        }
                    }

                    this.threadController.ReportThreadPercentage(this, "Creating Thumbnails", count++, info.Items.Count);
                }
            }

            // Have to scale the bitmaps for Ros's formats
            if (info.TotalMaxIntensity != 0.0)
            {
                info.FreeImageType = info.Items[0].FreeImageType;
                info.ColorDepth    = info.Items[0].ColorDepth;
            }
            else
            {
                info.ScaleMinIntensity = min;
                info.ScaleMaxIntensity = max;

                count = 0;

                info.FreeImageType = info.Items[0].FreeImageType;
                info.ColorDepth    = info.Items[0].ColorDepth;
            }

            this.threadController.ReportThreadCompleted(this, "Loaded Thumbnails", false);
        }
Esempio n. 3
0
        public void UpdateGraphForLoadedImage()
        {
            TileView viewer = this.mosaicWindow.TileView;

//            CalculateGreyLevelHistogramShape();

            double min_in_images = Double.MaxValue, max_in_images = Double.MinValue;
            double max_posible_intensity = 0.0;

            if (MosaicWindow.MosaicInfo.IsColour)
            {
                return;
            }

            if (viewer.CacheImageAvailiable)
            {
                max_posible_intensity = viewer.CacheImage.MaximumPossibleIntensityValue;
                viewer.CacheImage.FindMinMaxIntensity(out min_in_images, out max_in_images);
            }
            else
            {
                List <Tile> tiles = viewer.GetVisibleTiles();

                if (tiles == null)
                {
                    return;
                }

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

                    FreeImageAlgorithmsBitmap dib = tile.LoadFreeImageBitmap();

                    if (max_posible_intensity == 0.0)
                    {
                        max_posible_intensity = dib.MaximumPossibleIntensityValue;
                    }

                    double min;
                    double max;

                    dib.FindMinMaxIntensity(out min, out max);

                    if (min < min_in_images)
                    {
                        min_in_images = min;
                    }

                    if (max > max_in_images)
                    {
                        max_in_images = max;
                    }

                    dib.Dispose();
                }
            }

            this.min          = min_in_images;
            this.max          = max_in_images;
            this.max_possible = max_posible_intensity;

            this.minNumericUpDown.Minimum = Convert.ToDecimal(0);
            this.maxNumericUpDown.Minimum = Convert.ToDecimal(1);
            this.minNumericUpDown.Maximum = Convert.ToDecimal(this.max_possible - 1);
            this.maxNumericUpDown.Maximum = Convert.ToDecimal(this.max_possible);
            this.minNumericUpDown.Value   = Convert.ToDecimal(this.min);
            this.maxNumericUpDown.Value   = Convert.ToDecimal(this.max);

            this.zedGraphControl.GraphPane.XAxis.Scale.Min = 0;
            this.zedGraphControl.GraphPane.XAxis.Scale.Max = this.max;
            this.zedGraphControl.GraphPane.YAxis.Scale.Min = 0;
            this.zedGraphControl.GraphPane.YAxis.Scale.Max = 255;

            this.cursor1.Position = this.min;
            this.cursor2.Position = this.max;

            this.DisplayPlot();

            this.zedGraphControl.AxisChange();
        }
Esempio n. 4
0
        private void SaveStitchedImage()
        {
            if (System.IO.Path.GetExtension(this.filePath) != ".ics")
            {
                MessageBox.Show("Saving in formats other than ics may result " +
                                "in a loss of infomation.", "Warning");
            }

            if (this.threadController != null)
            {
                this.threadController.ReportThreadStarted(this, "Started Image Export");
            }

            FreeImageAlgorithmsBitmap stitchedImage = this.Stitch(this.saveDialog.ExportWidth,
                                                                  this.saveDialog.ExportHeight);

            if (stitchedImage == null)
            {
                this.FileToLargeError();
                return;
            }

            try
            {
                if (System.IO.Path.GetExtension(this.filePath) != ".ics")
                {
                    if (stitchedImage.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
                    {
                        stitchedImage.ConvertToStandardType(true);  // PRB convert takes double the memory, only do it when necessary
                    }
                    if (this.saveInfoPanel)
                    {
                        stitchedImage.Paste(this.infoBitmap, new Point(20, 20), 256);
                    }

                    //stitchedImage.SaveToFile(this.filePath);  // uses many converts and clones in FIA
                    stitchedImage.Save(this.filePath);  // PRB use a simpler native free_image save
                }
                else
                {
                    // infoBitmap is 8bit for greyscale or 24bit colour
                    // If we are saving a greyscale image with > 8 bits
                    // we need to scale the infoBitmap to the min and max
                    // possible values of the stitchedImage.
                    if (this.saveInfoPanel)
                    {
                        if (MosaicWindow.MosaicInfo.IsGreyScale && MosaicWindow.MosaicInfo.FreeImageType != this.infoBitmap.ImageType)
                        {
                            double min, max;
                            stitchedImage.FindMinMaxIntensity(out min, out max);
                            this.infoBitmap.StretchImageToType(MosaicWindow.MosaicInfo.FreeImageType, max);
                        }

                        stitchedImage.Paste(this.infoBitmap, new Point(20, 20));
                    }

                    IcsFile.SaveToFile(stitchedImage, this.filePath, true);

                    if (MosaicWindow.MosaicInfo.MetaData != null)
                    {
                        IcsFile icsFile = new IcsFile(this.filePath);

                        // We have to add the metadata to reflect the
                        // exported image.
                        //                       if(MosaicWindow.MosaicInfo.MetaData.ContainsKey("extents"))
                        {
                            string extentString = String.Format("{0:#.###e+000} {1:#.###e+000}",
                                                                this.saveDialog.NativeRegionWidth * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel,
                                                                this.saveDialog.NativeRegionHeight * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel);

                            MosaicWindow.MosaicInfo.MetaData["extents"] = extentString;
                            MosaicWindow.MosaicInfo.MetaData["units"]   = "um um";
                        }

//                        if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image physical_sizex"))
                        {
                            string extentString = String.Format("{0:#.###e+000}",
                                                                this.saveDialog.NativeRegionWidth * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel);

                            MosaicWindow.MosaicInfo.MetaData["image physical_sizex"] = extentString;
                        }

                        //                       if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image physical_sizey"))
                        {
                            string extentString = String.Format("{0:#.###e+000}",
                                                                this.saveDialog.NativeRegionHeight * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel);

                            MosaicWindow.MosaicInfo.MetaData["image physical_sizey"] = extentString;
                        }

//                        if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image sizex"))
                        {
                            MosaicWindow.MosaicInfo.MetaData["image sizex"] = stitchedImage.Width.ToString();
                        }

//                        if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image sizey"))
                        {
                            MosaicWindow.MosaicInfo.MetaData["image sizey"] = stitchedImage.Height.ToString();
                        }

                        //                       if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("dimensions"))
                        {
                            string extentString = String.Format("{0} {1}",
                                                                stitchedImage.Width,
                                                                stitchedImage.Height);

                            MosaicWindow.MosaicInfo.MetaData["dimensions"] = extentString;
                        }

                        // Add some metadata
                        MosaicWindow.MosaicInfo.MetaData["processed by"] = String.Format("{0} {1}",
                                                                                         Application.ProductName, Application.ProductVersion);

                        icsFile.AppendHistory(MosaicWindow.MosaicInfo.MetaData);

                        // calculate the um per pixel scale of the saved image
                        double xscale = this.saveDialog.NativeRegionWidth * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel / stitchedImage.Width;
                        double yscale = this.saveDialog.NativeRegionHeight * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel / stitchedImage.Height;

                        icsFile.SetNativeScale(0, 0.0, xscale, "microns");
                        icsFile.SetNativeScale(1, 0.0, yscale, "microns");

                        icsFile.Close();
                    }
                }

                stitchedImage.Dispose();

                if (this.infoBitmap != null)
                {
                    this.infoBitmap.Dispose();
                }

                if (this.threadController != null)
                {
                    this.threadController.ReportThreadCompleted(this, "Exported file", false);
                }

                this.Window.TileView.AllowMouseWheelZoom = true;
                this.Window.ToolStrip.Enabled            = true;
            }
            catch (FreeImageException)
            {
                this.FileToLargeError();

                stitchedImage.Dispose();

                //          this.Export();
            }
        }