%% Understanding SAR data
%% Read and show SAR image
% Let's load a subset of fully polarimetric image in scattering matrix format to Matlab. The image is already converted to matlab compatible format (make sure that the data file EMISAR_L_may_1995.mat is in your working directory).

% load EMISAR fully polarimetric image in scattering matrix format to Matlab 
load EMISAR_L_may_1995.mat
% and show loaded variables 
whos

% You see, that there are four variables (channels), every variable is a complex number matrice, corresponding to an image. Each variable is an element of scattering matrix S. In order to see the backscattering coefficient, one should use the squre of the scattering  matrix element *4*pi (see the equation in the lecture slides)

figure;
imagesc(Shh.*Shh'.'); % the imagesc function automatically scales the image, 
% the 4pi constant is therefore not needed
% here I have used multiplication by complex conjugate, but you can use
% also  abs(Shh).^2, the result is the same
colormap('gray'); axis off;% format the image B&W 
% lets create a variable
sigma_hh=Shh.*Shh'.';
% the dot in front of operator makes Matlab to carry out the operation
% element by element. If dot is omitted, Matlab will fo the matrix
% multiplication, which we do nit want.

% as you see, image shows only one bright pixel
%% Task 3 (1 p)
% Visualize backscattering coefficient for vv polarization. Show two images, one in linear scale another in logaritmic scale. Use imagesc command.

help imagesc

%% Task 4 (1 p)
% Study scattering matrix element pixel value distributions. Use histogram (hist function) and compare pixel value distributions in decibel scale and in linear scale. Show both amplitude and phase distributions.
% (note that  for statistical analysis it is handy to put all image values to one row with notation Shh(:))

help hist

%% Task 5 (1p)
% Show pixel value distribution also for backscattering coefficient, both in linear and in dB scale.



%% Task 6 (1p)
% Filter the image with 10x10 window averaging. You can use for this filter2 command and use for filter matrix a 10x10 matrix of ones. Filter the complex values of scattering matrix and also the sigma (scattering coefficient) image. Visualize and compare the result.
% What has happened to the complex image?

help filter2
help ones

% Return both, the output and also the script of your assignment. The assignment can be done also in python or octave.
%
%