All Downloads are FREE. Search and download functionalities are using the official Maven repository.

deepnetts.util.RandomlyTranslateImages Maven / Gradle / Ivy

/**  
 *  DeepNetts is pure Java Deep Learning Library with support for Backpropagation 
 *  based learning and image recognition.
 * 
 *  Copyright (C) 2017  Zoran Sevarac 
 *
 *  This file is part of DeepNetts.
 *
 *  DeepNetts is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see .package deepnetts.core;
 */

package deepnetts.util;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 * just move 2(x) pix to left right up down
 * 
 * @author Zoran Sevarac 
 */
public class RandomlyTranslateImages {
    
    String sourcePath = "/sourcePath/";
    String targetPath = "/sourcePath/"; 
    
    String imageIndexFileFile ="";
    String labelsFile ="";
    
    public void run() {
        try (BufferedWriter br = new BufferedWriter(new FileWriter(targetPath + "translatedImages.txt")) ){
            HashMap images = ImageUtils.loadFileImageMapFromDirectory(new File(sourcePath));
                       
            
            int i = 0;
            for(File file : images.keySet()) {
                if (!isImageFile(file)) continue;
                BufferedImage[] translatedImages = ImageUtils.randomTranslateImage(images.get(file), 2, 2);
                String fileName = file.getName();
                String name = fileName.substring(0, fileName.lastIndexOf("."));
                String imgType = fileName.substring(fileName.lastIndexOf(".")+1);
                                
                
                for(int j=0; j




© 2015 - 2025 Weber Informatics LLC | Privacy Policy