3.2. ASF MapReady

Alaska Satellite Facility

3.2.1. 简介

MapReady 是由 ASF 开发的遥感数据处理工具, 主要用于处理各种SAR数据, 尤其适合处理 CEOS 格式的数据, 其源码可以在 这里 获得. ASF MapReady 支持 ERS Level0 数据读取, 不支持 Sentinel Level0 数据读取.

注解

由 ASF MapReady 中的源码可知, 暂不支持 Sentinel Level0 级数据, 具体参见 src/libasf_import/import_sentinel.c 文件中的 import_sentinel() 函数:

if (strcmp_case(productType, “RAW”) == 0)

asfPrintError(“Product type ‘RAW’ currently not supported!n”);

else if (strcmp_case(productType, “SLC”) == 0 ||

strcmp_case(productType, “GRD”) == 0)

3.2.2. 安装 ASF MapReady

Ubuntu下配置安装

安装步骤如下:

  1. 安装依赖:

    sudo apt install gcc g++ bison flex libcunit1-dev libexif-dev libfftw3-dev libgdal-dev libgeotiff-dev libglade2-dev libglib2.0-dev libgsl-dev libgtk2.0-dev libjpeg-dev libpng-dev libproj-dev libshp-dev libtiff5-dev libxml2-dev
    
  2. 配置安装目录: ./configure --prefix=your_installation_path , 注意更改为自己的安装目录, 如 /mnt/e/sfw/sar/ASF_MapReady

  3. 构建: make 或多线程构建 make -j16

  4. 安装: make install

  5. 添加环境变量 export PATH=your_installation_path/bin:$PATH

安装完成后, 在终端输入 asf_mapready --help 可查看帮助并验证安装是否成功, 若安装成功, 则可以看到如下提示::

:~$ asf_mapready --help

Tool name:
   asf_mapready

Usage:
   asf_mapready [-create] [-input <inFile>] [-output <outFile>]
                [-tmpdir <dir>] [-log <logFile>] [-quiet] [-license]
                [-version] [-help]
                <config_file>

Description:
   This program can ingest level one CEOS and GeoTIFF format data, calibrate
   it to various radiometries, perform polarimetric decompositions, perform
   Faraday Rotation correction, perform terrain correction, geocode it, and
   then export it to a variety of graphics file formats. The user is able to
   control how asf_mapready dictates the processiong flow by creating a
   configuration file, which must then be edited, which is fed into
   asf_mapready when it is called.
:
:

3.2.3. ASF MapReady 源码分析

数据读取

asf_view --> read --> read_ceos/envi/seasat/terrasar/uavsar/tiff...

通过分析源码可知, ImageInfo 结构体是和读取显示图像相关的结构体, 在 asf_view.h 中定义了 ImageInfo 指针类型的两个变量( curr , mask )和一个数组( image_info )

// Can hold five images
#define MAX_IMAGES 5
extern ImageInfo image_info[MAX_IMAGES];
// "curr" always points to the currently being displayed image info
extern ImageInfo *curr;
extern ImageInfo *mask;
extern int current_image_info_index;
extern int n_images_loaded;

其中, 数组 image_info 存储多个图像 ImageInfo 结构体, curr 指针总是指向当前要显示的图像信息. ImageInfo 结构体中存储了待读取和显示图像的所有信息, 可以使用 cache.c 文件中的 get_pixel() 函数读取. ImageInfo 结构体成员如下.

struct ImageInfo
typedef struct {

int nl, ns; // number of lines(azimuth), number of samples(range)

meta_parameters *meta; // meta parameters

CachedImage *data_ci; //

BandConfig band_cfg;

ImageStats stats;

ImageStatsRGB stats_r;

ImageStatsRGB stats_g;

ImageStatsRGB stats_b;

char *filename;

char *data_name;

char *meta_name;

} ImageInfo;

其中 CachedImage 也是一个结构体, 其中存储着待读取图像的信息以及读取方法.

struct CachedImage

typedef struct { // Here is the ImageCache stuff. The global ImageCache that holds the loaded image is “data_ci”. This is all private data.

int nl, ns; // Image dimensions.

ClientInterface *client; // pointers to data read implementations

int n_tiles; // Number of tiles in memory

int reached_max_tiles; // Have we loaded as many tiles as we can?

int rows_per_tile; // Number of rows in each tile

int entire_image_fits; // TRUE if we can load the entire image

int *rowstarts; // Row numbers starting each tile

unsigned char **cache; // Cached values (floats, unsigned chars …)

int *access_counts; // Updated when a tile is accessed

int n_access; // used to find oldest tile

ssv_data_type_t data_type;// type of data we have

meta_parameters *meta; // metadata – don’t own this pointer

ImageStats *stats; // not owned by us, not populated by us

ImageStatsRGB *stats_r; // not owned by us, not populated by us

ImageStatsRGB *stats_g; // not owned by us, not populated by us

ImageStatsRGB *stats_b; // not owned by us, not populated by us

} CachedImage;

其中 ClientInterface 也是一个结构体, 其中存储着待读取图像的方法.

struct ClientInterface

typedef struct {

ReadClientFn *read_fn;

ThumbFn *thumb_fn;

FreeFn *free_fn;

void *read_client_info;

ssv_data_type_t data_type;

int require_full_load;

} ClientInterface;

如对于CEOS格式, read_fn 指向函数 read_ceos_client(), 其参数如下:

int read_ceos_client(int row_start, int n_rows_to_get, void *dest_void, void *read_client_info, meta_parameters *meta, int data_type)
  • row_start 读取起始行(azimuth)

  • n_rows_to_get 读取行数(azimuth)

  • dest_void 输出缓存指针

  • read_client_info 元信息指针

  • meta 元信息指针

  • data_type 数据类型

read_fn 指针指向的函数被 cache.c 文件中的 get_pixel() 函数调用, 格式如下:

self->client->read_fn(rs, rows_to_get, (void*)(self->cache[spot]),
       self->client->read_client_info, self->meta, self->client->data_type);

函数 get_pixel() 入口参数如下

static unsigned char *get_pixel(CachedImage *self, int line, int samp)
  • self CachedImage 指针

  • line 像素所在行

  • samp 像素所在列

函数 get_pixel() 被函数 cached_image_get_pixel() 调用, 函数 cached_image_get_pixel() 被函数 cached_image_new_from_file() 调用, 函数 cached_image_new_from_file() 又被函数 read_file() 调用. 总结调用如下

注解

ASF MapReady读取数据函数调用顺序为: main() –> on_new_button_clicked() –> new_file() –> load_file() –> load_file_banded() –> load_file_banded_imp() –> read_file() –> cached_image_new_from_file() –> cached_image_get_pixel() –> get_pixel() –> read_fn 指向的函数 (如 read_ceos_client()).

3.2.4. ASF MapReady 应用举例

数据导入

在终端输入 asf_import --help 可查看帮助,

导出 ERS2 Level0 级数据