2017-07-19 25 views
0

OSRM-Projectで双線形補間について質問があります。 私は「通常の」双線形補間を理解しています。ここではウィキペディアからの映像は、非常識です:双線形補間 - OSRM Rastersource

Bilinear Interpolation - Wikipedia

今私は、ラスタソースデータ用OSRM・プロジェクトで使用されている双一次補間を理解しようとしています。コードがどのように動作するか

// Query raster source using bilinear interpolation 
RasterDatum RasterSource::GetRasterInterpolate(const int lon, const int lat) const 
{ 
if (lon < xmin || lon > xmax || lat < ymin || lat > ymax) 
{ 
    return {}; 
} 

const auto xthP = (lon - xmin)/xstep; 
const auto ythP = 
    (ymax - lat)/
    ystep; // the raster texture uses a different coordinate system with y pointing downwards 

const std::size_t top = static_cast<std::size_t>(fmax(floor(ythP), 0)); 
const std::size_t bottom = static_cast<std::size_t>(fmin(ceil(ythP), height - 1)); 
const std::size_t left = static_cast<std::size_t>(fmax(floor(xthP), 0)); 
const std::size_t right = static_cast<std::size_t>(fmin(ceil(xthP), width - 1)); 

// Calculate distances from corners for bilinear interpolation 
const float fromLeft = xthP - left; // this is the fraction part of xthP 
const float fromTop = ythP - top; // this is the fraction part of ythP 
const float fromRight = 1 - fromLeft; 
const float fromBottom = 1 - fromTop; 

return {static_cast<std::int32_t>(raster_data(left, top) * (fromRight * fromBottom) + 
            raster_data(right, top) * (fromLeft * fromBottom) + 
            raster_data(left, bottom) * (fromRight * fromTop) + 
            raster_data(right, bottom) * (fromLeft * fromTop))}; 
} 

Original Code here

は、誰かが私に説明できますか?

入力フォーマットは、ASCII形式のSRTMデータです。

変数と幅NROWSncolumnsとして定義されます。

が同様のXSTEP最大ためYSTEPため高さある
return (max - min)/(static_cast<float>(count) - 1) 

XSTEPYSTEPは次のように定義されている 変数。

その他の質問 TIF形式のデータに同じコードを使用できますか?

+0

あなたが言うように、すでに双線形補間を理解しているなら、確かにこのコードの大部分を理解しているはずですか? – meowgoesthedog

+0

さて、私は明らかにする必要があります:私は双線形補間の理論を理解しています。私はこのコードの基本的な論理を理解していますが、なぜ私は理解できません。変数 "bottom"が計算され、特に "height - 1"となります。そして、 "fromX"変数の計算はどのように機能しますか? –

答えて

関連する問題