├── ImagePartition ├── kkk.JPG ├── metal.png ├── test01.jpg ├── test01i.jpg ├── test03.jpg ├── test03i.jpg ├── test04.jpg ├── test04i.jpg ├── plano_met.mat ├── ObjetosReconocidos.png ├── hormigon_1layer_75.mat ├── hormigon_2layer_55.mat ├── objetos_enterrados.mat ├── arena2objEncima_2BW_3D.fig ├── tierra_placaEncimayEnterrada_z150.mat ├── script_ejecutar.m ├── Image3DPartition.m ├── ImagePartition.m └── codigo_original.m └── ProcesadoSAR ├── gprMax_script.m ├── SAR_gprMax_PSM.m ├── SAR_gprMax.m ├── SAR_gprMax_correction.m ├── SAR_gprMax_PSM_multi.m ├── SAR_Matlab.m ├── SAR_gprMax_multi.m ├── gprMaxLoadBscan.m └── SAR_gprMax_PWSAR.m /ImagePartition/kkk.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/kkk.JPG -------------------------------------------------------------------------------- /ImagePartition/metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/metal.png -------------------------------------------------------------------------------- /ImagePartition/test01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/test01.jpg -------------------------------------------------------------------------------- /ImagePartition/test01i.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/test01i.jpg -------------------------------------------------------------------------------- /ImagePartition/test03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/test03.jpg -------------------------------------------------------------------------------- /ImagePartition/test03i.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/test03i.jpg -------------------------------------------------------------------------------- /ImagePartition/test04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/test04.jpg -------------------------------------------------------------------------------- /ImagePartition/test04i.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/test04i.jpg -------------------------------------------------------------------------------- /ImagePartition/plano_met.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/plano_met.mat -------------------------------------------------------------------------------- /ImagePartition/ObjetosReconocidos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/ObjetosReconocidos.png -------------------------------------------------------------------------------- /ImagePartition/hormigon_1layer_75.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/hormigon_1layer_75.mat -------------------------------------------------------------------------------- /ImagePartition/hormigon_2layer_55.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/hormigon_2layer_55.mat -------------------------------------------------------------------------------- /ImagePartition/objetos_enterrados.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/objetos_enterrados.mat -------------------------------------------------------------------------------- /ImagePartition/arena2objEncima_2BW_3D.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/arena2objEncima_2BW_3D.fig -------------------------------------------------------------------------------- /ImagePartition/tierra_placaEncimayEnterrada_z150.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosgdiaz/SignalProcessing/HEAD/ImagePartition/tierra_placaEncimayEnterrada_z150.mat -------------------------------------------------------------------------------- /ImagePartition/script_ejecutar.m: -------------------------------------------------------------------------------- 1 | clear all; close all; clc 2 | ImagePartition('test03.jpg',210, 600, 11500 ) 3 | %load('plano_met.mat') 4 | %load('objetos_enterrados.mat') 5 | %load('hormigon_1layer_75.mat') 6 | %load('hormigon_2layer_55.mat') 7 | %load('tierra_placaEncimayEnterrada_z150.mat') 8 | 9 | % load('../RadarILMsens/imagen_3D_arena_plastico.mat') 10 | % y=linspace(-0.5,0.5,41); 11 | % x=linspace(-0.4,0.4,36); 12 | % z=linspace(0,1.5,50); 13 | % Image3DPartition(x,y,z,20*log10(abs(imagen/max(max(max(imagen))))),-15.5,50, 2400) 14 | -------------------------------------------------------------------------------- /ImagePartition/Image3DPartition.m: -------------------------------------------------------------------------------- 1 | function [ ] = Image3DPartition( x, y, z, rho, umbral, volumen, volumen2 ) 2 | binaryrho = rho > umbral; 3 | filledrho = imfill(binaryrho,'holes'); 4 | CC=bwconncomp(filledrho,26); 5 | prop = regionprops(CC, 'FilledArea','PixelIdxList'); 6 | allAreas = [prop.FilledArea] 7 | allowableAreaIndexes = allAreas > volumen & allAreas < volumen2; 8 | keeperIndexes = find(allowableAreaIndexes); 9 | 10 | for i=keeperIndexes 11 | img=zeros(size(rho)); 12 | aux=prop(i).PixelIdxList; 13 | img(aux)=true; 14 | cdata = rand()*ones(size(img)); 15 | p=patch(isosurface(x,y,z,img,0)); 16 | isonormals(x,y,z,img,p) 17 | isocolors(x,y,z,cdata,p) 18 | p.FaceColor = 'interp'; 19 | p.EdgeColor = 'none'; 20 | grid on 21 | hold all 22 | end 23 | %keeperBlobsImage = ismember(filledrho, keeperIndexes); 24 | view(150,30) 25 | set(gca,'Zdir','reverse') 26 | xlabel('x(m)'); 27 | ylabel('y(m)'); 28 | zlabel('z(m)') 29 | title('3-D binary image') 30 | end 31 | 32 | -------------------------------------------------------------------------------- /ProcesadoSAR/gprMax_script.m: -------------------------------------------------------------------------------- 1 | clear all, close all, clc 2 | root='/Users/marcosgonzalezdiaz/Documents/Universidad/TFG/gprMax-master/Ensayos/'; 3 | A='primer_modelo_merged.out'; 4 | B='segundo_modelo_merged.out'; 5 | C='tercer_modelo_merged.out'; 6 | D='cuarto_modelo_merged.out'; 7 | E='quinto_modelo_merged.out'; 8 | F='sexto_modelo_merged.out'; 9 | G='varios_objetos_merged.out'; 10 | H='varios_objetos1_merged.out'; 11 | I='interfaz_rugosa_merged.out'; 12 | J='heterogeneo_plano_merged.out'; 13 | K='heterogeneo_rugoso_merged.out'; 14 | L='paper_TFG_hf_merged.out'; 15 | M='prueba_mortero_merged.out'; 16 | N='prueba2_merged.out'; 17 | O='tfg1_merged.out'; 18 | P='tfg2_merged.out'; 19 | Q='tfg3_merged.out'; 20 | R='tfg4_merged.out'; 21 | S='tfg5_merged.out'; 22 | T='tfg6_merged.out'; 23 | U='paper1_merged.out'; 24 | 25 | 26 | %[x, y, imagen]=SAR_gprMax_correction(strcat(root,P)); 27 | [x, y, imagen]=SAR_gprMax_PSM_multi(strcat(root,O),[0 0.42 0.52], [1 2.5 3.5]);%[0 0.14],[1 4+0.02j]); 28 | %[0 0.072 0.09 0.14],[1 2.19-0.02j 1.1-0.001j 4-0.2j]);%[0 0.072 0.09 0.14],[1 2.19-0.02j 1.1-0.001j 4+0.2j]);% 0.09 0.14],[1 2.19-0.02j 1.1-0.001j 4+0.2j]); 29 | %pcolor(x*100-24,y*100-7,20*log10(abs(imagen/max(max(imagen))))) 30 | find(y>=0.17 & y<=0.77); 31 | % index=find(y<=100); 32 | % media=zeros(size(imagen,1),1); 33 | % media(index)=sum(imagen(index,:),2)/size(imagen,2); 34 | % imagen = imagen - repmat(media,1,size(imagen,2)); 35 | pcolor(x*100-24,y(ans)*100-7,20*log10(abs(imagen(ans,:)/max(max(imagen(ans,:)))))) 36 | fontSize = 24; 37 | set(gca,'YDir','reverse') 38 | colormap jet; 39 | shading interp; 40 | xlabel('x [cm]','fontSize',fontSize); 41 | ylabel('z [cm]','fontSize',fontSize); 42 | h = colorbar; 43 | h.Location='southoutside'; 44 | ylabel(h, 'Amplitud normalizada [dB]', 'fontSize',fontSize) 45 | axis equal; 46 | xlim([-24 24]) 47 | ylim([20 70]) 48 | caxis([-30 0]); 49 | set(gca,'fontsize',fontSize) 50 | 51 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_gprMax_PSM.m: -------------------------------------------------------------------------------- 1 | function [ x_prima ,z_prima ,refl ] = SAR_gprMax_PSM( filename ) 2 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 3 | header.dt = h5readatt(filename, '/', 'dt'); 4 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 5 | % Detailed explanation goes here 6 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 7 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 8 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 9 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 10 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 11 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 12 | %Cargamos campo, tiempo y el numero de traza 13 | field = fields.ez; 14 | %field1=field(200:end,:)';%Quitamos el acoplo. Para la fft, tienen que estar en filas 15 | time = 0:header.dt:header.iterations * header.dt; 16 | prof = time(1:(end-1))*3e8/2; 17 | index2=find(prof >= 0.17); 18 | index=find(prof <= 2.27); 19 | %field = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 20 | % media=zeros(size(field,1),1); 21 | % media(index)=sum(field(index,:),2)/size(field,2); 22 | %field = field - repmat(media,1,size(field,2)); 23 | traces = 0:size(field,2)-1; 24 | %Definimos el eje de frecuencias 25 | NFFT=2^nextpow2(length(field));%Numero de puntos de la fft optimo 26 | Fs=1/header.dt;%Frecuencia de muestreo del GprMax 27 | f=linspace(-Fs/2,Fs/2,NFFT); 28 | f=f(f>=0);%Frecuencias positivas 29 | %Hacemos fftshift que centra la frecuencia cero en dimension 1(por 30 | %columnas) 31 | S1=fft(field,NFFT,1); 32 | S=S1(1:length(f),:);%Nos quedamos en el campo en frecuencias positivas 33 | % S=S(1:3:end,:); 34 | % f=f(1:3:end); 35 | S=permute(S,[2 3 1]); 36 | Sk=fft(S,[],1); 37 | Sk=fftshift(Sk,1); 38 | % Sk=fft(Sk,[],2); 39 | % Sk=fftshift(Sk,2); 40 | 41 | %x_prima=traces*0.025; 42 | x_prima=traces*0.008; 43 | y_prima=0; 44 | %z_prima=0:0.01:1-0.01; 45 | z_prima=prof(index2);%200:4:900); 46 | % refl=field(index2,:); 47 | % return; 48 | ksx=2*pi/0.008; 49 | kx=linspace(-ksx/2,ksx/2,length(x_prima)); 50 | 51 | kz=sqrt(4*(2*pi*permute(repmat(f,length(kx),1),[1,3,2])*sqrt(1)/3e8).^2-permute(repmat(kx,length(f),1),[2 3 1]).^2); 52 | kz(kz.*kz < 0) = 0; 53 | refl=zeros(numel(x_prima),length(y_prima),numel(z_prima)); 54 | 55 | for i=1:numel(z_prima) 56 | for j=1:numel(f) 57 | refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz(:,:,j)*z_prima(i)); 58 | end 59 | end 60 | refl=ifftshift(refl,1); 61 | refl=ifft(refl,[],1); 62 | 63 | % refl=ifft(refl,[],2); 64 | % refl=ifftshift(refl,2); 65 | refl=permute(refl,[3 1 2]); 66 | 67 | end 68 | 69 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_gprMax.m: -------------------------------------------------------------------------------- 1 | function [ x_prima ,y_prima ,imagen ] = SAR_gprMax( filename ) 2 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 3 | header.dt = h5readatt(filename, '/', 'dt'); 4 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 5 | % Detailed explanation goes here 6 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 7 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 8 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 9 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 10 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 11 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 12 | %Cargamos campo, tiempo y el numero de traza 13 | field = fields.ez; 14 | %field1=field(200:end,:)';%Quitamos el acoplo. Para la fft, tienen que estar en filas 15 | time = 0:header.dt:header.iterations * header.dt; 16 | prof = time(1:(end-1))*3e8/2; 17 | index2=find(prof >= 0.27); 18 | index=find(prof <= 2.27); 19 | %field1 = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 20 | %field = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 21 | % media=zeros(size(field)); 22 | % media(index,:)=field(index,:); 23 | %field = field - repmat(sum(media,2)/size(media,2),1,size(media,2)); 24 | traces = 0:size(field,2)-1; 25 | %Definimos el eje de frecuencias 26 | NFFT=2^nextpow2(length(field));%Numero de puntos de la fft optimo 27 | Fs=1/header.dt;%Frecuencia de muestreo del GprMax 28 | f=linspace(-Fs/2,Fs/2,NFFT); 29 | f=f(f>=0);%Frecuencias positivas 30 | %Hacemos fftshift que centra la frecuencia cero en dimension 1(por 31 | %columnas) 32 | FIELD1=fft(field,NFFT,1); 33 | FIELD=FIELD1(1:length(f),:);%Nos quedamos en el campo en frecuencias positivas 34 | %Preparamos la matriz que va a multiplicar al campo 35 | k0=2*pi*f*sqrt(1)/3e8; 36 | %k1=k0*sqrt(2.5); 37 | %Definimos las coordenadas de la imagen 38 | x_prima=traces*0.008;%0.025; 39 | %y_prima=0.15:0.01:0.85-0.01; 40 | y_prima=prof(index2);%0:0.001:0.30; 41 | 42 | [X,Y]=meshgrid(x_prima,y_prima);%Para hacer la matriz de distancias 43 | %Matriz de exponenciales 44 | exponenciales=repmat(2j,length(y_prima),length(FIELD)); 45 | imagen=zeros(length(y_prima),length(x_prima));%Creacion de la matriz de la imagen SAR 46 | for m=1:size(FIELD,2) %Se recorren las antenas 47 | %Creamos la matriz distancias dependiente de la antena que se este midiendo3 48 | D=sqrt(abs(X-X(1,m)).^2+(Y).^2); 49 | for x=1:length(x_prima)%Se recorren las columnas de la matriz imagen 50 | % imagen(:,x) = imagen(:,x) + exp(2*1j*(2*pi*repmat(f,length(y_prima),1).*... 51 | % repmat(D(:,x), 1, length(f)))/3e8)*FIELD(:,m); 52 | omega=repmat(k0,length(y_prima),1).*repmat(D(:,x),1,length(FIELD));%Nos quedamos con las distancias de la columna x 53 | imagen(:,x)=imagen(:,x)+exp(exponenciales.*omega)*FIELD(:,m); 54 | 55 | end 56 | 57 | 58 | end 59 | 60 | -------------------------------------------------------------------------------- /ImagePartition/ImagePartition.m: -------------------------------------------------------------------------------- 1 | function [] = ImagePartition(FullFileName, Umbral, Area, Area2 ) 2 | clc; % Clear the command window. 3 | % Close all figures (except those of imtool.) 4 | imtool close all; % Close all imtool figures. 5 | % Erase all existing variables. 6 | workspace; % Make sure the workspace panel is showing. 7 | format long g; 8 | format compact; 9 | fontSize = 14; 10 | 11 | % Check that user has the Image Processing Toolbox installed. 12 | hasIPT = license('test', 'image_toolbox'); 13 | if ~hasIPT 14 | % User does not have the toolbox installed. 15 | message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?'); 16 | reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes'); 17 | if strcmpi(reply, 'No') 18 | % User said No, so exit. 19 | return; 20 | end 21 | end 22 | 23 | %Get the full filename, with path prepended. 24 | if ~exist(FullFileName, 'file') 25 | % Didn't find it there. Check the search path for it. 26 | errorMessage = sprintf('Error: %s does not exist.', FullFileName); 27 | uiwait(warndlg(errorMessage)); 28 | return; 29 | end 30 | 31 | rgbImage = imread(FullFileName); 32 | [rows, columns, numberOfColorBands] = size(rgbImage); 33 | % Convert to binary 34 | if numberOfColorBands > 1 35 | grayImage = rgb2gray(rgbImage); 36 | binaryImage = grayImage > Umbral; 37 | else 38 | binaryImage = rgbImage > Umbral; 39 | end 40 | 41 | subplot(1,4,1) 42 | imshow(rgbImage,[]) 43 | % axis on; 44 | caption=sprintf('Imagen original'); 45 | title(caption,'Fontsize',fontSize); 46 | set(gcf,'units','normalized ','OuterPosition',[0 0 1 1]) 47 | drawnow; 48 | 49 | subplot(1,4,2) 50 | imshow(binaryImage,[]) 51 | caption=sprintf('Imagen binaria'); 52 | title(caption,'Fontsize',fontSize); 53 | drawnow; 54 | 55 | % Clean up a bit. 56 | %binaryImage = imclearborder(binaryImage); 57 | binaryImage = imfill(binaryImage, 'holes'); 58 | subplot(1,4,3) 59 | imshow(binaryImage,[]) 60 | caption=sprintf('Imagen binaria rellenada'); 61 | title(caption,'Fontsize',fontSize); 62 | drawnow; 63 | 64 | %Se utilizan funciones de Matlab para quedarnos con los objetas con un area 65 | %mayor que un umbral predefinido 66 | labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it 67 | coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels 68 | blobMeasurements = regionprops(labeledImage, 'all'); 69 | allAreas = [blobMeasurements.Area] 70 | allowableAreaIndexes = allAreas > Area & allAreas < Area2; 71 | keeperIndexes = find(allowableAreaIndexes); 72 | keeperBlobsImage = ismember(labeledImage, keeperIndexes); 73 | labeledImage = bwlabel(keeperBlobsImage, 8); 74 | subplot(1, 4, 4); 75 | labeledImage=repmat(uint8(labeledImage),1,1,3).*rgbImage; 76 | labeledImage(:,:,3)=(labeledImage(:,:,3)==0)*140; 77 | imshow(labeledImage, []); 78 | title('Objetos reconocidos', 'FontSize', fontSize); 79 | 80 | 81 | end 82 | 83 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_gprMax_correction.m: -------------------------------------------------------------------------------- 1 | function [x_prima ,y_prima ,imagen] = SAR_gprMax_correction(filename) 2 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 3 | header.dt = h5readatt(filename, '/', 'dt'); 4 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 5 | % Detailed explanation goes here 6 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 7 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 8 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 9 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 10 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 11 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 12 | %Cargamos campo, tiempo y el numero de traza 13 | field = fields.ez; 14 | %field1=field(200:end,:)';%Quitamos el acoplo. Para la fft, tienen que estar en filas 15 | time = 0:header.dt:header.iterations * header.dt; 16 | prof = time*3e8/2; 17 | index2=find(prof >= 0.27 & prof <= 0.67); 18 | index=find(prof <= 0.57); 19 | %field1 = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 20 | media=zeros(size(field)); 21 | media(index,:)=field(index,:); 22 | field = field - repmat(sum(media,2)/size(media,2),1,size(media,2)); 23 | traces = 0:size(field,2)-1; 24 | %field = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 25 | %Definimos el eje de frecuencias 26 | NFFT=2^nextpow2(length(field));%Numero de puntos de la fft optimo 27 | Fs=1/header.dt;%Frecuencia de muestreo del GprMax 28 | f=linspace(-Fs/2,Fs/2,NFFT); 29 | f=f(f>=0);%Frecuencias positivas 30 | %Hacemos fftshift que centra la frecuencia cero en dimension 1(por 31 | %columnas) 32 | FIELD1=fft(field,NFFT,1); 33 | FIELD=FIELD1(1:length(f),:);%Nos quedamos en el campo en frecuencias positivas 34 | %Preparamos la matriz que va a multiplicar al campo 35 | k0=2*pi*f/3e8; 36 | k1=k0*real(sqrt(3.5+0.05j)); 37 | %Definimos las coordenadas de la imagen 38 | x_prima=traces*0.008;%0.025; 39 | %y_prima=0.15:0.01:0.85-0.01; 40 | y_prima=prof(index2); 41 | 42 | [X,Y]=meshgrid(x_prima,y_prima);%Para hacer la matriz de distancias 43 | %Matriz de exponenciales 44 | exponenciales=repmat(2j,length(y_prima),length(FIELD)); 45 | imagen=zeros(length(y_prima),length(x_prima));%Creacion de la matriz de la imagen SAR 46 | 47 | h=0.42;%Distancia de las antenas al suelo 48 | inf=find(y_prima <= h); 49 | sup=find(y_prima > h); 50 | for m=1:size(FIELD,2) %Se recorren las antenas 51 | %Creamos la matriz distancias dependiente de la antena que se este midiendo 52 | D=sqrt(abs(X-X(1,m)).^2+(Y).^2); 53 | Xp=X-X(1,m); 54 | k=real(sqrt(1/(4+0.2j)));%Ponderacion dependiente de Er2 55 | Xb=Xp+k*(Xp.*h./Y-Xp);%Distancia x del la ruta optima 56 | d1=sqrt(h^2+Xb.^2); 57 | d2=sqrt((Y-h).^2+(Xp-Xb).^2); 58 | for x=1:length(x_prima)%Se recorren las columnas de la matriz imagen 59 | % imagen(:,x) = imagen(:,x) + exp(2*1j*(2*pi*repmat(f,length(y_prima),1).*... 60 | % repmat(D(:,x), 1, length(f)))/3e8)*FIELD(:,m); 61 | omega1=repmat(k0,length(sup),1).*repmat(d1(sup,x),1,length(FIELD));%Nos quedamos con las distancias de la columna x 62 | omega2=repmat(k1,length(sup),1).*repmat(d2(sup,x),1,length(FIELD)); 63 | imagen(sup,x)=imagen(sup,x)+exp(exponenciales(sup,:).*(omega1+omega2))*FIELD(:,m); 64 | omega=repmat(k0,length(inf),1).*repmat(D(inf,x),1,length(FIELD));%Nos quedamos con las distancias de la columna x 65 | imagen(inf,x)=imagen(inf,x)+exp(exponenciales(inf,:).*omega)*FIELD(:,m); 66 | end 67 | end 68 | 69 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_gprMax_PSM_multi.m: -------------------------------------------------------------------------------- 1 | function [ x_prima ,z_prima ,refl ] = SAR_gprMax_PSM_multi(filename, lim, eps ) 2 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 3 | header.dt = h5readatt(filename, '/', 'dt'); 4 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 5 | % Detailed explanation goes here 6 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 7 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 8 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 9 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 10 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 11 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 12 | %Cargamos campo, tiempo y el numero de traza 13 | field = fields.ez; 14 | 15 | %field1=field(200:end,:)';%Quitamos el acoplo. Para la fft, tienen que estar en filas 16 | time = 0:header.dt:header.iterations * header.dt; 17 | prof = time(1:(end-1))*3e8/2; 18 | index2=find(prof >= 0.27 & prof <= 0.77); 19 | index=find(prof <= 0.3); 20 | %field = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 21 | media=zeros(size(field)); 22 | media(index,:)=field(index,:); 23 | field = field - repmat(sum(media,2)/size(media,2),1,size(media,2)); 24 | %field = field - repmat(min(media,[],2),1,size(media,2)); 25 | 26 | traces = 0:size(field,2)-1; 27 | %Definimos el eje de frecuencias 28 | NFFT=2^nextpow2(length(field));%Numero de puntos de la fft optimo 29 | Fs=1/header.dt;%Frecuencia de muestreo del GprMax 30 | f=linspace(-Fs/2,Fs/2,NFFT); 31 | f=f(f>=0);%Frecuencias positivas 32 | %Hacemos fftshift que centra la frecuencia cero en dimension 1(por 33 | %columnas) 34 | S1=fft(field,NFFT,1); 35 | S=S1(1:length(f),:);%Nos quedamos en el campo en frecuencias positivas 36 | S=permute(S,[2 3 1]); 37 | Sk=fft(S,[],1); 38 | Sk=fftshift(Sk,1); 39 | % Sk=fft(Sk,[],2); 40 | % Sk=fftshift(Sk,2); 41 | 42 | %x_prima=traces*0.025; 43 | x_prima=traces*0.008; 44 | y_prima=0; 45 | %z_prima=0.15:0.01:0.85-0.01; 46 | z_prima=prof(index2); 47 | 48 | ksx=2*pi/0.008; 49 | kx=linspace(-ksx/2,ksx/2,length(x_prima)); 50 | ky=0; 51 | 52 | %kz1=sqrt(4*(2*pi*permute(repmat(f,length(kx),1),[1,3,2])/3e8).^2-permute(repmat(kx,length(f),1),[2 3 1]).^2); 53 | kz=sqrt(4*(2*pi*permute(repmat(f,length(kx),length(ky),1,length(eps)),[1,3,2,4]).*real(sqrt(repmat(permute(eps,[4 3 1 2]),... 54 | length(kx),length(ky),length(f))))/3e8).^2-permute(repmat(kx,length(f),length(ky),1,length(eps)),[2 3 1 4]).^2); 55 | 56 | 57 | % T12=2*eps*kz1./(eps*kz1+1*k2z); 58 | % T21=2*1*kz2./(1*kz2+eps*kz1); 59 | % kz1(kz1.*kz1 < 0) = 0; 60 | 61 | 62 | kz(kz.*kz < 0) = 0; %Est?n ordenados en la cuarta dimension 63 | 64 | refl=zeros(numel(x_prima),length(y_prima),numel(z_prima)); 65 | 66 | for i=1:numel(z_prima) 67 | for j=1:numel(f) 68 | log = z_prima(i) >= lim; 69 | pos = find(log,1,'last'); 70 | if pos>1 71 | refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*prod(exp(1j*kz(:,:,j,1:pos-1)... 72 | .*repmat(permute(lim(2:pos)-lim(1:pos-1),[4 3 1 2]),size(kz(:,:,1,1)))),4).*exp(1j*kz(:,:,j,pos)*(z_prima(i)-lim(pos))); 73 | else 74 | refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz(:,:,j,pos)*z_prima(i)); 75 | end 76 | % if z_prima(i)<=lim 77 | % refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz1(:,:,j)*z_prima(i)); 78 | % else 79 | % refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz1(:,:,j)*lim).*exp(1j*kz2(:,:,j)*(z_prima(i)-lim))./exp(-1j*angle(T12(:,:,j).*T21(:,:,j))); 80 | % end 81 | end 82 | end 83 | refl=ifftshift(refl,1); 84 | refl=ifft(refl,[],1); 85 | % refl=ifft(refl,[],2); 86 | % refl=ifftshift(refl,2); 87 | refl=permute(refl,[3 1 2]); 88 | 89 | end 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_Matlab.m: -------------------------------------------------------------------------------- 1 | % SAR SIMULATION 2 | 3 | clear all,clc,close all; 4 | 5 | fini = 14e9; % Start frequency 6 | ffin = 26e9; % Stop frequency 7 | df = 500*1e6; % Sampling frequency (equivalent to "PRF") 8 | 9 | Runamb = 3e8/(2*df); 10 | disp(['Maximum unambiguity distance: ' num2str(Runamb*100) ' cm']); 11 | 12 | f = [fini:df:ffin]; % Radar bandwidth 13 | BW=(f(end)-f(1))/1e9; 14 | 15 | disp(['Bandwidth = ' num2str(BW) ' GHz']); 16 | disp(['Range (distance) resolution) = ' num2str(3e8/(2*BW*1e7)) ' cm']); 17 | disp(' '); 18 | 19 | lambda_fMax=3e8/max(f); 20 | 21 | dx = 0.25; % Synthetic aperture sampling as a function of the wavelength 22 | dx=lambda_fMax*dx; 23 | 24 | Lap = 0.4; % Synthetic aperture size 25 | x = [-Lap/2 : dx : Lap/2]; 26 | y = 0*x + 0.2; % Position of the radar in the y-axis 27 | 28 | % Targets position ------------------------------ 29 | xp = [-0.08 -0.05 -0.02 0 0.03 0.062]; 30 | yp = [ 0.56 0.52 0.54 0.57 0.59 0.52]; 31 | 32 | % RCS of the targets (dBm2) 33 | rcs = [-3 -20 -10 0 -15 -6]; 34 | rcs = 10.^(rcs/10); 35 | 36 | mean_yp=mean(yp); 37 | dist_target=mean_yp - y(1); 38 | disp(['Aperture size = ' num2str(Lap*100) ' cm, aperture electric size = ' num2str(Lap/lambda_fMax) ' wavelengths']); 39 | disp(['Bandwidth = ' num2str(BW) ' GHz']); 40 | disp(['Cross-range resolution (approx). = ' num2str(100*lambda_fMax*dist_target/Lap) ' cm']); 41 | 42 | 43 | k = 2*pi.*f/3e8; 44 | 45 | % Calculation of the scattered field 46 | sigma = zeros(numel(f),numel(x)); 47 | sigma_log = sigma; 48 | 49 | for q= 1:numel(f) 50 | for p=1:numel(x) 51 | Rp = sqrt((x(p)-xp).^2+(y(p)-yp).^2); 52 | sigma (q,p) = sum((rcs.*exp(-1*j*2*k(q)*Rp))./(Rp.^2)); 53 | sigma_log(q,p) = 10*log10(abs(sigma(q,p))); 54 | end 55 | sigma_norm(q,:) = sigma_log(q,:)- max(sigma_log(q,:)); 56 | end 57 | 58 | % FIGURE 1 - SCATTERED FIELDS 59 | figure 60 | plot(x,sigma_norm(1,:),'linewidth',2); 61 | hold on 62 | plot(x,sigma_norm((end+1)/2,:),'r','linewidth',2); 63 | hold on 64 | plot(x,sigma_norm(end,:),'k','linewidth',2); 65 | xlabel('x(m)'); 66 | ylabel('Scattered field (dBV/m)'); 67 | legend('f = 18GHz','f = 22GHz','f = 26GHz'); 68 | axis([min(x) max(x) -20 0]); 69 | grid on; box on; 70 | 71 | 72 | % SAR imaging ============================================================= 73 | 74 | % Imaging domain 75 | dL = dx/2; 76 | X0 = [x(1) : dL: x(end)]; 77 | Y0 = [0.2 : dL: 0.6] + y(1); 78 | [X1 Y1] = meshgrid(X0,Y0); 79 | xprima = reshape (X1,numel(X1),1); 80 | yprima = reshape (Y1,numel(Y1),1); 81 | 82 | %reflectivity 83 | refl = zeros(numel(xprima),1); 84 | 85 | % Coherent combination of frequencies and aperture positions 86 | for q = 1:numel(f) 87 | for p = 1:numel(x) 88 | Rp = sqrt((x(p)-xprima).^2+(y(p)-yprima).^2); 89 | refl =refl+ sigma(q,p).*exp(1*j*2*k(q)*Rp); 90 | end 91 | end 92 | reflXY = refl/max(abs(refl)); 93 | reflXY = reshape(reflXY,size(X1)); 94 | reflXY = 10*log10(abs(reflXY)); 95 | 96 | % FIGURE 2 - SAR IMAGE 97 | figure; 98 | hold on; 99 | 100 | %Plots the synthetic aperture radar positions 101 | plot(x,y,'bo','markerfacecolor','b'); 102 | grid on; 103 | 104 | % Plots the reflectivity - SAR image - 105 | pcolor ( X1,Y1, reflXY); 106 | shading interp; 107 | set(gcf,'renderer','zbuffer'); 108 | xlabel('x axis (m)') 109 | ylabel('y axis (m)') 110 | title(['SAR image, reflectivity, in dB, BW = ' num2str(BW) ' GHz']); 111 | caxis([-40 0]); 112 | grid on; colorbar; 113 | set(gca,'dataaspectratio',[1 1 1]); 114 | 115 | % Plots the targets with marker size proportional to RCS 116 | rcs=10*log10(rcs); 117 | rcs_size=[4:1:16]; 118 | rcs_scale=linspace(min(rcs),max(rcs),numel(rcs_size)); 119 | for n=1:numel(rcs) 120 | [kk ind]=min(abs(rcs(n)-rcs_scale)); 121 | plot(xp(n),yp(n),'ko','markersize',rcs_size(ind),'markerfacecolor','none','linewidth',2); 122 | end 123 | box on; 124 | 125 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_gprMax_multi.m: -------------------------------------------------------------------------------- 1 | function [x_prima ,y_prima ,imagen] = SAR_gprMax_multi(filename, lim, eps) 2 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 3 | header.dt = h5readatt(filename, '/', 'dt'); 4 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 5 | % Detailed explanation goes here 6 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 7 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 8 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 9 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 10 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 11 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 12 | %Cargamos campo, tiempo y el numero de traza 13 | field = fields.ez; 14 | %field1=field(200:end,:)';%Quitamos el acoplo. Para la fft, tienen que estar en filas 15 | time = 0:header.dt:header.iterations * header.dt; 16 | prof = time*3e8/2; 17 | index2=find(prof >= 0.27 & prof <= 0.77); 18 | index=find(prof <= 0.30); 19 | %field1 = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 20 | media=zeros(size(field)); 21 | media(index,:)=field(index,:); 22 | field = field - repmat(sum(media,2)/size(media,2),1,size(media,2)); 23 | traces = 0:size(field,2)-1; 24 | %field = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 25 | %Definimos el eje de frecuencias 26 | NFFT=2^nextpow2(length(field));%Numero de puntos de la fft optimo 27 | Fs=1/header.dt;%Frecuencia de muestreo del GprMax 28 | f=linspace(-Fs/2,Fs/2,NFFT); 29 | f=f(f>=0);%Frecuencias positivas 30 | %Hacemos fftshift que centra la frecuencia cero en dimension 1(por 31 | %columnas) 32 | FIELD1=fft(field,NFFT,1); 33 | FIELD=FIELD1(1:length(f),:);%Nos quedamos en el campo en frecuencias positivas 34 | %Preparamos la matriz que va a multiplicar al campo 35 | k0=2*pi*f/3e8; 36 | k=[k0*sqrt(eps(1)); k0*sqrt(eps(2)); k0*sqrt(eps(3))]; 37 | %Definimos las coordenadas de la imagen 38 | x_prima=traces*0.008;%0.025; 39 | %y_prima=0.15:0.01:0.85-0.01; 40 | y_prima=prof(index2); 41 | 42 | [X,Y]=meshgrid(x_prima,y_prima);%Para hacer la matriz de distancias 43 | %Matriz de exponenciales 44 | imagen=zeros(length(y_prima),length(x_prima), numel(k0));%Creacion de la matriz de la imagen SAR 45 | 46 | D1=zeros(length(y_prima),length(x_prima),size(FIELD,2)); 47 | D2=D1; 48 | D3=D1; 49 | for m=1:size(FIELD,2) 50 | for i=1:length(y_prima) 51 | if y_prima(i) <= lim(1) 52 | D1(i,:,m)=sqrt((x_prima(m)-X(i,:)).^2+y_prima(i).^2); 53 | elseif y_prima(i) > lim(1) && y_prima(i) <= lim(2) 54 | x2 = x_prima(m) - X(i,:); 55 | ratio=sqrt(eps(1)/(eps(2)));%Ponderacion dependiente de Er2 56 | xb=x2+ratio*(x2*lim(1)./y_prima(i)-x2);%Distancia x del la ruta optima 57 | D1(i,:,m)=sqrt(lim(1)^2+xb.^2); 58 | D2(i,:,m)=sqrt((y_prima(i)-lim(1)).^2+(x2-xb).^2); 59 | else 60 | x3 = x_prima(m) - X(i,:); 61 | num = (1 + sqrt(eps(2)/eps(3)) * (lim(2) - y_prima(i)) / (y_prima(i) - lim(1)))*x3; 62 | denom = (1 - sqrt(eps(2)/eps(3)) * (y_prima(i) - lim(2)) / (y_prima(i) - lim(1)) - sqrt(eps(1)/eps(3)) * (y_prima(i) - lim(2)) * (lim(1) - lim(2)) / ((y_prima(i) - lim(1)) * lim(2))); 63 | xb2 = num / denom; 64 | xb1 = xb2 * (1 + sqrt(eps(1)/eps(2)) * (lim(1) - lim(2)) / lim(2)); 65 | D1(i,:,m)=sqrt(lim(1)^2+xb1.^2); 66 | D2(i,:,m)=sqrt((lim(2)-lim(1))^2+(xb2-xb1).^2); 67 | D3(i,:,m)=sqrt((y_prima(i)-lim(2)).^2+(x3-xb2).^2); 68 | end 69 | end 70 | end 71 | 72 | bp=waitbar(0,'Procesado DAS proyeccion 3D'); 73 | for m=1:size(FIELD,2)%Se recorren las antenas 74 | %disp(['Medida m = ' num2str(m) ' de ' num2str(Nx*Ny)]); 75 | for n=1:numel(k0) 76 | S=FIELD(n,:); 77 | imagen(:,:,n)=imagen(:,:,n)+S(m)*exp(2j*(k(1,n)*D1(:,:,m)+k(2,n)*D2(:,:,m)+k(3,n)*D3(:,:,m))); %*(4*pi*2*D*f(n)/(3e8*2*D0int(n))). 78 | end 79 | 80 | waitbar(m/(size(FIELD,2)),bp,sprintf('%0.2f %%',100*m/(size(FIELD,2)))); 81 | end 82 | close(bp) 83 | imagen = sum(imagen,3); 84 | 85 | end 86 | -------------------------------------------------------------------------------- /ProcesadoSAR/gprMaxLoadBscan.m: -------------------------------------------------------------------------------- 1 | function [header, fields] = gprMaxLoadBscan(filename) 2 | % gprmaxLoadOutput loads HDF5 output files from gprMax (www.gprmax.com) 3 | % 4 | % [header, fields] = gprMaxLoadBscan(filename) loads B-scan data from a 5 | % HDF5 output file from gprMax whose name is given by 6 | % filename. A structure containing model information 7 | % (header), and a structure containing time histories 8 | % of EM field values (fields) from receivers in the 9 | % model are returned. For more information on the 10 | % structure of the HDF5 file see 11 | % http://docs.gprmax.com/en/latest/output.html 12 | % 13 | % Author: Craig Warren (Craig.Warren@ed.ac.uk) 14 | % Date: 03/05/2017 15 | % 16 | 17 | % Properties contained in the B-scan (merged collection of A-scans) 18 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 19 | header.dt = h5readatt(filename, '/', 'dt'); 20 | 21 | % Time vector for plotting 22 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 23 | 24 | % Load fields 25 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 26 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 27 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 28 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 29 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 30 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 31 | 32 | % Plot B-scan (edit field to point to either Ex or Ey component 33 | field = fields.ez; 34 | time = 0:header.dt:header.iterations * header.dt; 35 | traces = 0:size(field,2); 36 | 37 | fh1=figure('Name', filename); 38 | clims = [-max(max(abs(field))) max(max(abs(field)))]; 39 | im = imagesc(traces, time, field, clims); 40 | xlabel('Trace number'); 41 | ylabel('Time [s]'); 42 | c = colorbar; 43 | c.Label.String = 'Field strength [V/m]'; 44 | ax = gca; 45 | ax.FontSize = 16; 46 | xlim([0 traces(end)]); 47 | 48 | fielddB = 20*log10(abs(field/max(max(field)))); 49 | fh2=figure('Name', filename); 50 | clims = [-60 0]; 51 | im = imagesc(traces, time, fielddB, clims); 52 | xlabel('Trace number'); 53 | ylabel('Time [s]'); 54 | c = colorbar; 55 | c.Label.String = 'Normalized field strength [dB]'; 56 | ax = gca; 57 | ax.FontSize = 16; 58 | xlim([0 traces(end)]); 59 | 60 | fh3=figure('Name', filename); 61 | clims = [-60 0]; 62 | im = imagesc(traces*0.025, time*3e8/2, fielddB, clims); 63 | xlabel('Aperture [m]'); 64 | ylabel('Distance [m]'); 65 | c = colorbar; 66 | c.Label.String = 'Normalized field strength [dB]'; 67 | ax = gca; 68 | ax.FontSize = 16; 69 | 70 | index_tg = 200; 71 | fielddB_tg = fielddB(index_tg:end,:); 72 | fielddB_tg = fielddB_tg-max(max(fielddB_tg)); 73 | time_tg = time(index_tg:end); 74 | fh4=figure('Name', filename); 75 | clims = [-30 0]; 76 | im = imagesc(traces*0.025, time_tg*3e8/2, fielddB_tg, clims); 77 | xlabel('Aperture [m]'); 78 | ylabel('Distance [m]'); 79 | c = colorbar; 80 | c.Label.String = 'Normalized field strength [dB]'; 81 | ax = gca; 82 | ax.FontSize = 16; 83 | 84 | % % Options to create a nice looking figure for display and printing 85 | % set(fh1,'Color','white','Menubar','none'); 86 | % X = 60; % Paper size 87 | % Y = 30; % Paper size 88 | % xMargin = 0; % Left/right margins from page borders 89 | % yMargin = 0; % Bottom/top margins from page borders 90 | % xSize = X - 2*xMargin; % Figure size on paper (width & height) 91 | % ySize = Y - 2*yMargin; % Figure size on paper (width & height) 92 | % 93 | % % Figure size displayed on screen 94 | % set(fh1, 'Units','centimeters', 'Position', [0 0 xSize ySize]) 95 | % movegui(fh1, 'center') 96 | % 97 | % % Figure size printed on paper 98 | % set(fh1,'PaperUnits', 'centimeters') 99 | % set(fh1,'PaperSize', [X Y]) 100 | % set(fh1,'PaperPosition', [xMargin yMargin xSize ySize]) 101 | % set(fh1,'PaperOrientation', 'portrait') 102 | end -------------------------------------------------------------------------------- /ImagePartition/codigo_original.m: -------------------------------------------------------------------------------- 1 | % Demo to use normxcorr2 to find a template (a white onion) 2 | % in a larger image (of a pile of vegetables) 3 | clc; % Clear the command window. 4 | close all; % Close all figures (except those of imtool.) 5 | imtool close all; % Close all imtool figures. 6 | clear; % Erase all existing variables. 7 | workspace; % Make sure the workspace panel is showing. 8 | format long g; 9 | format compact; 10 | fontSize = 14; 11 | 12 | % Check that user has the Image Processing Toolbox installed. 13 | hasIPT = license('test', 'image_toolbox'); 14 | if ~hasIPT 15 | % User does not have the toolbox installed. 16 | message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?'); 17 | reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes'); 18 | if strcmpi(reply, 'No') 19 | % User said No, so exit. 20 | return; 21 | end 22 | end 23 | 24 | % Read in a standard MATLAB color demo image. 25 | folder = '/'; 26 | baseFileName = 'test01i.jpg'; 27 | % Get the full filename, with path prepended. 28 | fullFileName = fullfile(folder, baseFileName); 29 | if ~exist(fullFileName, 'file') 30 | % Didn't find it there. Check the search path for it. 31 | fullFileName = baseFileName; % No path this time. 32 | if ~exist(fullFileName, 'file') 33 | % Still didn't find it. Alert user. 34 | errorMessage = sprintf('Error: %s\\%s does not exist.', folder, fullFileName); 35 | uiwait(warndlg(errorMessage)); 36 | return; 37 | end 38 | end 39 | rgbImage = imread(fullFileName); 40 | % Get the dimensions of the image. numberOfColorBands should be = 3. 41 | [rows, columns, numberOfColorBands] = size(rgbImage) 42 | % Display the original image. 43 | subplot(2, 3, 1); 44 | imshow(rgbImage, []); 45 | axis on; 46 | caption = sprintf('Original Color Image, %d rows by %d columns.', rows, columns); 47 | title(caption, 'FontSize', fontSize); 48 | % Enlarge figure to full screen. 49 | set(gcf, 'units','normalized','outerposition',[0, 0, 1, 1]); 50 | 51 | % Convert to binary 52 | if numberOfColorBands > 1 53 | binaryImage = rgbImage(:,:,1) > 200; 54 | else 55 | binaryImage = rgbImage > 200; 56 | end 57 | % Display the original image. 58 | subplot(2, 3, 2); 59 | imshow(binaryImage, []); 60 | axis on; 61 | caption = sprintf('Original Binary Image, %d rows by %d columns.', rows, columns); 62 | title(caption, 'FontSize', fontSize); 63 | 64 | % Clean up a bit. 65 | % binaryImage = imclearborder(binaryImage); 66 | binaryImage = imfill(~binaryImage, 'holes'); 67 | % Display the image. 68 | subplot(2, 3, 3); 69 | imshow(binaryImage, []); 70 | axis on; 71 | caption = sprintf('Cleaned Binary Image, %d rows by %d columns.', rows, columns); 72 | title(caption, 'FontSize', fontSize); 73 | drawnow; % Force it to refresh. 74 | 75 | labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it 76 | coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels 77 | 78 | subplot(2, 3, 4); 79 | imshow(labeledImage, []); 80 | title('Labeled Image, from bwlabel()', 'FontSize', fontSize); 81 | subplot(2, 3, 5); 82 | imshow(coloredLabels); 83 | caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.'); 84 | title(caption, 'FontSize', fontSize); 85 | drawnow; % Force it to refresh. 86 | 87 | % Get all the blob properties. Can only pass in originalImage in version R2008a and later. 88 | blobMeasurements = regionprops(labeledImage, 'all'); 89 | numberOfBlobs = size(blobMeasurements, 1); 90 | 91 | % Now I'll demonstrate how to select certain blobs based using the ismember function. 92 | % Let's say that we wanted to find only those blobs 93 | % with an intensity between 150 and 220 and an area less than 2000 pixels. 94 | % This would give us the three brightest dimes (the smaller coin type). 95 | %allPerimeters = [blobMeasurements.Perimeter] 96 | allAreas = [blobMeasurements.Area]; 97 | %allCircularities = allPerimeters .^ 2 ./ (4 * pi * allAreas); 98 | %sortedCirc = sort(allCircularities, 'Ascend') 99 | 100 | % Get a list of the blobs that meet our criteria and we need to keep. 101 | %allowablecircIndexes = (allCircularities < 6); 102 | allowableAreaIndexes = allAreas > 100; % Take the big objects. 103 | keeperIndexes = find(allowableAreaIndexes); 104 | % Extract only those blobs that meet our criteria, and 105 | % eliminate those blobs that don't meet our criteria. 106 | % Note how we use ismember() to do this. 107 | keeperBlobsImage = ismember(labeledImage, keeperIndexes); 108 | % Re-label with only the keeper blobs kept. 109 | labeledImage = bwlabel(keeperBlobsImage, 8); % Label each blob so we can make measurements of it 110 | % Now we're done. We have a labeled image of blobs that meet our specified criteria. 111 | subplot(2, 3, 6); 112 | imshow(labeledImage, []); 113 | title('"Keeper" blobs', 'FontSize', fontSize); 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /ProcesadoSAR/SAR_gprMax_PWSAR.m: -------------------------------------------------------------------------------- 1 | function [ x_prima ,z_prima ,refl ] = SAR_gprMax_PWSAR( filename, lim, eps, sigma ) 2 | header.iterations = double(h5readatt(filename,'/', 'Iterations')); 3 | header.dt = h5readatt(filename, '/', 'dt'); 4 | fields.time = linspace(0, (header.iterations)*(header.dt)*1E9, header.iterations); 5 | % Detailed explanation goes here 6 | fields.ex = h5read(filename, strcat('/rxs/rx1/', 'Ex'))'; 7 | fields.ey = h5read(filename, strcat('/rxs/rx1/', 'Ey'))'; 8 | fields.ez = h5read(filename, strcat('/rxs/rx1/', 'Ez'))'; 9 | fields.hx = h5read(filename, strcat('/rxs/rx1/', 'Hx'))'; 10 | fields.hy = h5read(filename, strcat('/rxs/rx1/', 'Hy'))'; 11 | fields.hz = h5read(filename, strcat('/rxs/rx1/', 'Hz'))'; 12 | %Cargamos campo, tiempo y el numero de traza 13 | field = fields.ez; 14 | 15 | %field1=field(200:end,:)';%Quitamos el acoplo. Para la fft, tienen que estar en filas 16 | time = 0:header.dt:header.iterations * header.dt; 17 | prof = time(1:(end-1))*3e8/2; 18 | index2=find(prof >= 0.17 & prof<=0.87); 19 | index=find(prof <= 0.27); 20 | %field = field(index:end,:);%Quitamos los 15 primeros centrimetos de la medida 21 | media=zeros(size(field)); 22 | media(index,:)=field(index,:); 23 | field = field - repmat(sum(media,2)/size(media,2),1,size(media,2)); 24 | 25 | traces = 0:size(field,2)-1; 26 | %Definimos el eje de frecuencias 27 | NFFT=2^nextpow2(length(field));%Numero de puntos de la fft optimo 28 | Fs=1/header.dt;%Frecuencia de muestreo del GprMax 29 | f=linspace(-Fs/2,Fs/2,NFFT); 30 | f=f(f>=0);%Frecuencias positivas 31 | ind=find(f>=0.1e9 & f<=6e9); 32 | f=f(ind); 33 | 34 | %Hacemos fftshift que centra la frecuencia cero en dimension 1(por 35 | %columnas) 36 | S1=fft(field,NFFT,1); 37 | S=S1(ind,:);%Nos quedamos en el campo en frecuencias positivas 38 | 39 | % f=f(1:4:end); 40 | % S=S(1:4:end,:); 41 | 42 | S=permute(S,[2 3 1]); 43 | Sk=fft(S,[],1); 44 | Sk=fftshift(Sk,1); 45 | % Sk=fft(Sk,[],2); 46 | % Sk=fftshift(Sk,2); 47 | 48 | %x_prima=traces*0.025; 49 | x_prima=traces*0.008; 50 | y_prima=0; 51 | %z_prima=0.15:0.01:0.85-0.01; 52 | z_prima=prof(index2); 53 | 54 | ksx=2*pi/0.008; 55 | kx=linspace(-ksx/2,ksx/2,length(x_prima)); 56 | ky=0; 57 | 58 | epsc=repmat(eps,length(f),1)-36j*pi*repmat(sigma,length(f),1)... 59 | ./(2*pi*repmat(permute(f,[2 1]),1,length(eps))*1e-9); 60 | %kz1=sqrt(4*(2*pi*permute(repmat(f,length(kx),1),[1,3,2])/3e8).^2-permute(repmat(kx,length(f),1),[2 3 1]).^2); 61 | kz=sqrt(4*(2*pi*permute(repmat(f,length(kx),length(ky),1,length(eps)),[1,3,2,4]).*real(sqrt(repmat(permute(epsc,[4 3 1 2]),... 62 | length(kx),length(ky),1)))/3e8).^2-permute(repmat(kx,length(f),length(ky),1,length(eps)),[2 3 1 4]).^2); 63 | 64 | kzc=sqrt(4*(2*pi*permute(repmat(f,length(kx),length(ky),1,length(eps)),[1,3,2,4]).*sqrt(repmat(permute(epsc,[4 3 1 2]),... 65 | length(kx),length(ky),1))/3e8).^2-permute(repmat(kx,length(f),length(ky),1,length(eps)),[2 3 1 4]).^2); 66 | % T12=2*eps*kz1./(eps*kz1+1*k2z); 67 | % T21=2*1*kz2./(1*kz2+eps*kz1); 68 | % kz1(kz1.*kz1 < 0) = 0; 69 | [X,Y]=meshgrid(eps); 70 | [Xc,Yc]=meshgrid(sigma); 71 | T=ones(size(kz)); 72 | for a=2:length(eps) 73 | for c=1:length(f) 74 | T(:,:,c,a)=2*(Y(a-1,a)-36j*pi*Yc(a-1,a)/(2*pi*f(c)*1e-9))... 75 | *kzc(:,:,c,a-1)./((Y(a-1,a)-36j*pi*Yc(a-1,a)/(2*pi*f(c)*1e-9))... 76 | *kzc(:,:,c,a-1)+(X(a-1,a)-36j*pi*Xc(a-1,a)/(2*pi*f(c)*1e-9))*kzc(:,:,c,a)); 77 | T(:,:,c,a)=T(:,:,c,a).*(2*(Y(a,a-1)-36j*pi*Yc(a,a-1)/(2*pi*f(c)*1e-9))... 78 | *kzc(:,:,c,a)./((Y(a,a-1)-36j*pi*Yc(a,a-1)/(2*pi*f(c)*1e-9))... 79 | *kzc(:,:,c,a)+(X(a,a-1)-36j*pi*Xc(a,a-1)/(2*pi*f(c)*1e-9))*kzc(:,:,c,a-1))); 80 | end 81 | 82 | 83 | end 84 | 85 | kz(kz.*kz < 0) = 0; %Solo nos quedamos con la parte real 86 | 87 | %Estan ordenados en la cuarta dimension 88 | 89 | refl=zeros(numel(x_prima),length(y_prima),numel(z_prima)); 90 | 91 | mu=4*pi*1e-7; 92 | epsilon=8.8542e-12; 93 | caten=real(1j*2*pi*repmat(permute(f,[3 4 2 1]),... 94 | length(kx),length(ky),1,length(eps))... 95 | .*sqrt(mu*epsilon*repmat(permute(eps,[3 4 1 2]),length(kx),... 96 | length(ky),length(f),1)).*... 97 | sqrt(1-1j*repmat(permute(sigma,[3 4 1 2])... 98 | ,length(kx),length(ky),length(f),1)./(... 99 | repmat(permute(f,[3 4 2 1]),length(kx),length(ky),1,length(eps))... 100 | .*repmat(permute(eps,[3 4 1 2]),length(kx),length(ky),length(f),1)*epsilon))); 101 | 102 | for i=1:numel(z_prima) 103 | for j=1:numel(f) 104 | log = z_prima(i) >= lim; 105 | pos = find(log,1,'last'); 106 | if pos>1 107 | refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*prod(exp(1j*kz(:,:,j,1:pos-1)... 108 | .*repmat(permute(lim(2:pos)-lim(1:pos-1),[4 3 1 2]),size(kz(:,:,1,1)))),4).*exp(1j*kz(:,:,j,pos)*(z_prima(i)-lim(pos)))... 109 | ./prod(T(:,:,j,2:pos),4)... 110 | .*(1.11.^(caten(:,:,j,pos)*(z_prima(i)-lim(pos)))... 111 | .*prod(1.11.^(caten(:,:,j,1:pos-1).*repmat(permute(lim(2:pos)... 112 | -lim(1:pos-1),[4 3 1 2]),size(kz(:,:,1,1)))),4));%.*prod(exp(1j*angle(T(:,:,j,2:pos))),4); 113 | else 114 | refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz(:,:,j,pos)*z_prima(i)); 115 | end 116 | % if z_prima(i)<=lim 117 | % refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz1(:,:,j)*z_prima(i)); 118 | % else 119 | % refl(:,:,i)=refl(:,:,i)+Sk(:,:,j).*exp(1j*kz1(:,:,j)*lim).*exp(1j*kz2(:,:,j)*(z_prima(i)-lim))./exp(-1j*angle(T12(:,:,j).*T21(:,:,j))); 120 | % end 121 | end 122 | end 123 | refl=ifftshift(refl,1); 124 | refl=ifft(refl,[],1); 125 | % refl=ifft(refl,[],2); 126 | % refl=ifftshift(refl,2); 127 | refl=permute(refl,[3 1 2]); 128 | 129 | end 130 | 131 | 132 | 133 | --------------------------------------------------------------------------------