mirror of https://github.com/Askill/mosaik.git
much faster, can still be improved a lot
This commit is contained in:
parent
08694c5662
commit
3359d772db
|
|
@ -2,12 +2,8 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="5d4ebe9a-78e7-4836-aff9-c6f6e8cd4a0d" name="Default" comment="">
|
<list default="true" id="5d4ebe9a-78e7-4836-aff9-c6f6e8cd4a0d" name="Default" comment="">
|
||||||
<change type="DELETED" beforePath="$PROJECT_DIR$/collage.jpeg" afterPath="" />
|
<change type="DELETED" beforePath="$PROJECT_DIR$/combined.png" afterPath="" />
|
||||||
<change type="DELETED" beforePath="$PROJECT_DIR$/collage.jpg" afterPath="" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/combined.png" afterPath="$PROJECT_DIR$/combined.png" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/company/Main.java" afterPath="$PROJECT_DIR$/src/com/company/Main.java" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/company/Main.java" afterPath="$PROJECT_DIR$/src/com/company/Main.java" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/company/chunk.java" afterPath="$PROJECT_DIR$/src/com/company/chunk.java" />
|
|
||||||
</list>
|
</list>
|
||||||
<ignored path="$PROJECT_DIR$/out/" />
|
<ignored path="$PROJECT_DIR$/out/" />
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
|
|
@ -19,11 +15,11 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="FileEditorManager">
|
<component name="FileEditorManager">
|
||||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
|
<leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
|
||||||
<file leaf-file-name="Main.java" pinned="false" current-in-tab="false">
|
<file leaf-file-name="Main.java" pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/src/com/company/Main.java">
|
<entry file="file://$PROJECT_DIR$/src/com/company/Main.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="1000">
|
<state relative-caret-position="380">
|
||||||
<caret line="79" column="0" lean-forward="false" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
<caret line="19" column="21" lean-forward="false" selection-start-line="19" selection-start-column="21" selection-end-line="19" selection-end-column="21" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
|
@ -31,13 +27,6 @@
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="combined.png" pinned="false" current-in-tab="true">
|
|
||||||
<entry file="file://$PROJECT_DIR$/combined.png">
|
|
||||||
<provider selected="true" editor-type-id="images">
|
|
||||||
<state />
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
</file>
|
|
||||||
<file leaf-file-name="chunk.java" pinned="false" current-in-tab="false">
|
<file leaf-file-name="chunk.java" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/src/com/company/chunk.java">
|
<entry file="file://$PROJECT_DIR$/src/com/company/chunk.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
|
@ -83,7 +72,7 @@
|
||||||
<detection-done>true</detection-done>
|
<detection-done>true</detection-done>
|
||||||
<sorting>DEFINITION_ORDER</sorting>
|
<sorting>DEFINITION_ORDER</sorting>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectFrameBounds" extendedState="6">
|
<component name="ProjectFrameBounds" extendedState="7">
|
||||||
<option name="x" value="868" />
|
<option name="x" value="868" />
|
||||||
<option name="y" value="-9" />
|
<option name="y" value="-9" />
|
||||||
<option name="width" value="1936" />
|
<option name="width" value="1936" />
|
||||||
|
|
@ -206,12 +195,12 @@
|
||||||
<workItem from="1532607142184" duration="5258000" />
|
<workItem from="1532607142184" duration="5258000" />
|
||||||
<workItem from="1532686237561" duration="4814000" />
|
<workItem from="1532686237561" duration="4814000" />
|
||||||
<workItem from="1532774518082" duration="6802000" />
|
<workItem from="1532774518082" duration="6802000" />
|
||||||
<workItem from="1532860671468" duration="4660000" />
|
<workItem from="1532860671468" duration="6952000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TimeTrackingManager">
|
<component name="TimeTrackingManager">
|
||||||
<option name="totallyTimeSpent" value="25586000" />
|
<option name="totallyTimeSpent" value="27878000" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TodoView">
|
<component name="TodoView">
|
||||||
<todo-panel id="selected-file">
|
<todo-panel id="selected-file">
|
||||||
|
|
@ -223,7 +212,7 @@
|
||||||
</todo-panel>
|
</todo-panel>
|
||||||
</component>
|
</component>
|
||||||
<component name="ToolWindowManager">
|
<component name="ToolWindowManager">
|
||||||
<frame x="-9" y="-9" width="3858" height="2140" extended-state="6" />
|
<frame x="-9" y="-9" width="3858" height="2140" extended-state="7" />
|
||||||
<editor active="true" />
|
<editor active="true" />
|
||||||
<layout>
|
<layout>
|
||||||
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||||
|
|
@ -407,20 +396,20 @@
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/combined.png">
|
||||||
|
<provider selected="true" editor-type-id="images">
|
||||||
|
<state />
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/src/com/company/Main.java">
|
<entry file="file://$PROJECT_DIR$/src/com/company/Main.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="1000">
|
<state relative-caret-position="380">
|
||||||
<caret line="79" column="0" lean-forward="false" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
<caret line="19" column="21" lean-forward="false" selection-start-line="19" selection-start-column="21" selection-end-line="19" selection-end-column="21" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/combined.png">
|
|
||||||
<provider selected="true" editor-type-id="images">
|
|
||||||
<state />
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
BIN
combined.png
BIN
combined.png
Binary file not shown.
|
Before Width: | Height: | Size: 12 MiB |
|
|
@ -10,21 +10,22 @@ public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
File file = new File("C:\\Users\\Elliot\\Desktop\\bear.jpg");
|
File file = new File("C:\\Users\\Elliot\\Desktop\\test.jpg");
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
BufferedImage image = ImageIO.read(fis); //reading the image file
|
BufferedImage image = ImageIO.read(fis); //reading the image file
|
||||||
|
|
||||||
ArrayList<String> repPaths = getAllImages(new File("C:\\Users\\Elliot\\Desktop\\test\\"));
|
ArrayList<String> repPaths = getAllImages(new File("C:\\Users\\Elliot\\Desktop\\test1\\"));
|
||||||
|
|
||||||
int rows = 50;
|
int rows = 150;
|
||||||
int cols = 50;
|
int cols = 150;
|
||||||
|
|
||||||
int chunkWidth = image.getWidth() / cols; // determines the chunk width and height
|
int chunkWidth = image.getWidth() / cols; // determines the chunk width and height
|
||||||
int chunkHeight = image.getHeight() / rows;
|
int chunkHeight = image.getHeight() / rows;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
int repCount = repPaths.size();
|
||||||
|
|
||||||
chunk[] chunks = new chunk[rows * cols];
|
chunk[] chunks = new chunk[rows * cols];
|
||||||
chunk[] replacements = new chunk[rows * cols];
|
chunk[] replacements = new chunk[repCount];
|
||||||
|
|
||||||
BufferedImage combined = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
BufferedImage combined = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics g = combined.getGraphics();
|
Graphics g = combined.getGraphics();
|
||||||
|
|
@ -46,10 +47,10 @@ public class Main {
|
||||||
}
|
}
|
||||||
System.out.println("splitting done");
|
System.out.println("splitting done");
|
||||||
//load replacement images into array
|
//load replacement images into array
|
||||||
for (int i = 0; i < cols*rows; i++) {
|
for (int i = 0; i < repCount; i++) {
|
||||||
// read file from path
|
// read file from path
|
||||||
// % repPaths.size to fill array even if not enough images in rep. folder
|
// % repPaths.size to fill array even if not enough images in rep. folder
|
||||||
File tempfile = new File(repPaths.get(i% repPaths.size()));
|
File tempfile = new File(repPaths.get(i));
|
||||||
FileInputStream tempfis = new FileInputStream(tempfile);
|
FileInputStream tempfis = new FileInputStream(tempfile);
|
||||||
|
|
||||||
// scale loaded image to fit chunk
|
// scale loaded image to fit chunk
|
||||||
|
|
@ -63,16 +64,16 @@ public class Main {
|
||||||
|
|
||||||
// fill array of chunks with read images
|
// fill array of chunks with read images
|
||||||
replacements[i] = new chunk(dimg);
|
replacements[i] = new chunk(dimg);
|
||||||
System.out.println((i*100)/(cols*rows));
|
System.out.println((i*100)/(repCount));
|
||||||
}
|
}
|
||||||
System.out.println("images loaded");
|
System.out.println("images loaded");
|
||||||
//for each chunk, calculate the euclidean distance to every possible replacement
|
//for each chunk, calculate the euclidean distance to every possible replacement
|
||||||
for (int i = 0; i < cols*rows; i++) {
|
for (int i = 0; i < cols*rows; i++) {
|
||||||
|
|
||||||
float[] distances = new float[cols*rows];
|
float[] distances = new float[repCount];
|
||||||
int minEuclid;
|
int minEuclid;
|
||||||
|
|
||||||
for (int j = 0; j < cols*rows; j++) {
|
for (int j = 0; j < repCount; j++) {
|
||||||
distances[j] = replacements[j].euclideanDistance(chunks[i].getAverage());
|
distances[j] = replacements[j].euclideanDistance(chunks[i].getAverage());
|
||||||
//int[] a = replacements[j].getAverage();
|
//int[] a = replacements[j].getAverage();
|
||||||
//int[] b = chunks[i].getAverage();
|
//int[] b = chunks[i].getAverage();
|
||||||
|
|
@ -85,7 +86,7 @@ public class Main {
|
||||||
|
|
||||||
}
|
}
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
ImageIO.write(combined, "PNG", new File("combined.png"));
|
ImageIO.write(combined, "PNG", new File("C:\\Users\\Elliot\\Desktop\\","combined.png"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue