### Question:
NativeImageLoader extends BaseImageLoader { protected Mat scalingIfNeed(Mat image) { return scalingIfNeed(image, height, width); } 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 testScalingIfNeed() throws Exception { Mat img1 = makeRandomImage(0, 0, 1); Mat img2 = makeRandomImage(0, 0, 3); int w1 = 60, h1 = 110, ch1 = 1; NativeImageLoader loader1 = new NativeImageLoader(h1, w1, ch1); Mat scaled1 = loader1.scalingIfNeed(img1); assertEquals(h1, scaled1.rows()); assertEquals(w1, scaled1.cols()); assertEquals(img1.channels(), scaled1.channels()); assertNotEquals(0.0, sumElems(scaled1).get(), 0.0); Mat scaled2 = loader1.scalingIfNeed(img2); assertEquals(h1, scaled2.rows()); assertEquals(w1, scaled2.cols()); assertEquals(img2.channels(), scaled2.channels()); assertNotEquals(0.0, sumElems(scaled2).get(), 0.0); int w2 = 70, h2 = 120, ch2 = 3; NativeImageLoader loader2 = new NativeImageLoader(h2, w2, ch2); loader2.direct = false; Mat scaled3 = loader2.scalingIfNeed(img1); assertEquals(h2, scaled3.rows()); assertEquals(w2, scaled3.cols()); assertEquals(img1.channels(), scaled3.channels()); assertNotEquals(0.0, sumElems(scaled3).get(), 0.0); Mat scaled4 = loader2.scalingIfNeed(img2); assertEquals(h2, scaled4.rows()); assertEquals(w2, scaled4.cols()); assertEquals(img2.channels(), scaled4.channels()); assertNotEquals(0.0, sumElems(scaled4).get(), 0.0); }