@ -1,31 +1,37 @@
package peery ;
package peery ;
import java.io.File ;
import java.io.File ;
import java.util.HashMap ;
import peery.file.FileHandler ;
import peery.file.FileHandler ;
import peery.file.SettingsHandler ;
import peery.log.Log ;
import peery.log.Log ;
import peery.log.LogLevel ;
import peery.log.LogLevel ;
import peery.picture.ImageAnalyzer ;
import peery.picture.ImageAnalyzer ;
import peery.picture.ImageUtils ;
public class Mosaic extends Thread {
public class Mosaic extends Thread {
public static final String programmName = "Mosaic" ,
public static final String programmName = "Mosaic" ,
versionString = "Alpha-0. 33 ";
versionString = "Alpha-0. 40 ";
private static final String outputName = "Output" ;
private static String outputName = "Output" ;
private static final int gridX = 100 , gridY = 5 0, targetMulti = 2 ,
private static int gridWidth = 100 , gridHeight = 10 0, targetMulti = 2 ,
alphaThreshhold = 30 ,
alphaThreshhold = 30 ,
adaptionCount = 300 ,
adaptionCount = 300 ,
inputWorkerLimit = 10 ,
inputWorkerLimit = 10 ,
targetWorkerLimit = 4 ,
targetWorkerLimit = 8 ,
matchWorkerLimit = 10 ,
matchWorkerLimit = 10 ,
placeWorkerLimit = 2 ;
placeWorkerLimit = 2 ; //get overwritten by file settings
private static final double adaptionStep = 1.1 , gridErrorThresh = 0.15 ;
private static double adaptionStep = 1.1 , gridErrorThresh = 0.15 ;
private static boolean keepRatio = fals e;
private static boolean keepRatio = true, overlapImages = tru e;
/ *
/ *
*
*
* Performance :
* TO DO :
* Write down stats what image was used ( how often )
* Make settings save & load from a settings file
*
*
* Performance :
*
*
* FIX :
* FIX :
* rasterization doesn ' t cover everything !
* rasterization doesn ' t cover everything !
@ -36,6 +42,7 @@ public class Mosaic extends Thread{
* explore guarantee of usage of at least once , each image .
* explore guarantee of usage of at least once , each image .
* /
* /
public SettingsHandler sh ;
public FileHandler fh ;
public FileHandler fh ;
public ImageAnalyzer ia ;
public ImageAnalyzer ia ;
@ -43,17 +50,26 @@ public class Mosaic extends Thread{
fh = new FileHandler ( "resources" ) ;
fh = new FileHandler ( "resources" ) ;
Log . log ( LogLevel . Info , "Starting " + programmName + " " + versionString ) ;
Log . log ( LogLevel . Info , "Starting " + programmName + " " + versionString ) ;
ia = new ImageAnalyzer ( fh , inputWorkerLimit , targetWorkerLimit , matchWorkerLimit ,
ia = new ImageAnalyzer ( fh , inputWorkerLimit , targetWorkerLimit , matchWorkerLimit ,
placeWorkerLimit , alphaThreshhold , keepRatio );
placeWorkerLimit , alphaThreshhold , keepRatio , overlapImages );
sh = new SettingsHandler ( fh , "settings.txt" ) ;
this . start ( ) ;
this . start ( ) ;
}
}
public void run ( ) {
public void run ( ) {
Log . log . perfLog ( "Started " + programmName + " v." + versionString ) ;
Log . log . perfLog ( "Started " + programmName + " v." + versionString ) ;
Log . log ( LogLevel . Info , "Checking for settings file ..." ) ;
if ( sh . settingsFile . exists ( ) ) {
Log . log ( LogLevel . Info , "Importing settings from file ..." ) ;
importSettings ( sh . loadSettings ( ) ) ;
} else {
Log . log ( LogLevel . Info , "Couldn't find a settings file. Dumping hard-coded settings ..." ) ;
sh . saveSettings ( exportSettings ( ) ) ;
}
System . out . println ( "gridHeightxxx:" + gridHeight ) ;
Log . log . perfLog ( "Starting indexing ..." ) ;
Log . log . perfLog ( "Starting indexing ..." ) ;
prepMatching ( ) ;
prepMatching ( ) ;
//Log.log(LogLevel.Error, ia.slotClassifications.toString()+" prep:"+ia.isPrepInProgress());
//Log.log(LogLevel.Error, ia.slotClassifications.toString()+" prep:"+ia.isPrepInProgress());
while ( ia . isPrepInProgress ( ) ) {
while ( ia . isPrepInProgress ( ) ) {
try {
try {
@ -82,13 +98,14 @@ public class Mosaic extends Thread{
e . printStackTrace ( ) ;
e . printStackTrace ( ) ;
}
}
}
}
cutOutGrid( ) ;
ImageUtils. cutOutGrid( ia ) ;
Log . log . perfLog ( "Finished Placement!" ) ;
Log . log . perfLog ( "Finished Placement!" ) ;
Log . log ( LogLevel . Info , "Finished placement. Output is done ..." ) ;
Log . log ( LogLevel . Info , "Finished placement. Output is done ..." ) ;
Log . log . perfLog ( "Saving output to file ..." ) ;
Log . log . perfLog ( "Saving output to file ..." ) ;
fh . saveImage ( ia . canvas , new File ( fh . OutputFolder + fh . fs + outputName + "-" + fh . OutputFolder . listFiles ( ) . length + ".png" ) ) ;
fh . saveImage ( ia . canvas , new File ( fh . OutputFolder + fh . fs + outputName + "-" + fh . OutputFolder . listFiles ( ) . length + ".png" ) ) ;
Log . log . perfLog ( "Everything done! Exiting ..." ) ;
Log . log . perfLog ( "Everything done! Exiting ..." ) ;
Log . log . finishPerfLog ( ) ;
Log . log . finishPerfLog ( ) ;
Log . shutdownLog ( ) ;
}
}
/ * *
/ * *
@ -97,7 +114,7 @@ public class Mosaic extends Thread{
* Starts threads to index all not indexed images and rasterizes and classifies the Target .
* Starts threads to index all not indexed images and rasterizes and classifies the Target .
* /
* /
public void prepMatching ( ) {
public void prepMatching ( ) {
ia . rasterizeTarget ( grid X, gridY , targetMulti , gridErrorThresh , adaptionCount , adaptionStep ) ;
ia . rasterizeTarget ( grid Width, gridHeight , targetMulti , gridErrorThresh , adaptionCount , adaptionStep ) ;
ia . updateIndex ( ) ;
ia . updateIndex ( ) ;
ia . classifyTarget ( ) ;
ia . classifyTarget ( ) ;
}
}
@ -112,10 +129,47 @@ public class Mosaic extends Thread{
ia . placeFragments ( ) ;
ia . placeFragments ( ) ;
}
}
public void cutOutGrid ( ) {
public void importSettings ( HashMap < String , String > settings ) {
Log . log ( LogLevel . Info , "Cutting out what the grid covered!" ) ;
if ( 0 < settings . get ( "version" ) . compareTo ( versionString ) ) {
Log . log ( LogLevel . Debug , "Cutting out 0 0 " + ia . gridEnd [ 0 ] + " " + ia . gridEnd [ 1 ] ) ;
Log . log ( LogLevel . Error , "Won't import settings! Version String doesn't match!" ) ;
ia . canvas = ia . canvas . getSubimage ( 0 , 0 , ia . gridEnd [ 0 ] , ia . gridEnd [ 1 ] ) ;
Log . log ( LogLevel . Error , "Read: " + versionString + " Expected: " + settings . get ( "version" ) ) ;
return ;
}
outputName = settings . get ( "outputName" ) ;
gridWidth = Integer . parseInt ( settings . get ( "gridWidth" ) ) ;
gridHeight = Integer . parseInt ( settings . get ( "gridHeight" ) ) ;
targetMulti = Integer . parseInt ( settings . get ( "targetMultiplier" ) ) ;
alphaThreshhold = Integer . parseInt ( settings . get ( "alphaThreshhold" ) ) ;
adaptionCount = Integer . parseInt ( settings . get ( "adaptionCount" ) ) ;
inputWorkerLimit = Integer . parseInt ( settings . get ( "inputWorkerLimit" ) ) ;
targetWorkerLimit = Integer . parseInt ( settings . get ( "targetWorkerLimit" ) ) ;
matchWorkerLimit = Integer . parseInt ( settings . get ( "matchWorkerLimit" ) ) ;
placeWorkerLimit = Integer . parseInt ( settings . get ( "placeWorkerLimit" ) ) ;
adaptionStep = Double . parseDouble ( settings . get ( "adaptionStep" ) ) ;
gridErrorThresh = Double . parseDouble ( settings . get ( "gridErrorThresh" ) ) ;
keepRatio = Boolean . parseBoolean ( settings . get ( "keepRatio" ) ) ;
overlapImages = Boolean . parseBoolean ( settings . get ( "overlapImages" ) ) ;
}
public HashMap < String , String > exportSettings ( ) {
HashMap < String , String > settings = new HashMap < String , String > ( ) ;
settings . put ( "version" , versionString ) ;
settings . put ( "outputName" , outputName ) ;
settings . put ( "gridWidth" , Integer . toString ( gridWidth ) ) ;
settings . put ( "gridHeight" , Integer . toString ( gridHeight ) ) ;
settings . put ( "targetMultiplier" , Integer . toString ( targetMulti ) ) ;
settings . put ( "alphaThreshhold" , Integer . toString ( alphaThreshhold ) ) ;
settings . put ( "adaptionCount" , Integer . toString ( adaptionCount ) ) ;
settings . put ( "inputWorkerLimit" , Integer . toString ( inputWorkerLimit ) ) ;
settings . put ( "targetWorkerLimit" , Integer . toString ( targetWorkerLimit ) ) ;
settings . put ( "matchWorkerLimit" , Integer . toString ( matchWorkerLimit ) ) ;
settings . put ( "placeWorkerLimit" , Integer . toString ( placeWorkerLimit ) ) ;
settings . put ( "adaptionStep" , Double . toString ( adaptionStep ) ) ;
settings . put ( "gridErrorThresh" , Double . toString ( gridErrorThresh ) ) ;
settings . put ( "keepRatio" , Boolean . toString ( keepRatio ) ) ;
settings . put ( "overlapImages" , Boolean . toString ( overlapImages ) ) ;
return settings ;
}
}
public static void main ( String [ ] args ) {
public static void main ( String [ ] args ) {