import java.awt.Color;
import java.awt.image.*;
import java.io.*;
import java.util.*;

import javax.imageio.ImageIO;

public class core {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		File dir = new File ("");

		String WorkingDirectory = null;
		
		WorkingDirectory = dir.getAbsolutePath();

		if(WorkingDirectory.contains("\\")) WorkingDirectory += "\\";
		else WorkingDirectory += '/';
		
		String pathOutput = WorkingDirectory + "recognition.out";
		String pathPicture = WorkingDirectory + "recognition.jpeg";
		File output = new File(pathOutput);
		int N = 0, M = 0;
		
		
		Scanner outputScr;
		try {
			outputScr = new Scanner(output);
			while(outputScr.hasNext())
			{
			String temp = outputScr.nextLine();
			String tempparse[] = temp.split(" ");
			M = tempparse.length;
			N++;
			}
			outputScr.close();
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		int A[][] = new int[N][M];
		try {
			outputScr = new Scanner(output);
			int i, j;

			for (i = 0; i < N; i++)
				for (j = 0; j < M; j++) {
					A[i][j] = outputScr.nextInt();
				}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		BufferedImage bimage = new BufferedImage(M, N,BufferedImage.TYPE_INT_RGB);
		
		int i, j;
		for (i = 1; i < bimage.getHeight(); i++)
			for (j = 1; j < bimage.getWidth(); j++) {
				Color clr;
				clr = new Color(A[i][j], A[i][j], A[i][j]);
				bimage.setRGB(j, i, clr.getRGB());
			}

		
	try {
			ImageIO.write(bimage, "jpeg", new File(pathPicture));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
