Beispiel #1
0
        private double[, ,] BSQ_LoadImageSingleBand(ImageSubWindow currentWindowToLoad, int bandIndex)
        {
            if (currentWindowToLoad == null)
            {
                currentWindowToLoad = new ImageSubWindow()
                {
                    xStart = 0, xEnd = Header.Samples, yStart = 0, yEnd = Header.Lines
                };
            }
            //..............................................................
            ImageVector = new double[currentWindowToLoad.xEnd - currentWindowToLoad.xStart, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, 1];
            using (BinaryReader imageReader = new BinaryReader(new FileStream(_PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                imageReader.BaseStream.Position += bandIndex * Header.Lines * Header.Samples * PixelType.Size();

                imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Samples * PixelType.Size();
                //................................................................................
                for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
                {
                    imageReader.BaseStream.Position += currentWindowToLoad.xStart * PixelType.Size();
                    for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                    {
                        ImageVector[s, l, 0] = LoadPixelBandValue(imageReader);
                    }
                    if (currentWindowToLoad.xEnd < Header.Samples)
                    {
                        int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                        imageReader.BaseStream.Position += remainderSamples * PixelType.Size();
                    }
                }
                //.................................................................
            }
            return(ImageVector);
        }
Beispiel #2
0
 private double[, ,] BIP_LoadImageCube_withSubWindow(ImageSubWindow currentWindowToLoad)
 {
     double[, ,] ImagePixels = new double[currentWindowToLoad.xEnd - currentWindowToLoad.xStart, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, Header.Bands];
     using (BinaryReader imageReader = new BinaryReader(new FileStream(_PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
     {
         // Set Seek Position -- Pixels NOT needed @ Start
         imageReader.BaseStream.Position += (currentWindowToLoad.yStart * Header.Samples * Header.Bands * PixelType.Size()); // Skip Not needed LINES to reach the start line
         //...............................................................................................
         for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
         {
             if (currentWindowToLoad.xStart != 0)
             {
                 imageReader.BaseStream.Position += (currentWindowToLoad.xStart * Header.Bands * PixelType.Size());// Skip Not needed SAMPLES to reach the start
             }
             for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
             {
                 for (int b = 0; b < Header.Bands; b++)
                 {
                     ImagePixels[s - currentWindowToLoad.xStart, l - currentWindowToLoad.yStart, b] = LoadPixelBandValue(imageReader);
                 }
                 // Set Seek Position -- (CurrentWindowToLoad.xEnd - Header.Samples) * sizeof(byte)
                 if (currentWindowToLoad.xEnd < Header.Samples)
                 {
                     int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                     imageReader.BaseStream.Position += remainderSamples * Header.Bands * PixelType.Size();
                 }
             }
         }
     }
     ImageVector = ImagePixels;
     return(ImageVector);
 }
Beispiel #3
0
 public override float[] LoadImageCube_withSubWindow_InSingleArray(ImageSubWindow currentWindowToLoad)
 {
     float[] ImagePixels = new float[(currentWindowToLoad.xEnd - currentWindowToLoad.xStart) * (currentWindowToLoad.yEnd - currentWindowToLoad.yStart) * Header.Bands];
     using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
     {
         int valueCounter = 0;
         // Set Seek Position -- Pixels NOT needed @ Start
         imageReader.BaseStream.Position += (currentWindowToLoad.yStart * Header.Samples * Header.Bands * PixelType.Size()); // Skip Not needed LINES to reach the start line
         //...............................................................................................
         for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
         {
             if (currentWindowToLoad.xStart != 0)
             {
                 imageReader.BaseStream.Position += (currentWindowToLoad.xStart * Header.Bands * PixelType.Size());// Skip Not needed SAMPLES to reach the start
             }
             for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
             {
                 for (int b = 0; b < Header.Bands; b++)
                 {
                     // ImagePixels[s - currentWindowToLoad.xStart, l - currentWindowToLoad.yStart, b] = BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                     ImagePixels[valueCounter++] = (float)BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                 }
                 // Set Seek Position -- (CurrentWindowToLoad.xEnd - Header.Samples) * sizeof(byte)
                 if (currentWindowToLoad.xEnd < Header.Samples)
                 {
                     int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                     imageReader.BaseStream.Position += remainderSamples * Header.Bands * PixelType.Size();
                 }
             }
         }
     }
     return(ImagePixels);
 }
Beispiel #4
0
        protected void WriteSubWindowHeader(ImageSubWindow currentWindowToLoad, string outputFilePath)
        {
            string newHeaderFilePath = HeaderInfo.GenerateHeaderFilePathFromImage(outputFilePath);

            using (StreamReader inforeader = new StreamReader(Header.HeaderFilePath))
            {
                using (StreamWriter infoWriter = new StreamWriter(newHeaderFilePath, false, Encoding.UTF8))
                {
                    while (!inforeader.EndOfStream)
                    {
                        string currentLine = inforeader.ReadLine();
                        if (currentLine.ToLower().Contains("samples"))
                        {
                            string[] currentLineParts = currentLine.Split('=');
                            infoWriter.Write(currentLineParts[0] + " = ");
                            infoWriter.WriteLine((currentWindowToLoad.xEnd - currentWindowToLoad.xStart));
                        }
                        else if (currentLine.ToLower().Contains("lines"))
                        {
                            string[] currentLineParts = currentLine.Split('=');
                            infoWriter.Write(currentLineParts[0] + " = ");
                            infoWriter.WriteLine((currentWindowToLoad.yEnd - currentWindowToLoad.yStart));
                        }
                        else
                        {
                            infoWriter.WriteLine(currentLine);
                        }
                    }
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Load a sub section of the hyperspectral image with ONLY a Single band.
 /// </summary>
 /// <param name="bandIndex">A zero based index of the band required for loading</param>
 /// <param name="currentWindowToLoad">The required region of the image to be loaded</param>
 /// <returns>The 3-dimentional array of the sub section of the Hyperspectral image loaded </returns>
 public double[, ,] LoadImageSingleBand(int bandIndex, ImageSubWindow currentWindowToLoad)
 {
     if (bandIndex < 0)
     {
         throw new Exception("bandIndex is less than zero");
     }
     if (bandIndex >= Header.Bands)
     {
         throw new Exception("bandIndex exceeded the image available bands");
     }
     ImageVector = currentFormateObj.LoadImageSingleBand(bandIndex, currentWindowToLoad);
     return(ImageVector);
 }
Beispiel #6
0
 public double[, ,] LoadImageSingleBand(ImageSubWindow currentWindowToLoad, int bandIndex)
 {
     if (Header.Interleave == Interleave.BSQ)
     {
         return(BSQ_LoadImageSingleBand(currentWindowToLoad, bandIndex));
     }
     else if (Header.Interleave == Interleave.BIL)
     {
         return(BIL_LoadImageSingleBand(currentWindowToLoad, bandIndex));
     }
     else if (Header.Interleave == Interleave.BIP)
     {
         return(BIP_LoadImageSingleBand(currentWindowToLoad, bandIndex));
     }
     return(null);
 }
Beispiel #7
0
 public double[, ,] LoadImageCube_withSubWindow(ImageSubWindow currentWindowToLoad)
 {
     if (Header.Interleave == Interleave.BSQ)
     {
         return(BSQ_LoadImageCube_withSubWindow(currentWindowToLoad));
     }
     else if (Header.Interleave == Interleave.BIL)
     {
         return(BIL_LoadImageCube_withSubWindow(currentWindowToLoad));
     }
     else if (Header.Interleave == Interleave.BIP)
     {
         return(BIP_LoadImageCube_withSubWindow(currentWindowToLoad));
     }
     else
     {
         return(null);
     }
 }
Beispiel #8
0
        public override void WriteImageCube_withSubWindow(ImageSubWindow currentWindowToLoad, string outputFilePath)
        {
            // Int16[, ,] ImageVector = new Int16[Header.Bands, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, currentWindowToLoad.xEnd - currentWindowToLoad.xStart];
            BinaryWriter imageWriter = new BinaryWriter(new FileStream(outputFilePath, FileMode.Create));

            using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                for (int b = 0; b < Header.Bands; b++)
                {
                    long currentBandStartPosition = imageReader.BaseStream.Position;
                    //Set Seek Position -- CurrentWindowToLoad.yStart * Header.Samples * sizeof(byte)
                    imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Samples * PixelType.Size();
                    //.................................................................
                    for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
                    {
                        //Set Seek Position -- CurrentWindowToLoad.xStart * sizeof(byte)
                        imageReader.BaseStream.Position += currentWindowToLoad.xStart * PixelType.Size();

                        for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                        {
                            // ImageVector[b, l - currentWindowToLoad.yStart, s - currentWindowToLoad.xStart] = (Int16)BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                            BinaryPixelConverter.WritePixelValue(imageWriter, imageReader, Header.ByteOrder, PixelType);
                        }
                        //Set Seek Position -- (CurrentWindowToLoad.xEnd - Header.Samples) * sizeof(byte)
                        if (currentWindowToLoad.xEnd < Header.Samples)
                        {
                            int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                            imageReader.BaseStream.Position += remainderSamples * PixelType.Size();
                        }
                    }
                    //Set Seek Position -- (CurrentWindowToLoad.yEnd - Header.Lines) * Header.Samples * sizeof(byte)
                    if (currentWindowToLoad.yEnd < Header.Lines)
                    {
                        int remainderlines = Header.Lines - currentWindowToLoad.yEnd;
                        imageReader.BaseStream.Position += remainderlines * Header.Samples * PixelType.Size();
                    }
                }
            }
            imageWriter.Close();
            WriteSubWindowHeader(currentWindowToLoad, outputFilePath);
            return;
        }
Beispiel #9
0
        //..............................................................
        public override void WriteImageCube_withSubWindow(ImageSubWindow currentWindowToLoad, string outputFilePath)
        {
            //double[, ,] ImageVector = new double[currentWindowToLoad.xEnd - currentWindowToLoad.xStart, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, Header.Bands];
            BinaryWriter imageWriter = new BinaryWriter(new FileStream(outputFilePath, FileMode.Create));

            using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                //  Set Seek Position -- Skip NON required Lines
                imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Bands * Header.Samples * PixelType.Size();
                //........................................................
                for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
                {
                    for (int b = 0; b < Header.Bands; b++)
                    {
                        //Set Seek Position -- SKIP NON Needed Samples @ Start
                        imageReader.BaseStream.Position += currentWindowToLoad.xStart * PixelType.Size();
                        //.................................................................
                        for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                        {
                            //--ImageVector[s - currentWindowToLoad.xStart, l - currentWindowToLoad.yStart, b] = BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                            BinaryPixelConverter.WritePixelValue(imageWriter, imageReader, Header.ByteOrder, PixelType);
                        }
                        //Set Seek Position -- SKIP NON Needed Samples @ END
                        if (currentWindowToLoad.xEnd < Header.Samples)
                        {
                            int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                            imageReader.BaseStream.Position += remainderSamples * PixelType.Size();
                        }
                    }
                    //Set Seek Position -- SKIP NON Needed Lines @ END
                    if (currentWindowToLoad.yEnd < Header.Lines)
                    {
                        int remainderlines = Header.Lines - currentWindowToLoad.yEnd;
                        imageReader.BaseStream.Position += remainderlines * Header.Samples * PixelType.Size();
                    }
                }
            }
            imageWriter.Close();
            WriteSubWindowHeader(currentWindowToLoad, outputFilePath);
            return;
        }
Beispiel #10
0
 public override double[, ,] LoadImageSingleBand(int bandIndex, ImageSubWindow currentWindowToLoad)
 {
     if (currentWindowToLoad == null)
     {
         currentWindowToLoad = new ImageSubWindow()
         {
             xStart = 0, xEnd = Header.Samples, yStart = 0, yEnd = Header.Lines
         };
     }
     //..............................................................
     double[, ,] ImageVector = new double[currentWindowToLoad.xEnd - currentWindowToLoad.xStart, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, 1];
     using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
     {
         imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Samples * Header.Bands * PixelType.Size();
         //....................................................................................
         for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
         {
             //.................................................................................
             imageReader.BaseStream.Position += currentWindowToLoad.xStart * Header.Bands * PixelType.Size();
             for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
             {
                 imageReader.BaseStream.Position += bandIndex * PixelType.Size();
                 ImageVector[s, l, 0]             = BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                 if (bandIndex < (Header.Bands - 1))
                 {
                     int remainderBands = Header.Bands - (bandIndex + 1);
                     imageReader.BaseStream.Position += remainderBands * PixelType.Size();
                 }
             }
             if (currentWindowToLoad.xEnd < Header.Samples)
             {
                 int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                 imageReader.BaseStream.Position += remainderSamples * Header.Bands * PixelType.Size();
             }
         }
         //.................................................................
     }
     return(ImageVector);
 }
Beispiel #11
0
 public override float[] LoadImageCube_withSubWindow_InSingleArray(ImageSubWindow currentWindowToLoad)
 {
     float[] ImageVector = new float[(currentWindowToLoad.xEnd - currentWindowToLoad.xStart) * (currentWindowToLoad.yEnd - currentWindowToLoad.yStart) * Header.Bands];
     using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
     {
         int valueCounter = 0;
         //  Set Seek Position -- Skip NON required Lines
         imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Bands * Header.Samples * PixelType.Size();
         //........................................................
         for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
         {
             for (int b = 0; b < Header.Bands; b++)
             {
                 //Set Seek Position -- SKIP NON Needed Samples @ Start
                 imageReader.BaseStream.Position += currentWindowToLoad.xStart * PixelType.Size();
                 //.................................................................
                 for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                 {
                     //ImageVector[s - currentWindowToLoad.xStart, l - currentWindowToLoad.yStart, b] = BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                     ImageVector[valueCounter++] = (float)BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                 }
                 //Set Seek Position -- SKIP NON Needed Samples @ END
                 if (currentWindowToLoad.xEnd < Header.Samples)
                 {
                     int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                     imageReader.BaseStream.Position += remainderSamples * PixelType.Size();
                 }
             }
             //Set Seek Position -- SKIP NON Needed Lines @ END
             if (currentWindowToLoad.yEnd < Header.Lines)
             {
                 int remainderlines = Header.Lines - currentWindowToLoad.yEnd;
                 imageReader.BaseStream.Position += remainderlines * Header.Samples * PixelType.Size();
             }
         }
     }
     return(ImageVector);
 }
Beispiel #12
0
        public override float[] LoadImageCube_withSubWindow_InSingleArray(ImageSubWindow currentWindowToLoad)
        {
            float[] ImageVector = new float[(currentWindowToLoad.xEnd - currentWindowToLoad.xStart) * (currentWindowToLoad.yEnd - currentWindowToLoad.yStart) * Header.Bands];
            using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                long valueCounter = 0;
                for (int b = 0; b < Header.Bands; b++)
                {
                    long currentBandStartPosition = imageReader.BaseStream.Position;
                    //Set Seek Position -- CurrentWindowToLoad.yStart * Header.Samples * sizeof(byte)
                    imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Samples * PixelType.Size();
                    //.................................................................
                    for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
                    {
                        //Set Seek Position -- CurrentWindowToLoad.xStart * sizeof(byte)
                        imageReader.BaseStream.Position += currentWindowToLoad.xStart * PixelType.Size();

                        for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                        {
                            ImageVector[valueCounter++] = (float)BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                        }
                        //Set Seek Position -- (CurrentWindowToLoad.xEnd - Header.Samples) * sizeof(byte)
                        if (currentWindowToLoad.xEnd < Header.Samples)
                        {
                            int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                            imageReader.BaseStream.Position += remainderSamples * PixelType.Size();
                        }
                    }
                    //Set Seek Position -- (CurrentWindowToLoad.yEnd - Header.Lines) * Header.Samples * sizeof(byte)
                    if (currentWindowToLoad.yEnd < Header.Lines)
                    {
                        int remainderlines = Header.Lines - currentWindowToLoad.yEnd;
                        imageReader.BaseStream.Position += remainderlines * Header.Samples * PixelType.Size();
                    }
                }
            }
            return(ImageVector);
        }
Beispiel #13
0
        //.....................................................................................
        private double[, ,] BSQ_LoadImageCube_withSubWindow(ImageSubWindow currentWindowToLoad)
        {
            ImageVector = new double[currentWindowToLoad.xEnd - currentWindowToLoad.xStart, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, Header.Bands];
            using (BinaryReader imageReader = new BinaryReader(new FileStream(_PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                for (int b = 0; b < Header.Bands; b++)
                {
                    long currentBandStartPosition = imageReader.BaseStream.Position;
                    //Set Seek Position -- CurrentWindowToLoad.yStart * Header.Samples * sizeof(byte)
                    imageReader.BaseStream.Position += currentWindowToLoad.yStart * Header.Samples * PixelType.Size();
                    //.................................................................
                    for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
                    {
                        //Set Seek Position -- CurrentWindowToLoad.xStart * sizeof(byte)
                        imageReader.BaseStream.Position += currentWindowToLoad.xStart * PixelType.Size();

                        for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                        {
                            ImageVector[s - currentWindowToLoad.xStart, l - currentWindowToLoad.yStart, b] = LoadPixelBandValue(imageReader);
                        }
                        //Set Seek Position -- (CurrentWindowToLoad.xEnd - Header.Samples) * sizeof(byte)
                        if (currentWindowToLoad.xEnd < Header.Samples)
                        {
                            int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                            imageReader.BaseStream.Position += remainderSamples * PixelType.Size();
                        }
                    }
                    //Set Seek Position -- (CurrentWindowToLoad.yEnd - Header.Lines) * Header.Samples * sizeof(byte)
                    if (currentWindowToLoad.yEnd < Header.Lines)
                    {
                        int remainderlines = Header.Lines - currentWindowToLoad.yEnd;
                        imageReader.BaseStream.Position += remainderlines * Header.Samples * PixelType.Size();
                    }
                }
            }
            return(ImageVector);
        }
Beispiel #14
0
        //................................................................
        public override void WriteImageCube_withSubWindow(ImageSubWindow currentWindowToLoad, string outputFilePath)
        {
            //  double[, ,] ImagePixels = new double[currentWindowToLoad.xEnd - currentWindowToLoad.xStart, currentWindowToLoad.yEnd - currentWindowToLoad.yStart, Header.Bands];
            BinaryWriter imageWriter = new BinaryWriter(new FileStream(outputFilePath, FileMode.Create));

            using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                // Set Seek Position -- Pixels NOT needed @ Start
                imageReader.BaseStream.Position += (currentWindowToLoad.yStart * Header.Samples * Header.Bands * PixelType.Size()); // Skip Not needed LINES to reach the start line
                //...............................................................................................
                for (int l = currentWindowToLoad.yStart; l < Header.Lines && l < currentWindowToLoad.yEnd; l++)
                {
                    if (currentWindowToLoad.xStart != 0)
                    {
                        imageReader.BaseStream.Position += (currentWindowToLoad.xStart * Header.Bands * PixelType.Size());// Skip Not needed SAMPLES to reach the start
                    }
                    for (int s = currentWindowToLoad.xStart; s < Header.Samples && s < currentWindowToLoad.xEnd; s++)
                    {
                        for (int b = 0; b < Header.Bands; b++)
                        {
                            // ImagePixels[s - currentWindowToLoad.xStart, l - currentWindowToLoad.yStart, b] = BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType);
                            BinaryPixelConverter.WritePixelValue(imageWriter, imageReader, Header.ByteOrder, PixelType);
                        }
                        // Set Seek Position -- (CurrentWindowToLoad.xEnd - Header.Samples) * sizeof(byte)
                        if (currentWindowToLoad.xEnd < Header.Samples)
                        {
                            int remainderSamples = Header.Samples - currentWindowToLoad.xEnd;
                            imageReader.BaseStream.Position += remainderSamples * Header.Bands * PixelType.Size();
                        }
                    }
                }
            }
            imageWriter.Close();
            WriteSubWindowHeader(currentWindowToLoad, outputFilePath);
            return;
        }
Beispiel #15
0
 public abstract double[, ,] LoadImageSingleBand(int bandIndex, ImageSubWindow currentWindowToLoad);
Beispiel #16
0
 /// <summary>
 /// Loads a sub section of the Hyperspectral image into a 3-dimensional array,specified by the parameter. Saved in the Property : ImageVector
 /// </summary>
 /// <param name="currentWindowToLoad">The required region of the image to be loaded</param>
 /// <returns>The 3-dimentional array of the sub section of the Hyperspectral image loaded </returns>
 public double[, ,] LoadImageCube_withSubWindow(ImageSubWindow currentWindowToLoad)
 {
     ImageVector = currentFormateObj.LoadImageCube_withSubWindow(currentWindowToLoad);
     return(ImageVector);
 }
Beispiel #17
0
 public abstract double[, ,] LoadImageCube_withSubWindow(ImageSubWindow currentWindowToLoad);
Beispiel #18
0
 public abstract float[] LoadImageCube_withSubWindow_InSingleArray(ImageSubWindow currentWindowToLoad);
Beispiel #19
0
 /// <summary>
 /// Loads a sub section of the Hyperspectral image into a 1-dimensional array,specified by the parameter.(rows then columns)
 /// </summary>
 /// <param name="currentWindowToLoad">The required region of the image to be loaded</param>
 /// <returns>The 1-dimentional array of the sub section of the Hyperspectral image loaded </returns>
 public float[] LoadImageCube_withSubWindow_InSingleArray(ImageSubWindow currentWindowToLoad)
 {
     return(currentFormateObj.LoadImageCube_withSubWindow_InSingleArray(currentWindowToLoad));
 }
Beispiel #20
0
        /// <summary>
        /// Loads the Whole Image as a 3-Dimensional Array [X,Y,Z], inwhich the Z axis is only one value
        /// X: is the number od Samples (width)
        /// Y: is the Number of Lines (height)
        /// Z: is the number of Bands (Z-axis) ONLY ONE
        /// </summary>
        /// <param name="pictureFilepath">the absolute path of the (.dat) file</param>
        /// /// <param name="CurrentWindowToLoad">a window object identifing the part of the image cube required</param>
        /// <param name="bandIndex"> the index of the band required</param>
        /// <returns>3-Dimensional Array [X,Y,Z] containing the image window data cube,inwhich the Z axis is only one value</returns>
        public static double[, ,] LoadImageBandInMemory(string pictureFilepath, ImageSubWindow CurrentWindowToLoad, int bandIndex)
        {
            HeaderInfo info = LoadHeaderFile(pictureFilepath);
            DataType   currentReadingType = GetImageBinaryFormatFromHeaderInfo(info);

            if (CurrentWindowToLoad == null)
            {
                CurrentWindowToLoad = new ImageSubWindow()
                {
                    xStart = 0, xEnd = info.Samples, yStart = 0, yEnd = info.Lines
                };
            }
            //..............................................................
            double[, ,] ImagePixels = new double[CurrentWindowToLoad.xEnd - CurrentWindowToLoad.xStart, CurrentWindowToLoad.yEnd - CurrentWindowToLoad.yStart, 1];
            using (BinaryReader imageReader = new BinaryReader(new FileStream(pictureFilepath, FileMode.Open)))
            {
                #region Set Seek BAND Position -- CurrentWindowToLoad.yStart * info.Samples * sizeof(byte)
                switch (currentReadingType)
                {
                case DataType.uint8:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(byte);
                    break;

                case DataType.int16:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(Int16);
                    break;

                case DataType.int32:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(Int32);
                    break;

                case DataType.single:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(Single);
                    break;

                case DataType.envidouble:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(double);
                    break;

                case DataType.uint32:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(UInt32);
                    break;

                case DataType.int64:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(Int64);
                    break;

                case DataType.uint16:
                    imageReader.BaseStream.Position += bandIndex * info.Lines * info.Samples * sizeof(UInt16);
                    break;

                default:
                    break;
                }


                #endregion
                int  b = 0;
                long currentBandStartPosition = imageReader.BaseStream.Position;
                #region Set Seek Position -- CurrentWindowToLoad.yStart * info.Samples * sizeof(byte)
                switch (currentReadingType)
                {
                case DataType.uint8:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(byte);
                    break;

                case DataType.int16:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(Int16);
                    break;

                case DataType.int32:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(Int32);
                    break;

                case DataType.single:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(Single);
                    break;

                case DataType.envidouble:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(double);
                    break;

                case DataType.uint32:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(UInt32);
                    break;

                case DataType.int64:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(Int64);
                    break;

                case DataType.uint16:
                    imageReader.BaseStream.Position += CurrentWindowToLoad.yStart * info.Samples * sizeof(UInt16);
                    break;

                default:
                    break;
                }


                #endregion
                //.................................................................
                #region Read Pixel Lines
                for (int l = CurrentWindowToLoad.yStart; l < info.Lines && l < CurrentWindowToLoad.yEnd; l++)
                {
                    #region Set Seek Position -- CurrentWindowToLoad.xStart * sizeof(byte)
                    switch (currentReadingType)
                    {
                    case DataType.uint8:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(byte);
                        break;

                    case DataType.int16:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(Int16);
                        break;

                    case DataType.int32:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(Int32);
                        break;

                    case DataType.single:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(Single);
                        break;

                    case DataType.envidouble:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(double);
                        break;

                    case DataType.uint32:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(UInt32);
                        break;

                    case DataType.int64:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(Int64);
                        break;

                    case DataType.uint16:
                        imageReader.BaseStream.Position += CurrentWindowToLoad.xStart * sizeof(UInt16);
                        break;

                    default:
                        break;
                    }


                    #endregion
                    for (int s = CurrentWindowToLoad.xStart; s < info.Samples && s < CurrentWindowToLoad.xEnd; s++)
                    {
                        ImagePixels[s, l, b] = LoadPixelBandValue(currentReadingType, imageReader);
                    }
                    #region Set Seek Position -- (CurrentWindowToLoad.xEnd - info.Samples) * sizeof(byte)
                    if (CurrentWindowToLoad.xEnd < info.Samples)
                    {
                        int remainderSamples = info.Samples - CurrentWindowToLoad.xEnd;
                        switch (currentReadingType)
                        {
                        case DataType.uint8:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(byte);
                            break;

                        case DataType.int16:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(Int16);
                            break;

                        case DataType.int32:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(Int32);
                            break;

                        case DataType.single:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(Single);
                            break;

                        case DataType.envidouble:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(double);
                            break;

                        case DataType.uint32:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(UInt32);
                            break;

                        case DataType.int64:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(Int64);
                            break;

                        case DataType.uint16:
                            imageReader.BaseStream.Position += remainderSamples * sizeof(UInt16);
                            break;

                        default:
                            break;
                        }
                    }
                    #endregion
                }
                #endregion
                //.................................................................
                #region Set Seek Position -- (CurrentWindowToLoad.yEnd - info.Lines) * info.Samples * sizeof(byte)
                if (CurrentWindowToLoad.yEnd < info.Lines)
                {
                    int remainderlines = info.Lines - CurrentWindowToLoad.yEnd;
                    switch (currentReadingType)
                    {
                    case DataType.uint8:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(byte);
                        break;

                    case DataType.int16:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(Int16);
                        break;

                    case DataType.int32:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(Int32);
                        break;

                    case DataType.single:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(Single);
                        break;

                    case DataType.envidouble:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(double);
                        break;

                    case DataType.uint32:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(UInt32);
                        break;

                    case DataType.int64:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(Int64);
                        break;

                    case DataType.uint16:
                        imageReader.BaseStream.Position += remainderlines * info.Samples * sizeof(UInt16);
                        break;

                    default:
                        break;
                    }
                }

                #endregion
            }
            return(ImagePixels);
        }
Beispiel #21
0
 public abstract void WriteImageCube_withSubWindow(ImageSubWindow currentWindowToLoad, string outputFilePath);