### Question:
NativeImageLoader extends BaseImageLoader { protected Mat centerCropIfNeeded(Mat img) { int x = 0; int y = 0; int height = img.rows(); int width = img.cols(); int diff = Math.abs(width - height) / 2; if (width > height) { x = diff; width = width - diff; } else if (height > width) { y = diff; height = height - diff; } return img.apply(new Rect(x, y, width, height)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); @Override String[] getAllowedFormats(); INDArray asRowVector(String filename); @Override INDArray asRowVector(File f); @Override INDArray asRowVector(InputStream is); INDArray asRowVector(Object image); INDArray asRowVector(Frame image); INDArray asRowVector(Mat image); INDArray asRowVector(org.opencv.core.Mat image); INDArray asMatrix(String filename); @Override INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); @Override INDArray asMatrix(InputStream is); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); Image asImageMatrix(String filename); @Override Image asImageMatrix(File f); @Override Image asImageMatrix(File f, boolean nchw); @Override Image asImageMatrix(InputStream is); @Override Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(Object image); void asMatrixView(InputStream is, INDArray view); void asMatrixView(String filename, INDArray view); void asMatrixView(File f, INDArray view); void asMatrixView(Mat image, INDArray view); void asMatrixView(org.opencv.core.Mat image, INDArray view); INDArray asMatrix(Frame image); INDArray asMatrix(org.opencv.core.Mat image); INDArray asMatrix(Mat image); ImageWritable asWritable(String filename); ImageWritable asWritable(File f); INDArray asMatrix(ImageWritable writable); Frame asFrame(INDArray array); Frame asFrame(INDArray array, int dataType); Mat asMat(INDArray array); Mat asMat(INDArray array, int dataType); static final String[] ALLOWED_FORMATS; }### Answer:
@Test public void testCenterCropIfNeeded() throws Exception { int w1 = 60, h1 = 110, ch1 = 1; int w2 = 120, h2 = 70, ch2 = 3; Mat img1 = makeRandomImage(h1, w1, ch1); Mat img2 = makeRandomImage(h2, w2, ch2); NativeImageLoader loader = new NativeImageLoader(h1, w1, ch1, true); Mat cropped1 = loader.centerCropIfNeeded(img1); assertEquals(85, cropped1.rows()); assertEquals(60, cropped1.cols()); assertEquals(img1.channels(), cropped1.channels()); assertNotEquals(0.0, sumElems(cropped1).get(), 0.0); Mat cropped2 = loader.centerCropIfNeeded(img2); assertEquals(70, cropped2.rows()); assertEquals(95, cropped2.cols()); assertEquals(img2.channels(), cropped2.channels()); assertNotEquals(0.0, sumElems(cropped2).get(), 0.0); }