Skip to content

Commit

Permalink
Merge pull request #45 from jiayuasu/master
Browse files Browse the repository at this point in the history
Push Babylon initial code
  • Loading branch information
jiayuasu authored Jan 19, 2017
2 parents 7ca462e + dd5f865 commit 2adce0c
Show file tree
Hide file tree
Showing 99 changed files with 17,573 additions and 5,159 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/dependency-reduced-pom.xml
/bin/
/doc/
/conf/
/log/
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.datasyslab</groupId>
<artifactId>geospark</artifactId>
<version>0.4.0</version>
<version>0.5.0</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Geospatial extension for Apache Spark</description>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.0.1</version>
<version>2.1.0</version>
<scope>provided</scope>
</dependency>

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/datasyslab/babylon/core/ImageGenerator.java
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;
}
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 src/main/java/org/datasyslab/babylon/core/OverlayOperator.java
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 src/main/java/org/datasyslab/babylon/core/PhotoFilter.java
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;
}
}
Loading

0 comments on commit 2adce0c

Please sign in to comment.