org.datavec.image.transform.ColorConversionTransform Java Examples
The following examples show how to use
org.datavec.image.transform.ColorConversionTransform.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YOLOModel.java From java-ml-projects with Apache License 2.0 | 6 votes |
public void init() { try { if (Objects.isNull(modelPath)) { yoloModel = (ComputationGraph) YOLO2.builder().build().initPretrained(); setModelClasses(COCO_CLASSES); } else { yoloModel = ModelSerializer.restoreComputationGraph(modelPath); if (!(yoloModel.getOutputLayer(0) instanceof Yolo2OutputLayer)) { throw new Error("The model is not an YOLO model (output layer is not Yolo2OutputLayer)"); } setModelClasses(classes.split("\\,")); } imageLoader = new NativeImageLoader(getInputWidth(), getInputHeight(), getInputChannels(), new ColorConversionTransform(COLOR_BGR2RGB)); loadInputParameters(); } catch (IOException e) { throw new Error("Not able to init the model", e); } }
Example #2
Source File: CifarLoader.java From DataVec with Apache License 2.0 | 6 votes |
/** * Preprocess and store cifar based on successful Torch approach by Sergey Zagoruyko * Reference: https://github.com/szagoruyko/cifar.torch */ public opencv_core.Mat convertCifar(Mat orgImage) { numExamples++; Mat resImage = new Mat(); OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); // ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2Luv); // ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2Luv); ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2YCrCb); ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2YCrCb); if (converter != null) { ImageWritable writable = new ImageWritable(converter.convert(orgImage)); // TODO determine if need to normalize y before transform - opencv docs rec but currently doing after writable = yuvTransform.transform(writable); // Converts to chrome color to help emphasize image objects writable = histEqualization.transform(writable); // Normalizes values to further clarify object of interest resImage = converter.convert(writable.getFrame()); } return resImage; }
Example #3
Source File: CifarLoader.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * Preprocess and store cifar based on successful Torch approach by Sergey Zagoruyko * Reference: <a href="https://github.com/szagoruyko/cifar.torch">https://github.com/szagoruyko/cifar.torch</a> */ public Mat convertCifar(Mat orgImage) { numExamples++; Mat resImage = new Mat(); OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); // ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2Luv); // ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2Luv); ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2YCrCb); ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2YCrCb); if (converter != null) { ImageWritable writable = new ImageWritable(converter.convert(orgImage)); // TODO determine if need to normalize y before transform - opencv docs rec but currently doing after writable = yuvTransform.transform(writable); // Converts to chrome color to help emphasize image objects writable = histEqualization.transform(writable); // Normalizes values to further clarify object of interest resImage = converter.convert(writable.getFrame()); } return resImage; }
Example #4
Source File: LegacyMDPWrapper.java From deeplearning4j with Apache License 2.0 | 5 votes |
private void createTransformProcess() { IHistoryProcessor historyProcessor = getHistoryProcessor(); if(historyProcessor != null && shape.length == 3) { int skipFrame = historyProcessor.getConf().getSkipFrame(); int frameStackLength = historyProcessor.getConf().getHistoryLength(); int height = shape[1]; int width = shape[2]; int cropBottom = height - historyProcessor.getConf().getCroppingHeight(); int cropRight = width - historyProcessor.getConf().getCroppingWidth(); transformProcess = TransformProcess.builder() .filter(new UniformSkippingFilter(skipFrame)) .transform("data", new EncodableToImageWritableTransform()) .transform("data", new MultiImageTransform( new CropImageTransform(historyProcessor.getConf().getOffsetY(), historyProcessor.getConf().getOffsetX(), cropBottom, cropRight), new ResizeImageTransform(historyProcessor.getConf().getRescaledWidth(), historyProcessor.getConf().getRescaledHeight()), new ColorConversionTransform(COLOR_BGR2GRAY) //new ShowImageTransform("crop + resize + greyscale") )) .transform("data", new ImageWritableToINDArrayTransform()) .transform("data", new SimpleNormalizationTransform(0.0, 255.0)) .transform("data", HistoryMergeTransform.builder() .isFirstDimenstionBatch(true) .build(frameStackLength)) .build("data"); } else { transformProcess = TransformProcess.builder() .transform("data", new EncodableToINDArrayTransform()) .build("data"); } }