キーワード: Locator
イテレータを多次元化したもの。
これ自身はイテレータではない。
GIL から提供されている Locator には memory_based_2d_locator と virtual_2d_locator の2つがあって、メモリ上のピクセルを扱うなら interleaved だろうが planar だろうが memory_based_2d_locator を使えば良い。
memory_based_2d_locator のテンプレート引数には StepIterator(Y 方向のイテレータ)を渡す。例えば以下のようなパラメータを。
- pixel
* (for interleaved images) - planar_pixel_iterator
(for planar images) - memory_based_step_iterator
*> (for interleaved images with non-standard step) - memory_based_step_iterator
> (for planar images with non-standard step)
X 方向のイテレータをカスタマイズする場合には、StepIterator のテンプレート引数を Iterator Adapter に変更すれば良い。
以下は Pixel Locator の使い方のサンプル
loc=img.xy_at(10,10); // start at pixel (x=10,y=10) above=loc.cache_location(0,-1); // remember relative locations of neighbors above and below below=loc.cache_location(0, 1); ++loc.x(); // move to (11,10) loc.y()+=15; // move to (11,25) loc-=point2<std::ptrdiff_t>(1,1);// move to (10,24) *loc=(loc(0,-1)+loc(0,1))/2; // set pixel (10,24) to the average of (10,23) and (10,25) (grayscale pixels only) *loc=(loc[above]+loc[below])/2; // the same, but faster using cached relative neighbor locations