private void btnRead_Click(object sender, EventArgs e)
        {
            DialogResult dRes = openFileDialog.ShowDialog();
            if (dRes == DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;

                txtOutput.Text = txtOutput.Text + "Attempting to read the file '" + fileName + "'...";
                try
                {
                    MatFileReader mfr = new MatFileReader(fileName);
                    txtOutput.Text += "Done!\nMAT-file contains the following:\n";
                    txtOutput.Text += mfr.MatFileHeader.ToString() + "\n";
                    foreach (MLArray mla in mfr.Data)
                    {
                        txtOutput.Text = txtOutput.Text + mla.ContentToString() + "\n";
                    }
                }
                catch (System.IO.IOException)
                {
                    txtOutput.Text = txtOutput.Text + "Invalid MAT-file!\n";
                    MessageBox.Show("Invalid binary MAT-file! Please select a valid binary MAT-file.",
                        "Invalid MAT-file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                    
            }
        }
        private void ConvertMatlabFiles()
        {
            string[] events = Directory.GetFiles(@"C:\Users\Brent\Desktop\Neuro Imaging\BrentExport\sz_fmri");

            foreach (var evt in events)
            {
                var fileName = System.IO.Path.GetFileName(evt);
                var subjId = fileName.Split('_')[0];

                using (StreamWriter sw = new StreamWriter(@"C:\Users\Brent\Desktop\tmp\" + subjId + "_fMRI_mo-adj-mtx.txt"))
                {
                    MatFileReader mtx = new MatFileReader(evt);
                    foreach (var mla in mtx.Data)
                    {
                        var itms = (MLDouble)mla;

                        for (int m = 0; m < 90; m++)
                        {
                            for (int n = 90; n < 180; n += 1)
                            {
                                var val = itms.Get(m, n);
                                if (n == 90)
                                    sw.Write(val.ToString());
                                else
                                    sw.Write("\t" + val.ToString());
                            }
                            sw.WriteLine();
                        }
                    }
                }
            }
        }
Exemple #3
0
        public StereoSystem(string CalibrationMatFile, string CalibrationMatFile_Rectified)
        {
            MatFileReader mfr = new MatFileReader(CalibrationMatFile);
            MatFileReader mfr2 = new MatFileReader(CalibrationMatFile_Rectified);
            double[,] A1 = MLDoubleParser("KK_left_new", mfr2);
            double[,] A2 = MLDoubleParser("KK_right_new", mfr2);
            double[,] kc1 = MLDoubleParser("kc_left", mfr);
            double[,] kc2 = MLDoubleParser("kc_right", mfr);
            double[,] fc1 = MLDoubleParser("fc_left", mfr);
            double[,] fc2 = MLDoubleParser("fc_right", mfr);
            double[,] cc1 = MLDoubleParser("cc_left", mfr);
            double[,] cc2 = MLDoubleParser("cc_right", mfr);
            double[,] R = MLDoubleParser("R", mfr);
            double[,] T = MLDoubleParser("T", mfr);
            double[,] nx = MLDoubleParser("nx", mfr);
            double[,] ny = MLDoubleParser("ny", mfr);
            int ImageWidth = (int)nx[0, 0];
            int ImageHeight = (int)ny[0, 0];

            LeftCam = new CameraParameters(A1, kc1, fc1, cc1, ImageWidth, ImageHeight);
            RightCam = new CameraParameters(A2, kc2, fc2, cc2, ImageWidth, ImageHeight);
            TranslationVector = new Matrix<double>(T);
            RotationMatrix = new Matrix<double>(R);
            DisparityDepthMapMatrix = new Matrix<double>(4, 4);
            ImageSize = new Size(ImageWidth, ImageHeight);

            CvInvoke.cvStereoRectify(
                LeftCam.CameraMatrix.Ptr,
                RightCam.CameraMatrix.Ptr,
                LeftCam.distCoeffs.Ptr,
                RightCam.distCoeffs.Ptr,
                ImageSize,
                RotationMatrix.Ptr,
                TranslationVector.Ptr,
                LeftCam.RectificationTransform.Ptr,
                RightCam.RectificationTransform.Ptr,
                LeftCam.ProjectionMatrix.Ptr,
                RightCam.ProjectionMatrix.Ptr,
                DisparityDepthMapMatrix.Ptr,
                Emgu.CV.CvEnum.STEREO_RECTIFY_TYPE.DEFAULT,
                1,
                Size.Empty,
                ref LeftCam.ROI,
                ref RightCam.ROI);

            LeftCam.UndistortRectifyMap();
            RightCam.UndistortRectifyMap();

            var Variables = new List<MLArray>();
            int[] Dims = {ImageHeight, ImageWidth};
            Variables.Add(MLVariableCreator("LeftMapX", LeftCam.mapx));
            Variables.Add(MLVariableCreator("RightMapX", RightCam.mapx));
            Variables.Add(MLVariableCreator("LeftMapY", LeftCam.mapy));
            Variables.Add(MLVariableCreator("RightMapY", RightCam.mapy));
            var Writer = new MatFileWriter("ImageMap.mat", Variables, false);
            DisparityMapGPU = new GpuImage<Gray, byte>(ImageHeight, ImageWidth);
            DisparityMap = new Image<Gray, byte>(ImageWidth, ImageHeight);
            GPU_Block_Matcher = new GpuStereoBM(NumDisparities, BlockSize);
        }
 private double[][] LoadDict(string dictionaryPath)
 {
     // Read in dictionary.
     MatFileReader mfr = new MatFileReader(dictionaryPath);
     MLDouble ml = mfr.Content["dic"] as MLDouble;
     this.dict_dimension = ml.Dimensions;
     return ml.GetArray();
 }
        /// <summary>
        /// This method provides spikes data.
        /// </summary>
        /// <returns>
        /// Returns the spikes caused by stimuli delivered by the GetStimuli-method. 
        /// 
        /// Dimensions of the returned array:
        /// 1 - Observed cells.
        /// 2 - Detected spikes for each cell.
        /// 3 - Time when spike occurred.
        /// </returns>
        public static double[][][] GetSpikes()
        {
            //var reader = new MatFileReader(@"F:\Development\Uni\Nonlinearities\Data\Long Experiment\spksV6.mat");
            var reader = new MatFileReader(@"..\..\..\Data\Long Experiment\spksV6.mat");
            var spikes = new List<double[][]>();

            reader.Data.ForEach(data => spikes.Add(((MLDouble)data).GetArray()));

            return spikes.ToArray();
        }
        internal ArrayReader(string fileName)
        {
            try
            {
                MatFileReader mfr = new MatFileReader(fileName);
                A = ((MLDouble)(mfr.GetMLArray("A"))).GetArray();
                PP = ((MLDouble)(mfr.GetMLArray("PP"))).GetArray();
                double[][] Q = ((MLDouble)(mfr.GetMLArray("q"))).GetArray();
                q = new double[Q.Length];
                for (int i = 0; i < Q.Length; i++)
                {
                    q[i] = Q[i][0];
                }

                double[][] P = ((MLDouble)mfr.GetMLArray("p")).GetArray();
                p = new double[P.Length];
                for (int i = 0; i < P.Length; i++)
                {
                    p[i] = P[i][0];
                }
                double[][] V = ((MLDouble)mfr.GetMLArray("v")).GetArray();
                v = new double[V.Length];
                for (int i = 0; i < V.Length; i++)
                {
                    v[i] = V[i][0];
                }

                double[][] WW = ((MLDouble)mfr.GetMLArray("w")).GetArray();
                w = new double[WW.Length];
                for (int i = 0; i < WW.Length; i++)
                {
                    w[i] = WW[i][0];
                }
            }
            catch (System.IO.IOException)
            {
                throw new MatlabIOException("Cannot read file");
            }
        }
 /// <summary>
 /// This method provides stimuli data. 
 /// </summary>
 /// <returns>
 /// Returns stimuli which triggered spikes delivered by the GetSpikes-method.
 /// 
 /// Dimension of the returned array:
 /// 1 - Presented frames.
 /// 2 - Presented bars per frame (1 represents white bar, -1 represents black bar).
 /// </returns>
 public static double[][] GetStimuli()
 {
     //var reader = new MatFileReader(@"F:\Development\Uni\Nonlinearities\Data\Long Experiment\msq1D.mat");
     var reader = new MatFileReader(@"..\..\..\Data\Long Experiment\msq1D.mat");
     return ((MLDouble)reader.GetMLArray("msq1D")).GetArray();
 }
        public void TrainModel(string featureFilePath)
        {
            MatFileReader mfr = new MatFileReader(featureFilePath);
            MLSingle ml = mfr.Content["rgbdfea"] as MLSingle;
            int[] dimension = ml.Dimensions;
            double[][] mlArray = MatrixUtil.Transpose(ml.GetArray());

            MLDouble label = mfr.Content["rgbdclabel"] as MLDouble;
            double[] labels = label.GetArray()[0];

            this.TrainModel(labels, mlArray);
        }
Exemple #9
0
 private double[,] MLDoubleParser(string VariableName, MatFileReader mfr)
 {
     MLDouble MLVariable = (mfr.Content[VariableName] as MLDouble);
     return MLDoubleParser(MLVariable);
 }
Exemple #10
0
        // read one frame data of the .mat file type
        private void readOneFrameMat(string currentName, out short Az_bins, out int range_bins, out float[] Ang_plot, out float[] RP_dBm)
        {
            Az_bins = 0;
            range_bins = 0;
            Ang_plot = null;
            RP_dBm = null;

            MatFileReader mfr = new MatFileReader(currentName);
            foreach (MLDouble mld in mfr.Data)
            {
                string name = System.Text.ASCIIEncoding.ASCII.GetString(mld.GetNameToByteArray());
                switch (name)
                {
                    case "Ang_plot":
                        Az_bins = (short)mld.Dimensions[1];
                        Ang_plot = new float[Az_bins];
                        for (int i = 0; i < Az_bins; i++)
                        {
                            Ang_plot[i] = (float)mld.GetReal(i);
                        }                        
                        break;
                    case "RP_dBm":
                        range_bins = (short)mld.Dimensions[0];
                        Az_bins = (short)mld.Dimensions[1];
                        RP_dBm = new float[range_bins * Az_bins];
                        int k = 0;
                        for (int i = 0; i < range_bins; i++)
                        {
                            for (int j = 0; j < Az_bins; j++)
                            {
                                RP_dBm[k++] = (float)mld.GetReal(i + j * range_bins);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
        }
Exemple #11
0
        private void readParametersMat(string parameterName, out float Ang_endpt, out float MagMax, out float MagMin, out float fft_dR)
        {
            Ang_endpt = 0;
            MagMax = 0;
            MagMin = 0;
            fft_dR = 0;

            MatFileReader mfr = new MatFileReader(parameterName);
            foreach (MLArray mla in mfr.Data)
            {
                if (mla is MLDouble)
                {
                    MLDouble mld = mla as MLDouble;
                    string name = System.Text.ASCIIEncoding.ASCII.GetString(mld.GetNameToByteArray());
                    switch (name)
                    {
                        case "Ang_endpt":
                            Ang_endpt = (float)mld.Get(0, 0);
                            break;
                        case "MagMax":
                            MagMax = (float)mld.Get(0, 0);
                            break;
                        case "MagMin":
                            MagMin = (float)mld.Get(0, 0);
                            break;
                        case "fft_dR":
                            fft_dR = (float)mld.Get(0, 0);
                            break;
                        default:
                            break;
                    }
                }
            }            
        }