栅格重分类方法很多,在AE中有多种方式可以实现,使用地图代数(在RasterModel中实现),或者IReclassOp,或者Geoprocessor的方式都可以,甚至可以遍历栅格来实现,这是最原始的方式,不过也可能是最实用的。这里使用的是最原始的遍历栅格的方式。
public static void StrechDN(IRasterLayer pRasterLayer, int OTSU,int minValue, int maxValue)//修改二值化后的像素值
{
//获取栅格像素块
IRaster pRaster = pRasterLayer.Raster;
IRasterProps pRasterProps = (IRasterProps)pRaster; //rasterband;
//设置像素块的大小
IPnt pBlockSize1 = new PntClass();
pBlockSize1.SetCoords(pRasterProps.Width, pRasterProps.Height);
IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pBlockSize1);// raster2.CreateCursorEx(pBlockSize1).PixelBlock;
int w = pixelBlock.Width;
int h = pixelBlock.Height;
//read the first pixel block,左上点坐标
IPnt topleftCorner = new PntClass();
topleftCorner.SetCoords(0, 0);//左上角第一个像素点
pRaster.Read(topleftCorner, pixelBlock);//从第一个点开始读pixelBlock大小的像素块
//modify one pixel value at location