#include "../indexcalculation/indexcalculation/imagemosaicing.h"
#include #include #include #include "gdal_priv.h"
using namespace std;
int main()
bool isimagemosaicing=imgmerge.startimagemosaicing(0);
if (!isimagemosaicing)
system("pause");
return 0;
}
#include #include #include #include "gdal_priv.h"
#include "gdalwarper.h"
using namespace std;
class imagemosaicing;
#include "imagemosaicing.h"
imagemosaicing::imagemosaicing()
bool imagemosaicing::creatmergeimage(vectorpszfilename,const char* outputpszfilename);
double extent[4] = ;
vectorxlist, ylist, xresolution, yresolution;
for (int i = 0; i < imagenumber; i++)
nbandnumber = imagemulti[i]->getrastercount();
imageprojection = imagemulti[i]->getprojectionref();
if (imageprojection == null || imageprojection == "")
gedt = imagemulti[i]->getrasterband(1)->getrasterdatatype();
int irasterxsize = imagemulti[i]->getrasterxsize();
int irasterysize = imagemulti[i]->getrasterysize();
gdalgetgeotransform(imagemulti[i], thisgeotranform);//求解仿射變換矩陣
xlist.push_back(extent[0]);
xlist.push_back(extent[2]);
ylist.push_back(extent[1]);
ylist.push_back(extent[3]);
xresolution.push_back(thisgeotranform[1]);
yresolution.push_back(fabs(thisgeotranform[5]));
} double xlistmax = *max_element(xlist.begin(), xlist.end());
double xlistmin = *min_element(xlist.begin(), xlist.end());
double ylistmax = *max_element(ylist.begin(), ylist.end());
double ylistmin = *min_element(ylist.begin(), ylist.end());
xresolutionmin = *min_element(xresolution.begin(), xresolution.end());
yresolutionmin = *min_element(yresolution.begin(), yresolution.end());
double outputgeotransform[6] = ;
outputgeotransform[0] = xlistmin;
outputgeotransform[1] = xresolutionmin;
outputgeotransform[2] = 0.0;
outputgeotransform[3] = ylistmax;
outputgeotransform[4] = 0.0;
outputgeotransform[5] = -yresolutionmin;
int outputirasterxsize = (int)((xlistmax - xlistmin) / xresolutionmin + 0.5);
int outputirasterysize = (int)((ylistmax - ylistmin) / yresolutionmin + 0.5);
gdaldriver *gdal_output;
gdal_output = getgdaldrivermanager()->getdriverbyname("gtiff");
gdaldataset *outputpodata = gdal_output->create(outputpszfilename, outputirasterxsize, outputirasterysize, nbandnumber, gedt, null);//建立輸出空白影像
if (outputpodata == null)
outputpodata->setgeotransform(outputgeotransform);//設定輸出影像的仿射變換矩陣
outputpodata->setprojection(imageprojection);//設定投影
//關閉指標
for (int i = 0; i < imagenumber; i++)
gdalclose(outputpodata);
return true;
}bool imagemosaicing::startimagemosaicing(int imageresampletype)
void *htransformarg = null;
htransformarg = gdalcreategenimgprojtransformer2(hsrcimage, hdstimage, null);//建立源影像和目標影像的轉換引數
if (htransformarg==null)
gdaltransformerfunc pfntransformer = null;
pfntransformer = gdalgenimgprojtransform;
gdalwarpoptions *pswo = gdalcreatewarpoptions();//設定轉換引數
pswo->hsrcds = hsrcimage;//源影像指標
pswo->hdstds = hdstimage;//目標影像指標
pswo->eworkingdatatype = gedt;//影像資料型別
pswo->nbandcount = nbandnumber;//波段數
pswo->eresamplealg = imageresampletype;//重取樣型別
pswo->ptransformerarg = htransformarg;//不同座標系的轉換引數
pswo->pfntransformer = pfntransformer;//座標轉換的函式指標
pswo->pansrcbands = (int *)cplmalloc(pswo->nbandcount*sizeof(int));//開闢記憶體儲存波段順序(源影像)
pswo->pandstbands = (int *)cplmalloc(pswo->nbandcount*sizeof(int));//開闢記憶體儲存波段順序(目標影像)
for (int i_band = 0; i_band < nbandnumber; i_band++)
gdalwarpoperation gwo;//轉換操作
int xsizedstimage = hdstimage->getrasterxsize();
int ysizedstimage = hdstimage->getrasterysize();
if (gwo.initialize(pswo)==ce_none)
if (htransformarg!=null)
gdaldestroywarpoptions(pswo);//銷毀操作指標
gdalclose(hsrcimage);//關閉源影像
鑲嵌結果:
使用GDAL讀取影像
最近在學習gdal和opencv,gdal的強大功能我就不用說了,大家上網可以查到很多關於它的資料。opencv是乙個開源的計算機視覺庫,可以去opencv中文論壇具體了解它,說下我的構思吧,opencv庫里有很多關於數字影象處理的函式,但是它卻侷限於遙感影象的讀取,而gdal卻對遙感影像的讀取支援...
遙感影像鑲嵌及實現 一
遙感影像鑲嵌及實現 一 影像鑲嵌是將多幅帶有地理資訊的影像輸出為一幅大範圍覆蓋影像的一種遙感影像處理功能。這些影像是需要經過正射校正,融合 勻光勻色,然後進行鑲嵌。鑲嵌的關鍵是構建輸入影像的鑲嵌線網路,然後根據鑲嵌線輸出影像。在遙感處理流程中,主要的流程是 輸入全色及多光譜1a級影像,為了克服各種因...
C 使用GDAL讀取與建立影像
中都加了凝視,這裡就不再一一敘述了。例如以下 class floodsimulation 載入淹沒區dem,並建立淹沒範圍影像 dem檔案路徑 public void loaddataset string m demfilepath 在gdal中建立影像,先須要明白待建立影像的格式,並獲取到該影像格...