Its been a little while since my last post, but I have been busy.
It is weird to travel through school and be tested. At every turn we feel like the work we are tasked with is
nuisance. As we continue to push to meet our deadlines and develop projects to meet the expectations we learn why we love what we do. This is why computer science is so great. Every challenge instills a love and drive for something we never thought we would enjoy. All that being said, I have been working on a project for software engineering that I never thought I would enjoy. Image analysis. It has been roughly 3 weeks or so into my project development and it is almost like an addiction. blah blah blah, right. anyway, I'm here to show what has been made so far.
I have been working with javafx, fxml, jdbc, and eclipse. This hasn't been a picnic but has yielded a pretty nice project so far. The idea of this project is to take an image, and some data from that image, and use it to compare the likeliness of that image to another. My code, and project so far, is really rough and "dirty" as they say for a quick solutions, but I'm open to suggestions and help. Here are screen-shots of what I have so far.
The code is overloaded, dirty, and probably not very efficient but this is my learning curve as of late. I don't have much time to fix much before it is due. The database adapter is still in works but all the code can be found here:
https://github.com/GettinDatFoShow/ImageAnalysis.git
For anyone who is interested in doing image comparison for their own projects.
Please don't shower me with comments of how ugly or incorrect the code is. I put it together in short time. My goal is to continue to improve it over time and to work with others who have questions about how they would like to do image comparison.
The percentages in the program have been decided in this way:
I decided to first separate the rgb vales and count up a total for each, then divide them by the total that they could be per the pixel count. ie. add up all red values then divide by 255*how many pixels there were.
for colorfulness, I defined it as: the total unique values of each three valued pixel, ie. 255-255-255 then divided the total by the amount of pixels in the image as a total prospect for different values that could occur. I realized that the colorfulness of a photo is purely defined by the person designing the program and after tough consideration, this is where I arrived. I WOULD LOVE someone else's opinion on how to present this detail. Anyway, this is here because I love to code and I love creativity. So, I would love to hear your
opinions. Thanks, and code on.
Here is the absolutely awful and badly mad image compare image class otherwise known as ICImage.java
remember, this does not include the javaFX controller, or fxml or main class which can all be found in the git hub link. enjoy. (ps, i wish i could have commented more but if you have questions, please ask.)
import java.text.DateFormat; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.Calendar; |
import java.util.Collections; |
import java.awt.Component; |
import java.awt.Container; |
import java.awt.image.BufferedImage; |
import java.io.IOException; |
import java.net.MalformedURLException; |
import javax.imageio.ImageIO; |
import javax.swing.JFrame; |
public class ICImage extends Component { |
public int[][] iColorPixelArray; |
public int[][][] iColorIntArray; |
public ArrayList<String> totalColors = new ArrayList<String>(); |
public BufferedImage image; |
public double[] percentages = new double[4]; |
public double totalColor; |
public double transparentcy; |
public double percentRed; |
public double percentGreen; |
public double percentBlue; |
public double colorFulness; |
public double totalColorPercentage; |
public ICImage(File file) |
this.image = ImageIO.read(file); |
} catch (IOException e) { |
System.out.println("ERROR: NO IMAGE!!"); |
System.out.print("FILE PATH : "); |
System.out.print(this.imageFile.getAbsolutePath()); |
this.setISource(this.imageFile.getAbsolutePath()); |
this.setINameFromFile(file); |
this.setColorArrays(image); |
this.setIcolorPercentages(); |
public ICImage(String imageSource) |
this.setISource(imageSource); // link to image |
this.createBImage(); // create buffered image |
this.setIcolorPercentages(); |
public ICImage(String imageSource, String imageName) |
this.setISource(imageSource); // link to image |
this.createBImage(); // create buffered image |
this.setIName(imageName); |
this.setIcolorPercentages(); |
// MUTATORS ====== ( SET METHODS ) ====== |
public void setIURL(File file) |
this.IURL = file.toURI().toURL().toString(); |
} catch (MalformedURLException e) { |
System.out.println("MalformedURL Exception"); |
public void setINameFromFile(File file) |
this.iName = file.getName(); |
int pos = this.iName.lastIndexOf("."); |
this.iName = this.iName.substring(0, pos); |
public void setISource(String imageSource){ // setting image source (iSrc) with string |
public void createBImage() |
{ // method creates buffered image object |
String imageSource = this.getISource(); |
this.image = ImageIO.read(this.getClass().getResource(imageSource)); // set up buffered image |
System.err.println(e.getMessage()); |
this.setColorArrays(image); |
public void createBImage(String imageLocation) |
{ // overload method creates buffered image object |
this.image = ImageIO.read(this.getClass().getResource(imageLocation)); // set up buffered image |
System.err.println(e.getMessage()); |
this.setColorArrays(image); |
public void setIHeight(BufferedImage image) |
this.iHeight = image.getHeight(); |
public void setIWidth(BufferedImage image) |
this.iWidth = image.getWidth(); |
public void setColorArrays(BufferedImage image) |
int h = this.getIHeight(); |
int w = this.getIWidth(); |
this.iColorPixelArray = new int[h][w]; |
int[] alphaArray = new int[h*w]; |
int[] redArray = new int[h*w]; |
int[] greenArray = new int[h*w]; |
int[] blueArray = new int[h*w]; |
for (int i = 0; i < h; i++) { |
for (int j = 0; j < w; j++) { |
pixel = image.getRGB(j, i); |
alphaArray[counter] = this.getAlpha(pixel); |
redArray[counter] = this.getRed(pixel); |
greenArray[counter] = this.getGreen(pixel); |
blueArray[counter] = this.getBlue(pixel); |
this.iColorPixelArray[i][j] = pixel; |
setBins(alphaArray, redArray, greenArray, blueArray); |
public void setIName(String imageName){ |
public void setIAArray(int[] alphaArray){ |
this.iAArray = alphaArray; |
public void setIBArray(int[] blueArray){ |
this.iBArray = blueArray; |
public void setIRArray(int[] redArray){ |
public void setIGArray(int[] greenArray){ |
this.iGArray = greenArray; |
public void setBins(int[] alphaArray, int[] redArray, int[] greenArray, int[] blueArray){ |
this.iAbin = new int[256]; |
this.iRbin = new int[256]; |
this.iGbin = new int[256]; |
this.iBbin = new int[256]; |
for(int i = 0; i < 256; i++){ |
int end = alphaArray.length; |
for(int i = 0; i < end ; i++){ |
this.iAbin[alphaArray[i]] += 1 ; |
this.iRbin[redArray[i]] += 1; |
this.iGbin[greenArray[i]] += 1; |
this.iBbin[blueArray[i]] += 1 ; |
public void findTotalColors(){ |
int end = this.getPixelTotal(); |
ArrayList<String> result = new ArrayList<String>(); |
for(int i = 0; i < end; i++){ |
red = Integer.toString(this.iRArray[i]); |
green = Integer.toString(this.iGArray[i]); |
blue = Integer.toString(this.iBArray[i]); |
result.add(red+green+blue); |
Collections.sort(result);; |
this.totalColors.add(result.get(0)); |
for(int i = 0; i < end; i++){ |
if(result.get(i).equals(this.totalColors.get(pointer))){ |
this.totalColors.add(result.get(i)); |
public void setIcolorPercentages(){ |
double end = this.iRArray.length; |
long total = this.iRArray.length*255; |
for(int i = 0; i < end; i++){ |
alpha += this.iAArray[i]; |
green += this.iGArray[i]; |
this.totalColor = red + blue + green; |
// System.out.println(alpha); |
// System.out.println(red); |
// System.out.println(green); |
// System.out.println(blue); |
// System.out.println(total); |
// System.out.println("**************"); |
this.transparentcy = alpha/totalColor*100; |
this.percentRed = red/totalColor*100; |
this.percentGreen = green/totalColor*100; |
this.percentBlue = blue/totalColor*100; |
System.out.println(this.getPixelTotal()); |
System.out.println(this.totalColors.size()); |
this.colorFulness = (double) this.totalColors.size() / (double) this.getPixelTotal()*100; |
System.out.println(this.transparentcy); |
System.out.println(this.percentRed); |
System.out.println(this.percentGreen); |
System.out.println(this.percentBlue); |
System.out.print("colorfulness: "); |
System.out.println(this.colorFulness); |
this.percentages[0] = this.transparentcy; |
this.percentages[1] = this.percentRed; |
this.percentages[2] = this.percentGreen; |
this.percentages[3] = this.percentBlue; |
//getting current date and time using Date class |
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); |
Date dateobj = new Date(); |
this.iDate = df.format(dateobj); |
public void setPixelTotal(int counter){ |
this.pixelTotal = counter; |
// ACCESSORS ====== ( GET METHODS ) ====== |
public String getISource(){ // getting image source (iSrc) string |
public String getIName(){ |
public BufferedImage getICImage(){ |
public int[][] getIColorPixelArray(){ |
return this.iColorPixelArray; |
public int[] getIAArray(){ |
public int[] getIBArray(){ |
public int[] getIRArray(){ |
public int[] getIGArray(){ |
public int getAlpha(int pixel){ |
return (pixel >> this.A) & 0xff; |
public int getRed(int pixel){ |
return (pixel >> this.R) & 0xff; |
public int getGreen(int pixel){ |
return (pixel >> this.G) & 0xff; |
public int getBlue(int pixel){ |
public String getIDate(){ |
public int getPixelTotal(){ |
// ===== ( OVERLOADED GET FUNCTIONS ) ====== |
public double getAlpha(int[][] colorArray, int x, int y){ |
int pixel = colorArray[y][x]; |
public double getRed(int[][] colorArray, int x, int y){ |
int pixel = colorArray[y][x]; |
public double getGreen(int[][] colorArray, int x, int y){ |
int pixel = colorArray[y][x]; |
public double getBlue(int[][] colorArray, int x, int y){ |
int pixel = colorArray[y][x]; |
public int[] getAlphaBin(){ |
public int[] getRedBin(){ |
public int[] getGreenBin(){ |
public int[] getBlueBin(){ |
// public double[] getIcolorPercentages(){ |
//// this.setIcolorPercentages(); |
// return this.IcolorPercentages; |
}
// ************************ end of ICImage Class *****************************
No comments:
Post a Comment