Exemplo n.º 1
0
        private void loadInputImageButton_Click(object sender, EventArgs e)
        {
            Bitmap bInput = Grayscale.ToGrayscale(Bitmap.FromFile(path) as Bitmap);

            inputImagePictureBox.Image = bInput;

            inputImageResolutionTextBox.Text = "" + bInput.Width + " X " + bInput.Height;
        }
Exemplo n.º 2
0
        public static Bitmap Pad(Bitmap image, int newWidth, int newHeight)
        {
            int width  = image.Width;
            int height = image.Height;

            /*
             * It is always guaranteed that,
             *
             *      width < newWidth
             *
             *          and
             *
             *      height < newHeight
             */
            if ((width < newWidth && height < newHeight) ||
                (width < newWidth && height == newHeight) ||
                (width == newWidth && height < newHeight))
            {
                Bitmap paddedImage = Grayscale.CreateGrayscaleImage(newWidth, newHeight);

                BitmapLocker inputImageLocker  = new BitmapLocker(image);
                BitmapLocker paddedImageLocker = new BitmapLocker(paddedImage);

                inputImageLocker.Lock();
                paddedImageLocker.Lock();

                int startPointX = (int)Math.Ceiling((double)(newWidth - width) / (double)2) - 1;
                int startPointY = (int)Math.Ceiling((double)(newHeight - height) / (double)2) - 1;

                for (int y = startPointY; y < (startPointY + height); y++)
                {
                    for (int x = startPointX; x < (startPointX + width); x++)
                    {
                        int xxx = x - startPointX;
                        int yyy = y - startPointY;

                        paddedImageLocker.SetPixel(x, y, inputImageLocker.GetPixel(xxx, yyy));



                        string str = string.Empty;
                    }
                }

                paddedImageLocker.Unlock();
                inputImageLocker.Unlock();

                return(paddedImage);
            }
            else if (width == newWidth && height == newHeight)
            {
                return(image);
            }
            else
            {
                throw new Exception("Pad() -- threw an exception");
            }
        }
        public FourierTransform(Bitmap image)
        {
            ImageBitmap = image;
            Width       = image.Width;
            Height      = image.Height;

            GrayscaleImageInteger = Grayscale.ToGrayscale2(ImageBitmap);
            GrayscaleImageComplex = ImageDataConverter.ToComplex(GrayscaleImageInteger);
        }
Exemplo n.º 4
0
        private void loadButton_Click(object sender, EventArgs e)
        {
            Bitmap bInputImage = Grayscale.ToGrayscale(Bitmap.FromFile(path) as Bitmap);

            int newWidth  = (int)Tools.ToNextPow2((uint)bInputImage.Width);
            int newHeight = (int)Tools.ToNextPow2((uint)bInputImage.Height);

            Bitmap lenaResized = ImageResizer.Resize(bInputImage, newWidth, newHeight);

            inputImagePictureBox.Image = lenaResized as Image;
        }
Exemplo n.º 5
0
        public static double[,] Pad(double[,] image, int newWidth, int newHeight)
        {
            int width  = image.GetLength(0);
            int height = image.GetLength(1);

            /*
             * It is always guaranteed that,
             *
             *      width < newWidth
             *
             *          and
             *
             *      height < newHeight
             */
            if ((width < newWidth && height < newHeight) ||
                (width < newWidth && height == newHeight) ||
                (width == newWidth && height < newHeight))
            {
                double[,] resizedImage = new double[newWidth, newHeight];

                double color = 0.0;

                Grayscale.Fill(resizedImage, color);

                int startPointX = ((newWidth - width) / 2) - 1;
                int startPointY = ((newHeight - height) / 2) - 1;

                for (int y = startPointY; y < startPointY + height; y++)
                {
                    for (int x = startPointX; x < startPointX + width; x++)
                    {
                        int xxx = x - startPointX;
                        int yyy = y - startPointY;
                        resizedImage[x, y] = image[xxx, yyy];
                    }
                }

                return(resizedImage);
            }
            else if (width == newWidth && height == newHeight)
            {
                return(image);
            }
            else
            {
                throw new Exception("Pad() -- threw an exception");
            }
        }
        private void padButton_Click(object sender, EventArgs e)
        {
            Bitmap lena = Grayscale.ToGrayscale(_inputImage);
            Bitmap mask = Grayscale.ToGrayscale(_maskImage);

            ////We must add
            int maxWidth  = (int)Tools.ToNextPow2(Convert.ToUInt32(lena.Width + mask.Width));
            int maxHeight = (int)Tools.ToNextPow2(Convert.ToUInt32(lena.Height + mask.Height));

            Bitmap paddedImage = ImagePadder.Pad(lena, maxWidth, maxHeight);
            Bitmap paddedMask  = ImagePadder.Pad(mask, maxWidth, maxHeight);

            //new PictureBoxForm(paddedImage, paddedMask).ShowDialog();

            inputImagePictureBox.Image = paddedImage;
            paddedMaskPictureBox.Image = paddedMask;
        }
Exemplo n.º 7
0
        public static Bitmap ToBitmap(double[,] input)
        {
            int width  = input.GetLength(0);
            int height = input.GetLength(1);

            Bitmap output = Grayscale.CreateGrayscaleImage(width, height);

            BitmapData data = output.LockBits(new Rectangle(0, 0, width, height),
                                              ImageLockMode.WriteOnly,
                                              output.PixelFormat);

            int pixelSize = System.Drawing.Image.GetPixelFormatSize(PixelFormat.Format8bppIndexed) / 8;

            int offset = data.Stride - width * pixelSize;

            double Min = 0.0;
            double Max = 255.0;

            unsafe
            {
                byte *address = (byte *)data.Scan0.ToPointer();

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        double v = 255 * (input[x, y] - Min) / (Max - Min);

                        byte value = unchecked ((byte)v);

                        for (int c = 0; c < pixelSize; c++, address++)
                        {
                            *address = value;
                        }
                    }

                    address += offset;
                }
            }

            output.UnlockBits(data);

            return(output);
        }
        public static Bitmap ToBitmap(int[,] image)
        {
            int Width = image.GetLength(0);
            int Height = image.GetLength(1);
            int y, x;

            Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed);

            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, Width, Height),
                                                    ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);

            int bytesPerPixel = sizeof(byte);

            unsafe
            {
                byte *address = (byte *)bitmapData.Scan0;

                for (y = 0; y < bitmapData.Height; y++)
                {
                    for (x = 0; x < bitmapData.Width; x++)
                    {
                        //Converting int to an array of bytes
                        byte[] bytes = BitConverter.GetBytes(image[x, y]);//?????????

                        //placing the array of bytes into memory
                        for (int k = 0; k < bytesPerPixel; k++)
                        {
                            address[k] = bytes[k];
                        }

                        address += bytesPerPixel;
                    }

                    address += (bitmapData.Stride - (bitmapData.Width * bytesPerPixel));
                }
            }
            bitmap.UnlockBits(bitmapData);

            Grayscale.SetGrayscalePalette(bitmap);

            return(bitmap);
        }
Exemplo n.º 9
0
        public static int[,] ToGrayscale2(Bitmap colorBitmap)
        {
            Bitmap bmp = Grayscale.ToGrayscale(colorBitmap);

            return(ImageDataConverter.ToInteger(bmp));
        }
Exemplo n.º 10
0
        private void loadInputImageButton_Click(object sender, EventArgs e)
        {
            _inputImage = Grayscale.ToGrayscale(Bitmap.FromFile(imagePath) as Bitmap);

            inputImagePictureBox.Image = _inputImage as Image;
        }