antoverlay

PURPOSE ^

ANTOVERLAY - overlay a figure with image of Antarctica

SYNOPSIS ^

function antoverlay(fig1,fig2,alpha,colorbartitle,colmap,wrappingnumber,outlineflag,colorbarflag);

DESCRIPTION ^

ANTOVERLAY - overlay a figure with image of Antarctica

   Overlay figure1 image with Antarctica Power Image, and display on figure 2.
   
   Usage:
      antoverlay(fig1,fig2,alpha,colorbartitle,colmap,wrappingnumber,outlineflag,colorbarflag)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function antoverlay(fig1,fig2,alpha,colorbartitle,colmap,wrappingnumber,outlineflag,colorbarflag);
0002 %ANTOVERLAY - overlay a figure with image of Antarctica
0003 %
0004 %   Overlay figure1 image with Antarctica Power Image, and display on figure 2.
0005 %
0006 %   Usage:
0007 %      antoverlay(fig1,fig2,alpha,colorbartitle,colmap,wrappingnumber,outlineflag,colorbarflag)
0008 
0009 if ((nargin==0) || (nargin~=8)),
0010     help antoverlay;
0011     return;
0012 end
0013 
0014 %Capture image on figure fig1:
0015 figure(fig1)
0016 
0017 %Capture title
0018 t=get(gca,'Title');
0019 ti=get(t,'String');
0020 
0021 %First remove tick marks
0022 fig1xticks=get(gca,'XTick');
0023 fig1yticks=get(gca,'YTick');
0024 set(gca,'XTick',[]);
0025 set(gca,'YTick',[]);
0026 
0027 %Capture
0028 im=frame2im(getframe);
0029 
0030 %Capture max and min values
0031 maxminvalues=caxis;
0032 c1=maxminvalues(1);
0033 c2=maxminvalues(2);
0034 
0035 %flip image and rescale it.
0036 red=im(:,:,1);
0037 green=im(:,:,2);
0038 blue=im(:,:,3);
0039 im(:,:,1)=flipud(red);
0040 im(:,:,2)=flipud(green);
0041 im(:,:,3)=flipud(blue);
0042 
0043 %Get Size of image
0044 s=size(im);
0045 s1=s(1);
0046 s2=s(2);
0047 
0048 %Get coordinates of image
0049 xbound=xlim;
0050 ybound=ylim;
0051 x0=xbound(1);
0052 x1=xbound(2);
0053 y0=ybound(1);
0054 y1=ybound(2);
0055 
0056 
0057 %Create new image coordinates
0058 x_m=x0:(x1-x0)/(s2-1):x1;
0059 y_m=y0:(y1-y0)/(s1-1):y1;
0060 
0061 %Now that image on figure fig1 is correctly setup, go fetch
0062 %the radar power image.
0063 path_gdal='/home/larour/gdal2/bin/';
0064 %the geotiff image is either 200m or 1km accuracy. We take the 1km accuracy if the domain
0065 %of fig1  is more than 1000 km.
0066 geotiff_name='/proj/tpfimos/larour/Glaciology/Model_Data/Mosaic_Tiff/amm125m_v2_200m.tif';
0067 if (max((x1-x0),(y1-y0))>1000000),
0068     geotiff_name='/proj/tpfimos/larour/Glaciology/Model_Data/Mosaic_Tiff/amm125m_v2_1km.tif';
0069 end
0070 inputname='./temp.tif';
0071 
0072 command=['system(''' path_gdal 'gdal_translate -projwin ' num2str(x0) ' ' num2str(y1) ' ' num2str(x1) ' ' num2str(y0) ' ' geotiff_name ' ' inputname ''');'];
0073 eval(command);
0074 
0075 %Read in temp.tif:
0076 radar=imread('temp.tif','TIFF');
0077 %make sure radar image is square
0078 r=size(radar);
0079 r1=r(1);
0080 r2=r(2);
0081 x_r=x0:(x1-x0)/(r2-1):x1;
0082 y_r=y0:(y1-y0)/(r1-1):y1;
0083 
0084 %Display radar image first
0085 figure(fig2)
0086 figure_position=[1604 4 1594 1123];
0087 set(fig2,'Position',figure_position);
0088 %Build square axes
0089 %size_axes=.8;
0090 %position_axes=[(1-size_axes*figure_position(4)/figure_position(3))/2 (1-size_axes)/2 size_axes*figure_position(4)/figure_position(3)  size_axes];
0091 %axes('Position',position_axes);
0092 rim=imagesc(x_r,y_r,flipud(radar));colormap('gray');
0093 xlim([x0 x1]);
0094 ylim([y0 y1]);
0095 set(gca,'YDir','normal');
0096 
0097 %Display captured image
0098 hold on
0099 iim=image(x_m,y_m,im);
0100 xlim([x0 x1]);
0101 ylim([y0 y1]);
0102 set(gca,'YDir','normal');
0103 position_axes=get(gca,'Position');
0104 
0105 %Take out ticks.
0106 set(gca,'XTick',[]); set(gca,'YTick',[]);
0107 set(gca,'XTickLabel',[]); set(gca,'YTickLabel',[]);
0108 
0109 
0110 %Set transparency of data image
0111 set(iim,'AlphaData',alpha);
0112 
0113 %Set title identical to the one from fig1
0114 title(ti,'Fontsize',18);
0115 
0116 for i=1:5,
0117     plot(x_m,y_m(i)*ones(length(x_m),1),'k');
0118     plot(x_m,y_m(length(y_m)-i+1)*ones(length(x_m),1),'k');
0119     plot(x_m(i)*ones(length(y_m),1),y_m,'k');
0120     plot(x_m(length(x_m)-i+1)*ones(length(y_m),1),y_m,'k');
0121 end
0122 
0123 
0124 if(outlineflag),
0125     %Read in outline of antarctica and display.
0126     load /proj/tpfimos/larour/Glaciology/Model_Data/Mosaic_Tiff/antarctica_outline
0127     disp('Select lower-left corner of outline image');
0128     [xcorner,ycorner]=ginput(1);
0129     disp('Select upper_right corner of outline image');
0130     [xcorner2,ycorner2]=ginput(1);
0131     %make sure ratio is conserved
0132     xcorner2=xcorner+(ycorner2-ycorner)*(length(outlinex)/length(outliney));
0133 
0134     position_outline=[position_axes(1)+position_axes(3)*(xcorner-x0)/(x1-x0),position_axes(2)+position_axes(4)*(ycorner-y0)/(y1-y0),(xcorner2-xcorner)/(x1-x0)*position_axes(3),(ycorner2-ycorner)/(y1-y0)*position_axes(4)];
0135     outline_axes=axes('Position',position_outline); 
0136     imagesc(outlinex,outliney,outline);set(outline_axes,'YDir','normal');
0137     save temp outlinex outliney outline
0138     set(outline_axes,'XTick',[]); set(outline_axes,'YTick',[]);
0139     set(outline_axes,'XTickLabel',[]); set(outline_axes,'YTickLabel',[]);
0140     hold on;
0141     %build box inside the continent
0142     for i=1:50,
0143         plot(x0:500:x1,(y0+500*i)*ones(length(x0:500:x1),1),'r');
0144         plot(x0:500:x1,(y1-500*i)*ones(length(x0:500:x1),1),'r');
0145         plot((x0+500*i)*ones(length(y0:500:y1),1),y0:500:y1,'r');
0146         plot((x1-500*i)*ones(length(y0:500:y1),1),y0:500:y1,'r');
0147     end
0148     %make border
0149     for i=1:50,
0150         plot(min(outlinex):500:max(outlinex),(min(outliney)+500*i)*ones(length(min(outlinex):500:max(outlinex)),1),'w');
0151         plot(min(outlinex):500:max(outlinex),(max(outliney)-500*i)*ones(length(min(outlinex):500:max(outlinex)),1),'w');
0152         plot((min(outlinex)+500*i)*ones(length(min(outliney):500:max(outliney)),1),min(outliney):500:max(outliney),'w');
0153         plot((max(outlinex)-500*i)*ones(length(min(outliney):500:max(outliney)),1),min(outliney):500:max(outliney),'w');
0154     end
0155 end
0156 
0157 %Build colorbar
0158 if(colorbarflag),
0159     disp('Select lower-left corner of colorbar');
0160     [xcorner,ycorner]=ginput(1);
0161     disp('Select upper-right corner of colorbar');
0162     [xcorner2,ycorner2]=ginput(1);
0163     position_colorbar=[position_axes(1)+position_axes(3)*(xcorner-x0)/(x1-x0),position_axes(2)+position_axes(4)*(ycorner-y0)/(y1-y0),(xcorner2-xcorner)/(x1-x0)*position_axes(3),(ycorner2-ycorner)/(y1-y0)*position_axes(4)];
0164 else
0165     position_colorbar=[.7,.05,.1,.02];
0166 end
0167 colim=zeros(1,length(colmap),3);
0168 colim(1,:,1)=colmap(:,1);
0169 colim(1,:,2)=colmap(:,2);
0170 colim(1,:,3)=colmap(:,3);
0171 colaxes=axes('Position',position_colorbar);
0172 image(colim);set(colaxes,'YDir','normal');
0173 set(colaxes,'XTick',[]);
0174 set(colaxes,'YTick',[]);
0175 %t=text(length(colmap)/2,2,[num2str(c2/wrappingnumber) ' ' colorbartitle]);
0176 t=text(0,0,num2str(c1));
0177 set(t,'FontSize',16,'HorizontalAlignment','left');
0178 t=text(length(colmap)/2,0,colorbartitle);
0179 set(t,'FontSize',16,'HorizontalAlignment','center');
0180 t=text(length(colmap),0,num2str(c2));
0181 set(t,'FontSize',16,'HorizontalAlignment','right');
0182 
0183 %We are done, reeastablish figure fig1 settings
0184 figure(fig1);
0185 set(gca,'XTick',fig1xticks);
0186 set(gca,'YTick',fig1yticks);
0187 
0188 %Make handle back for figure fig2
0189 figure(fig2);
0190 
0191

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003