-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadBIL.cpp
More file actions
89 lines (69 loc) · 2.37 KB
/
readBIL.cpp
File metadata and controls
89 lines (69 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <fstream>
#include <iterator>
#include <vector>
#include <opencv2/highgui.hpp>
#include <omp.h>
#include <iostream>
// g++ readBIL.cpp -o readBILCube `pkg-config --cflags --libs opencv`
int columns = 1080;
int bands = 96;
int rows = 1735;
char* buffer;
char** waveLengths;
int main(int argc, char* argv[])
{
if (argc<2) {
puts("Usage: a.out [PATH TO RAW]");
return -1;
}
// buffer = malloc(columns*bands*rows);
buffer = new char[columns*bands*rows];
waveLengths = new char*[bands];
for(int band=0; band<bands; band++){
waveLengths[band] = new char[rows*columns];
}
std::ifstream input( argv[1], std::ios::in | std::ios::binary );
if (!input)
{
std::cout << "Failed to open file\n";
exit(1);
}
input.seekg (0, input.end);
int lengthFile = input.tellg();
input.seekg (0, input.beg);
input.read(buffer, columns*rows*bands);
if (input)
printf("%i Characters read successfully\n", lengthFile);
else
printf("Error, read only %i out of %li characters\n", lengthFile, input.gcount());
#pragma omp parallel for num_threads(4)
for(int band=0; band<bands; band++){
for(int row=0; row<rows; row++){
for(int column=0; column<columns; column++){
waveLengths[band][row*columns+column] = buffer[row*bands*columns+band*columns+column];
}
}
}
std::stringstream ss;
ss << argv[1];
std::string folderName = ss.str();
std::string newDirectory = "mkdir -p ./" +folderName+".Images";
system(newDirectory.c_str());
for(int band=0; band<bands; band++){
std::string filename = "./" +folderName+".Images" + "/" + std::to_string(band) + ".png";
cv::Mat grayScaleMat = cv::Mat(rows, columns, CV_8UC1, waveLengths[band]);
imwrite(filename,grayScaleMat);
}
//Make RGB image
std::vector<cv::Mat> rgbChannels;
// RGB: 25 33 47
rgbChannels.push_back(cv::Mat(rows, columns, CV_8UC1, waveLengths[22]));
rgbChannels.push_back(cv::Mat(rows, columns, CV_8UC1, waveLengths[32]));
rgbChannels.push_back(cv::Mat(rows, columns, CV_8UC1, waveLengths[49]));
cv::Mat rgbImage;
cv::merge(rgbChannels, rgbImage);
std::string filename = "./" +folderName+".Images" + "/" + "color" + ".png";
imwrite(filename,rgbImage);
delete waveLengths;
return 0;
}