Exemple #1
0
        public void Bitwise_method(float[,] pixel_matrix, BinaryWriter bWriter, bool oneframe)
        {
            UInt32        evt;
            UInt32        timestamp;
            ASCIIEncoding asen = new ASCIIEncoding();

            //AEDAT HEADER FOR JAER
            if (oneframe)
            {
                bWriter.Write(asen.GetBytes("#!AER-DAT2.0\r\n"));
                bWriter.Write(asen.GetBytes("# This is a raw AE data file created by saveaerdat.m\r\n"));
                bWriter.Write(asen.GetBytes("# Data format is int32 address, int32 timestamp (8 bytes total), repeated for each event\r\n"));
                bWriter.Write(asen.GetBytes("# Timestamps tick is 1 us\r\n"));
                bWriter.Write(asen.GetBytes("# End of ASCII Header\r\n"));
            }

            UInt32 addr = 0;
            UInt32 ts   = 0;


            for (Int32 i = 0; i < Math.Pow(2, 22); i++)
            {
                //Reverse counter value
                UInt32 reversed_count = Frame_Utils.Reverse32((UInt32)i);
                //Decoder inverted counter value
                int b_xpos            = (int)(reversed_count >> 8) & 0x7f;
                int b_ypos            = (int)(reversed_count >> 15) & 0x7f;
                int bitwise_greyscale = (int)reversed_count & 0xff;
                int matrix_value      = (int)Math.Round((1 - pixel_matrix[b_xpos, b_ypos]) * 256);

                //Compare grayscale, if condition is true generate and event and write in the output file
                if (bitwise_greyscale >= matrix_value)
                {
                    addr      = (UInt32)((127 - b_ypos) << 8 | (127 - b_xpos) << 1 | 1);
                    ts        = ts + (UInt32)this.GetLatency();
                    evt       = (UInt32)((BitConverter.GetBytes(addr)[0] << 24) | BitConverter.GetBytes(addr)[1] << 16 | BitConverter.GetBytes(addr)[2] << 8 | BitConverter.GetBytes(addr)[3]);
                    timestamp = (UInt32)((BitConverter.GetBytes(ts)[0] << 24) | BitConverter.GetBytes(ts)[1] << 16 | BitConverter.GetBytes(ts)[2] << 8 | BitConverter.GetBytes(ts)[3]);
                    bWriter.Write(evt);
                    bWriter.Write(timestamp);
                }
            }
        }
Exemple #2
0
        private void ApplyFilter_Click(object sender, EventArgs e)
        {
            //No image loaded
            if (current_image == null)
            {
                MessageBox.Show("Please Select an Image");
            }
            else
            {
                //Apply filter to image
                Image <Gray, float> Convolved_Image = new Image <Gray, float>(current_image);
                string filter_text = filter_list.Text;

                switch (filter_text)
                {
                case "Sobel Vertical":
                    Convolved_Image = ImageFrame.Convert <Gray, Byte>().Sobel(0, 1, 3).AbsDiff(new Gray(0.0));
                    break;

                case "Sobel Horizontal":
                    Convolved_Image = ImageFrame.Convert <Gray, Byte>().Sobel(1, 0, 3).AbsDiff(new Gray(0.0));
                    break;

                case "Laplacian":
                    Convolved_Image = ImageFrame.Convert <Gray, Byte>().Laplace(3).AbsDiff(new Gray(5.0));
                    break;

                case "Gaussian":
                    Convolved_Image = ImageFrame.Convert <Gray, float>().SmoothGaussian(3);
                    break;
                }

                //Update current Image
                current_image = Convolved_Image.Bitmap;

                //Get Pixel brightness of new image
                Frame_Utils.Get_pixel_bright(current_image, pixel_matrix);

                //Update Picturebox with New Image
                Image_box.Image = current_image;
            }
        }
Exemple #3
0
        //Browse for an image and get pixel brightness for future conversion/modification and update picture box
        private void BrowseImage_Click(object sender, EventArgs e)
        {
            //Open File explorer
            Stream         myStream       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter           = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;
            conversion_algorithms           = new Algorithms((UInt32)eventlatency.Value);
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            //Get Image and rescale its size to 128x128
                            ImageFrame = new Image <Bgr, Byte>((Bitmap)Bitmap.FromFile(openFileDialog.FileName)).Resize(128, 128, 0);
                            Image <Gray, Byte> grayImage = ImageFrame.Convert <Gray, Byte>();
                            current_image = grayImage.Bitmap;
                            //Get brightness of pixels
                            pixel_matrix = new float[current_image.Width, current_image.Height];
                            Frame_Utils.Get_pixel_bright(current_image, pixel_matrix);
                            Image_box.Image    = grayImage.Bitmap;
                            Image_box.SizeMode = PictureBoxSizeMode.StretchImage;
                            Image_box.Refresh();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }