public boolean load(boolean flipX, boolean flipY) {

        int imageWidth = colorImage.getWidth();
        int imageHeight = colorImage.getHeight();

        if (imageWidth != imageHeight)
                throw new RuntimeException("imageWidth: " + imageWidth
                        + " != imageHeight: " + imageHeight);

        size = imageWidth;
        ImageRaster raster = getImageRaster();

        heightData = new float[(imageWidth * imageHeight)];

        ColorRGBA colorStore = new ColorRGBA();
        
        int index = 0;
        if (flipY) {
            for (int h = 0; h < imageHeight; ++h) {
                if (flipX) {
                    for (int w = imageWidth - 1; w >= 0; --w) {
                        //int baseIndex = (h * imageWidth)+ w;
                        //heightData[index++] = getHeightAtPosition(raster, baseIndex, colorStore)*heightScale;
                        heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale*backwardsCompScale;
                    }
                } else {
                    for (int w = 0; w < imageWidth; ++w) {
                        //int baseIndex = (h * imageWidth)+ w;
                        //heightData[index++] = getHeightAtPosition(raster, baseIndex, colorStore)*heightScale;
                        heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale*backwardsCompScale;
                    }
                }
            }
        } else {
            for (int h = imageHeight - 1; h >= 0; --h) {
                if (flipX) {
                    for (int w = imageWidth - 1; w >= 0; --w) {
                        //int baseIndex = (h * imageWidth)+ w;
                        //heightData[index++] = getHeightAtPosition(raster, baseIndex, colorStore)*heightScale;
                        heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale*backwardsCompScale;
                    }
                } else {
                    for (int w = 0; w < imageWidth; ++w) {
                        //int baseIndex = (h * imageWidth)+ w;
                        //heightData[index++] = getHeightAtPosition(raster, baseIndex, colorStore)*heightScale;
                        heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale*backwardsCompScale;
                    }
                }
            }
        }

        return true;
    }
Get the grayscale value, or override in your own sub-classes
jme3-terrain/src/main/java/com/jme3/terrain/heightmap/ImageBasedHeightMap.java