-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReading_S2Matrix.m
More file actions
103 lines (87 loc) · 3.18 KB
/
Reading_S2Matrix.m
File metadata and controls
103 lines (87 loc) · 3.18 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
%% Reading S2 matrix (S2 generated in PolSARPro)
%%
[filename, path] = uigetfile('*.*', 'Path selection Time 1');
path
f0 = fopen([path 'config.txt']);
tmp = fgets(f0);
nrows = sscanf(fgets(f0),'%d');
tmp = fgets(f0);
tmp = fgets(f0);
ncols = sscanf(fgets(f0),'%d');
ep = 0;
f1 = fopen([path 's11.bin'],'rb');
f2 = fopen([path 's12.bin'],'rb');
f3 = fopen([path 's21.bin'],'rb');
f4 = fopen([path 's22.bin'],'rb');
s11_1 = fread(f1,[2*ncols nrows],'float32');
% ENVI data type =6 ==> Complex format
% Complex (2x32 bits)data currently not supported');
% Importing as double-precision instead;==>format= 'double';
s12_1 = fread(f2,[2*ncols nrows],'float32');
s21_1 = fread(f3,[2*ncols nrows],'float32');
s22_1 = fread(f4,[2*ncols nrows],'float32');
%% Note: In general, the first row will be real part and the next row will...
% be imaginary part in the complex data file i.e. Real and Imaginary parts will
% be alternating in each row. This format may differ based on the method of storing the file.
%% https://www.imageeprocessing.com/2015/03/how-to-read-image-file-or-complex-image.html
%%
s11_real = s11_1(1:2:ncols*2,:);
s11_imag = s11_1(2:2:ncols*2,:);
s11 = complex(s11_real,s11_imag);
s12_real = s12_1(1:2:ncols*2,:);
s12_imag = s12_1(2:2:ncols*2,:);
s12 = complex(s12_real,s12_imag);
s21_real = s21_1(1:2:ncols*2,:);
s21_imag = s21_1(2:2:ncols*2,:);
s21 = complex(s21_real,s21_imag);
s22_real = s22_1(1:2:ncols*2,:);
s22_imag = s22_1(2:2:ncols*2,:);
s22 = complex(s22_real,s22_imag);
fclose('all');
tic
%%
%Image visualization
f10 = figure('Name', 'Matrix element-S11');
set(gca,'FontSize',15)
imagesc(abs(s11)')
axis('image');
colormap('gray');
colorbar('FontSize', 15);
caxis([0 0.8]);
%% Testing with SNAP RS2>>Radiometric calibrate check i and q channel
% Snap pixel location column, row : java starts with 0,0
% MATLAB starts with 1,1
% Hence in MATLAB: img (col-1, row-1) == SNAPimg (col, row)
fprintf('S11_real (1385,1197) == %.4f \n', s11_real(1385,1197));
fprintf('S11_imag (1385,1197) == %.4f\n', s11_imag(1385,1197));
fprintf('S11 (1385,1197) == %.4f+%.4fj\n', real(s11(1385,1197)), imag(s11(1385,1197)));
%% Creating colour image
% Combine separate color channels into an RGB image.
dbl = abs(s11) - abs(s22); % Shh-Svv
vol = abs (s21); %Shv
surf = abs(s11) + abs(s22);
rgbImage = cat(3, dbl', vol', surf');
%% Enhance Composite with a Contrast Stretch
stretched_rgbImage1 = imadjust(rgbImage,stretchlim(rgbImage));
%Visualization of RGB image
f11 = figure;
set(f11,'name','PauliRGB (Contrast Stretch-lin)','numbertitle','off');
imshow(stretched_rgbImage1);
axis('image');
%caxis([-35 0]);
title('Pauli-RGB-MATLAB');
%% Enhance Composite with a Decorrelation Stretch
stretched_rgbImage2 = decorrstretch(rgbImage, 'Tol', 0.05);
%Visualization of RGB image
f12 = figure;
set(f12,'name','PauliRGB (Decorrelation Stretch)','numbertitle','off');
imshow(stretched_rgbImage2);
axis('image');
% caxis([0 1]);
title('Pauli-RGB-MATLAB2');
%%
%Save visualized RGB .png file in same path
figname_png12 = strcat([path,'PauliRGB(decorrstretch).png']);
print(f12,figname_png12,'-dpng')
fclose('all');
%% end of code