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 += 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] = BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType); } if (currentWindowToLoad.xEnd < Header.Samples) { int remainderSamples = Header.Samples - currentWindowToLoad.xEnd; imageReader.BaseStream.Position += remainderSamples * PixelType.Size(); } } //................................................................. } return(ImageVector); }
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); }
public override Int16[, ,] LoadRotatedImageCube() { Int16[, ,] ImageVector = new Int16[Header.Bands, Header.Lines, Header.Samples]; using (BinaryReader imageReader = new BinaryReader(new FileStream(PictureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))) { for (int l = 0; l < Header.Lines; l++) { for (int s = 0; s < Header.Samples; s++) { for (int b = 0; b < Header.Bands; b++) { ImageVector[b, l, s] = (Int16)BinaryPixelConverter.AssignPixelValue(imageReader, Header.ByteOrder, PixelType); } } } } return(ImageVector); }
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; }
//.............................................................. 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; }
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); }
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); }
//................................................................ 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; }