Working with multiband hyperspectral images in ENVI BIL format (raw, hdr). Saving bands to 2D image.
See original GitHub issueHi,
I am beginning to learn more about net-vips and starting to use it more for various projects. So far mainley worked with regular 2d images and I find the performance and mamory usage amazing.
I have recently started to learn about hyperspectral images (HSI) but due to a lack of information having a hard time figuring out how to get started with net-vips.
I’m fairly new to net-vips and HSI so please go easy on me if get the terminology wrong.
I have a sample HSI image in ENVI BIL (Band-interleaved-by-line) format (.raw and .hdr - header file). I am trying to learn how to do some basic operations on it e.g.: extracting bands to 2d images, joining bands and saving them to 2d images.
My header file gives me information about the file/format:
ENVI
samples = 2883
lines = 4094
bands = 306
header offset = 0
file type = ENVI Standard
data type = 4
interleave = bil
wavelength units = nm
binning = {4,4}
wavelength = {"list of wavelengths here"}
I did try to use the Rawload()
and started reading the documentation but I’m stuck.
Should I be looking at Enums.Interpretation
and Enumbs.BandFormat
?
static void Main(string[] args)
{
string selectedFile = @"C:\hsi.raw";
int datatype = 4; // Floating - point: 32 - bit single - precision
int samples = 2883; // width
int lines = 4094; // height
int bands = 306; // number of bands (channels)
using (var image = Image.Rawload(selectedFile, samples, lines, bands, access: Enums.Access.Sequential))
{
var splited = image.Bandsplit();
int counter = 0;
foreach (var im in splited)
{
im.WriteToFile("img" + counter + ".jpg");
counter++;
}
}
}
static void Main(string[] args)
{
string selectedFile = @"C:\hsi.raw";
int datatype = 4; // Floating - point: 32 - bit single - precision
int samples = 2883; // width
int lines = 4094; // height
int bands = 306; // bands (channels)
using (var image = Image.Rawload(selectedFile, samples, lines, bands, access: Enums.Access.Sequential))
{
image[0].WriteToFile("test.jpg");
}
}
I have also tried to do this manually with FileStream, calculating positions, using Buffer.BlockCopy and attempting to get an image from a byte array.
I was wondering if someone with more experience in the subject could help me get started/give some examples if possible?
Many thanks.
EDIT:
I have managed to get some results to extract one band manually: using FileStream
, setting img dimensions and positions of bands then looping while doing BlockCopy
to float[]
.
Eventually converting float[]
to byte[]
then using Net-Vips Image.FromMemory
to save as jpg.
Still trying to figure out if this could be more straightforward with net-vips? (like using the Rawload and then working on bands).
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Top GitHub Comments
It looks like the sample image uses 0 - 1 for black to white, so I think adding a
*256
will fix it.I had a go in python:
It makes this:
I suppose we’d need to add something about the SPD to fix the blueness.
(saving as
.v
and then using vipsdisp or nip2 to examine the file is an easy way to find things like this)I hope this information helped. Please feel free to re-open if questions remain.