-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from jiayuasu/master
Push Babylon initial code
- Loading branch information
Showing
99 changed files
with
17,573 additions
and
5,159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
/dependency-reduced-pom.xml | ||
/bin/ | ||
/doc/ | ||
/conf/ | ||
/log/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/datasyslab/babylon/core/ImageGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* FILE: ImageGenerator.java | ||
* PATH: org.datasyslab.babylon.core.ImageGenerator.java | ||
* Copyright (c) 2017 Arizona State University Data Systems Lab | ||
* All rights reserved. | ||
*/ | ||
package org.datasyslab.babylon.core; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
import org.apache.spark.api.java.JavaPairRDD; | ||
|
||
import scala.Tuple2; | ||
|
||
/** | ||
* The Class ImageGenerator. | ||
*/ | ||
public abstract class ImageGenerator implements Serializable{ | ||
|
||
/** | ||
* Save as file. | ||
* | ||
* @param distributedPixelImage the distributed pixel image | ||
* @param outputPath the output path | ||
* @return true, if successful | ||
* @throws Exception the exception | ||
*/ | ||
public boolean SaveAsFile(JavaPairRDD<Integer,ImageSerializableWrapper> distributedPixelImage, String outputPath) throws Exception | ||
{ | ||
List<Tuple2<Integer,ImageSerializableWrapper>> imagePartitions = distributedPixelImage.collect(); | ||
for(Tuple2<Integer,ImageSerializableWrapper> imagePartition:imagePartitions) | ||
{ | ||
this.SaveAsFile(imagePartition._2.image, outputPath+"-"+imagePartition._1); | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Save as file. | ||
* | ||
* @param pixelImage the pixel image | ||
* @param outputPath the output path | ||
* @return true, if successful | ||
* @throws Exception the exception | ||
*/ | ||
public abstract boolean SaveAsFile(BufferedImage pixelImage, String outputPath) throws Exception; | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/datasyslab/babylon/core/ImageSerializableWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* FILE: ImageSerializableWrapper.java | ||
* PATH: org.datasyslab.babylon.core.ImageSerializableWrapper.java | ||
* Copyright (c) 2017 Arizona State University Data Systems Lab | ||
* All rights reserved. | ||
*/ | ||
package org.datasyslab.babylon.core; | ||
|
||
import java.io.*; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
import java.awt.image.*; | ||
|
||
/** | ||
* The Class ImageSerializableWrapper. | ||
*/ | ||
public class ImageSerializableWrapper implements Serializable { | ||
|
||
/** The image. */ | ||
protected transient BufferedImage image; | ||
|
||
/** | ||
* Instantiates a new image serializable wrapper. | ||
* | ||
* @param image the image | ||
*/ | ||
public ImageSerializableWrapper(BufferedImage image) { | ||
this.image = image; | ||
} | ||
|
||
/** | ||
* Write object. | ||
* | ||
* @param out the out | ||
* @throws IOException Signals that an I/O exception has occurred. | ||
*/ | ||
// Serialization method. | ||
private void writeObject(ObjectOutputStream out) throws IOException { | ||
out.defaultWriteObject(); | ||
ImageIO.write(image, "png", out); | ||
} | ||
|
||
/** | ||
* Read object. | ||
* | ||
* @param in the in | ||
* @throws IOException Signals that an I/O exception has occurred. | ||
* @throws ClassNotFoundException the class not found exception | ||
*/ | ||
// Deserialization method. | ||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { | ||
in.defaultReadObject(); | ||
image = ImageIO.read(in); | ||
if(image==null) | ||
{ | ||
System.out.println("I got nothing from the stream!"); | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/org/datasyslab/babylon/core/OverlayOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* FILE: OverlayOperator.java | ||
* PATH: org.datasyslab.babylon.core.OverlayOperator.java | ||
* Copyright (c) 2017 Arizona State University Data Systems Lab | ||
* All rights reserved. | ||
*/ | ||
package org.datasyslab.babylon.core; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.image.BufferedImage; | ||
import java.util.Iterator; | ||
|
||
import org.apache.spark.api.java.JavaPairRDD; | ||
import org.apache.spark.api.java.function.PairFunction; | ||
|
||
import scala.Tuple2; | ||
|
||
/** | ||
* The Class OverlayOperator. | ||
*/ | ||
public class OverlayOperator { | ||
|
||
/** The back image. */ | ||
public BufferedImage backImage; | ||
|
||
/** The distributed back image. */ | ||
public JavaPairRDD<Integer,BufferedImage> distributedBackImage; | ||
|
||
/** | ||
* Instantiates a new overlay operator. | ||
* | ||
* @param distributedBackImage the distributed back image | ||
*/ | ||
public OverlayOperator(JavaPairRDD<Integer,BufferedImage> distributedBackImage) | ||
{ | ||
this.distributedBackImage = distributedBackImage; | ||
} | ||
|
||
/** | ||
* Instantiates a new overlay operator. | ||
* | ||
* @param backImage the back image | ||
*/ | ||
public OverlayOperator(BufferedImage backImage) | ||
{ | ||
this.backImage = backImage; | ||
} | ||
|
||
/** | ||
* Join image. | ||
* | ||
* @param distributedFontImage the distributed font image | ||
* @return true, if successful | ||
*/ | ||
public boolean JoinImage(JavaPairRDD<Integer,BufferedImage> distributedFontImage) | ||
{ | ||
this.distributedBackImage = this.distributedBackImage.cogroup(distributedFontImage).mapToPair(new PairFunction<Tuple2<Integer,Tuple2<Iterable<BufferedImage>,Iterable<BufferedImage>>>,Integer,BufferedImage>() | ||
{ | ||
@Override | ||
public Tuple2<Integer, BufferedImage> call( | ||
Tuple2<Integer, Tuple2<Iterable<BufferedImage>, Iterable<BufferedImage>>> imagePair) | ||
throws Exception { | ||
int imagePartitionId = imagePair._1; | ||
Iterator<BufferedImage> backImageIterator = imagePair._2._1.iterator(); | ||
Iterator<BufferedImage> frontImageIterator = imagePair._2._2.iterator(); | ||
if(backImageIterator.hasNext()==false) | ||
{ | ||
throw new Exception("[OverlayOperator][JoinImage] The back image iterator didn't get any image partitions."); | ||
} | ||
if(frontImageIterator.hasNext()==false) | ||
{ | ||
throw new Exception("[OverlayOperator][JoinImage] The front image iterator didn't get any image partitions."); | ||
} | ||
BufferedImage backImage = backImageIterator.next(); | ||
BufferedImage frontImage = frontImageIterator.next(); | ||
if(backImage.getWidth()!=frontImage.getWidth()||backImage.getHeight()!=frontImage.getHeight()) | ||
{ | ||
throw new Exception("[OverlayOperator][JoinImage] The two given image don't have the same width or the same height."); | ||
} | ||
int w = Math.max(backImage.getWidth(), frontImage.getWidth()); | ||
int h = Math.max(backImage.getHeight(), frontImage.getHeight()); | ||
BufferedImage combinedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); | ||
Graphics graphics = combinedImage.getGraphics(); | ||
graphics.drawImage(backImage, 0, 0, null); | ||
graphics.drawImage(frontImage, 0, 0, null); | ||
return new Tuple2(imagePartitionId,combinedImage); | ||
} | ||
}); | ||
return true; | ||
} | ||
|
||
|
||
/** | ||
* Join image. | ||
* | ||
* @param frontImage the front image | ||
* @return true, if successful | ||
* @throws Exception the exception | ||
*/ | ||
public boolean JoinImage(BufferedImage frontImage) throws Exception | ||
{ | ||
if(backImage.getWidth()!=frontImage.getWidth()||backImage.getHeight()!=frontImage.getHeight()) | ||
{ | ||
throw new Exception("[OverlayOperator][JoinImage] The two given image don't have the same width or the same height."); | ||
} | ||
int w = Math.max(backImage.getWidth(), frontImage.getWidth()); | ||
int h = Math.max(backImage.getHeight(), frontImage.getHeight()); | ||
BufferedImage combinedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); | ||
Graphics graphics = combinedImage.getGraphics(); | ||
graphics.drawImage(backImage, 0, 0, null); | ||
graphics.drawImage(frontImage, 0, 0, null); | ||
this.backImage = combinedImage; | ||
return true; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/datasyslab/babylon/core/PhotoFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* FILE: PhotoFilter.java | ||
* PATH: org.datasyslab.babylon.core.PhotoFilter.java | ||
* Copyright (c) 2017 Arizona State University Data Systems Lab | ||
* All rights reserved. | ||
*/ | ||
package org.datasyslab.babylon.core; | ||
|
||
/** | ||
* The Class PhotoFilter. | ||
*/ | ||
public abstract class PhotoFilter { | ||
|
||
/** The filter radius. */ | ||
protected int filterRadius; | ||
|
||
/** The convolution matrix. */ | ||
protected Double[][] convolutionMatrix; | ||
|
||
/** | ||
* Instantiates a new photo filter. | ||
* | ||
* @param filterRadius the filter radius | ||
*/ | ||
public PhotoFilter(int filterRadius) | ||
{ | ||
this.filterRadius=filterRadius; | ||
this.convolutionMatrix = new Double[2*filterRadius+1][2*filterRadius+1]; | ||
} | ||
|
||
/** | ||
* Gets the filter radius. | ||
* | ||
* @return the filter radius | ||
*/ | ||
public int getFilterRadius() { | ||
return filterRadius; | ||
} | ||
|
||
/** | ||
* Gets the convolution matrix. | ||
* | ||
* @return the convolution matrix | ||
*/ | ||
public Double[][] getConvolutionMatrix() { | ||
return convolutionMatrix; | ||
} | ||
} |
Oops, something went wrong.