Example #1
0
        public static Bitmap[] gdcmBitmap2Bitmap(gdcm.Bitmap bmjpeg2000)
        {
            // przekonwertuj teraz na bitmapę C#
            uint cols = bmjpeg2000.GetColumns();
            uint rows = bmjpeg2000.GetRows();

            // wartość zwracana - tyle obrazków, ile warstw
            Bitmap[] ret = new Bitmap[1];


            // bufor
            byte[] bufor = new byte[bmjpeg2000.GetBufferLength()];
            if (!bmjpeg2000.GetBuffer(bufor))
            {
                throw new Exception("błąd pobrania bufora");
            }

            // w strumieniu na każdy piksel 2 bajty; tutaj LittleEndian (mnie znaczący bajt wcześniej)

            Bitmap X = new Bitmap((int)rows / 3, (int)cols / 3);

            double[,] Y = new double[rows, cols];
            double m      = 0;
            int    stride = (int)cols * 4;
            int    size   = (int)rows * stride;

            for (int r = 0; r < bufor.Length - 1; r++)
            {
                // przeskalujemy potem do wartości max.
                if (bufor[r] * 256 + bufor[r + 1] > m)
                {
                    m = bufor[r] * 256 + bufor[r + 1];
                }
            }

            // wolniejsza metoda tworzenia bitmapy
            for (int r = 0; r < rows / 3; r++)
            {
                for (int c = 0; c < cols / 3; c++)
                {
                    int index = c * 3 * stride + 3 * r * 3;

                    if (index + 2 < bufor.Length)
                    {
                        int red   = (int)(255 * (bufor[index] * 256 + bufor[index + 1]) / m);
                        int green = (int)(255 * (bufor[index + 1] * 256 + bufor[index + 2]) / m);
                        int blue  = (int)(255 * (bufor[index + 2] * 256 + bufor[index + 3]) / m);
                        X.SetPixel(r, c, Color.FromArgb(red, green, blue));
                    }
                }
            }
            // kolejna bitmapa
            ret[0] = X;

            return(ret);
        }
Example #2
0
        public static Bitmap[] gdcmBitmap2Bitmap(gdcm.Bitmap bmjpeg2000)
        {
            // przekonwertuj teraz na bitmapę C#
            uint cols   = bmjpeg2000.GetDimension(0);
            uint rows   = bmjpeg2000.GetDimension(1);
            uint layers = bmjpeg2000.GetDimension(2);

            // wartość zwracana - tyle obrazków, ile warstw
            Bitmap[] ret = new Bitmap[layers];


            // bufor
            byte[] bufor = new byte[bmjpeg2000.GetBufferLength()];
            if (!bmjpeg2000.GetBuffer(bufor))
            {
                throw new Exception("błąd pobrania bufora");
            }

            // w strumieniu na każdy piksel 2 bajty; tutaj LittleEndian (mnie znaczący bajt wcześniej)
            for (uint l = 0; l < layers; l++)
            {
                Bitmap X = new Bitmap((int)cols, (int)rows);
                double[,] Y = new double[cols, rows];
                double m = 0;

                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < cols; c++)
                    {
                        // współrzędne w strumieniu
                        int j = ((int)(l * rows * cols) + (int)(r * cols) + (int)c) * 2;
                        Y[r, c] = (double)bufor[j + 1] * 256 + (double)bufor[j];
                        // przeskalujemy potem do wartości max.
                        if (Y[r, c] > m)
                        {
                            m = Y[r, c];
                        }
                    }
                }

                // wolniejsza metoda tworzenia bitmapy
                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < cols; c++)
                    {
                        int f = (int)(255 * (Y[r, c] / m));
                        X.SetPixel(c, r, Color.FromArgb(f, f, f));
                    }
                }
                // kolejna bitmapa
                ret[l] = X;
            }
            return(ret);
        }
Example #3
0
        public static System.Drawing.Bitmap[] gdcmBitmap2Bitmap(gdcm.Bitmap bmjpeg2000)
        {
            uint columns = bmjpeg2000.GetDimension(0);
            uint rows    = bmjpeg2000.GetDimension(1);

            uint layers = bmjpeg2000.GetDimension(2);

            System.Drawing.Bitmap[] ret = new System.Drawing.Bitmap[layers];

            byte[] bufor = new byte[bmjpeg2000.GetBufferLength()];
            if (!bmjpeg2000.GetBuffer(bufor))
            {
                throw new Exception("Błąd pobrania bufora");
            }

            for (uint l = 0; l < layers; l++)
            {
                System.Drawing.Bitmap X = new System.Drawing.Bitmap((int)columns, (int)rows);
                double[,] Y = new double[columns, rows];
                double m = 0;

                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < columns; c++)
                    {
                        int j = ((int)(l * rows * columns) + (int)(r * columns) + (int)c) * 2;
                        Y[r, c] = (double)bufor[j + 1] * 256 + (double)bufor[j];
                        if (Y[r, c] > m)
                        {
                            m = Y[r, c];
                        }
                    }
                }

                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < columns; c++)
                    {
                        int f = (int)(255 * (Y[r, c] / m));
                        X.SetPixel(c, r, System.Drawing.Color.FromArgb(f, f, f));
                    }
                }
                ret[l] = X;
            }
            return(ret);
        }