Skip navigation

logos

Above is an image of my Exercise 3.

==============================================================

Description:

This Processing applet was made to explore how machine learning can be used to sort logos by similarity. The applet looks at a collection of logos and sorts them based on how similar they are to a user-chosen logo from the collection. The logos all begin at full brightness, and when a logo is chosen, the other logos fade to black until they are sorted with the most similar logo as the brightest and the least similar logo as the darkest.

==============================================================

Code:

import java.io.File;
import java.io.FilenameFilter;
import imagelib.*;
import similarity.*;
ArrayList histograms;
PImage[] images;
int picIndex;
float px = 0;
float py = 0;
float pz = 0;
float mx = 0;
float my = 0;
float circleX = 0;
float circleY = 0;
float circleDiameter = 0;
float colorVariable = 0;
float opacity;
float vOpacity;
float vBoxOpacity;
int colorStart;
int frame;
color c;
float boxOpacity = 17;
//float idealBoxOpacity;
void setup() {
picIndex=-1;
size(1280,720);
File datafolder = new File(sketchPath, “data”);
String[] files = datafolder.list(filter);
if (files==null|files.length<1){
println(“You must add images in jpg format to the data subdirectory of your sketch.”);
exit();
}
images = new PImage[files.length];
int num_bins = 6;
histograms = new ArrayList(files.length);
double[] histogram;
for (int i = 0; i < files.length; i++) {
println(files[i]);
images[i] = loadImage(files[i]);
histogram = ImageParsing.histHue(this, images[i],num_bins);
histograms.add(i, histogram);
}
resetImages();
fill(0,220);
rect(0,0, 1280,720);
noFill();
}
void resetImages() {
int picy = 0;
int picx = 0;
background(255);
for (int i = 0; i < images.length ;i++) {
if (picx >= width) {
picx = 0;
picy += 240;
}
image(images[i],picx,picy,320,240);
picx += 320;
}
}
void draw() {
smooth();
noStroke();
float A = 0.90;
float B = 1.0-A;
mx = A*mx + B*mouseX;
my = A*my + B*mouseY;
circleDiameter = 40;
vOpacity = -10;
opacity = vOpacity+opacity;
if(opacity<25){
opacity=25;
}
if(picIndex>-1){
markSimilars(picIndex);
}
}
void mousePressed() {
boxOpacity = 0;
opacity = 255;
c = color(random(0,255),random(150,255),random(0,255));
if (mouseButton == LEFT) {
picIndex = (mouseY / 240) * 4 + mouseX / 320;
if (picIndex < images.length) {
markSimilars(picIndex);
}
}
}
void markSimilars(int index) {
int rectx, recty;
resetImages();
int[] similars = Similarity.similarVectors(histograms, index);
PFont Serif_48;
Serif_48 = loadFont(“Serif-48.vlw”);
textFont(Serif_48, 48);
for (int i = 0; i < similars.length; i++) {
println(i);
rectx = (similars[i] % 4) * 320;
recty = (similars[i] / 4) * 240;
/*fill(255,255,0);
text(i,rectx+30,recty+90);*/
float idealBoxOpacity = (i+1)*20;
println(idealBoxOpacity);
if(boxOpacity>idealBoxOpacity){
vBoxOpacity = -2;
boxOpacity = vBoxOpacity+boxOpacity;
}
else if(boxOpacity<idealBoxOpacity){
vBoxOpacity = 2;
boxOpacity = vBoxOpacity+boxOpacity;
}
else{
boxOpacity=idealBoxOpacity;
}
fill(0,boxOpacity);
noStroke();
rect(rectx,recty,320,240);
}
}
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.toLowerCase().endsWith(“.jpg”)) return true;
return false;
}
};

import java.io.File;

import java.io.FilenameFilter;

import imagelib.*;

import similarity.*;

ArrayList histograms;

PImage[] images;

int picIndex;

float px = 0;

float py = 0;

float pz = 0;

float mx = 0;

float my = 0;

float circleX = 0;

float circleY = 0;

float circleDiameter = 0;

float colorVariable = 0;

float opacity;

float vOpacity;

float vBoxOpacity;

int colorStart;

int frame;

color c;

float boxOpacity = 17;

//float idealBoxOpacity;

void setup() {

picIndex=-1;

size(1280,720);

File datafolder = new File(sketchPath, “data”);

String[] files = datafolder.list(filter);

if (files==null|files.length<1){

println(“You must add images in jpg format to the data subdirectory of your sketch.”);

exit();

}

images = new PImage[files.length];

int num_bins = 6;

histograms = new ArrayList(files.length);

double[] histogram;

for (int i = 0; i < files.length; i++) {

println(files[i]);

images[i] = loadImage(files[i]);

histogram = ImageParsing.histHue(this, images[i],num_bins);

histograms.add(i, histogram);

}

resetImages();

fill(0,220);

rect(0,0, 1280,720);

noFill();

}

void resetImages() {

int picy = 0;

int picx = 0;

background(255);

for (int i = 0; i < images.length ;i++) {

if (picx >= width) {

picx = 0;

picy += 240;

}

image(images[i],picx,picy,320,240);

picx += 320;

}

}

void draw() {

smooth();

noStroke();

float A = 0.90;

float B = 1.0-A;

mx = A*mx + B*mouseX;

my = A*my + B*mouseY;

circleDiameter = 40;

vOpacity = -10;

opacity = vOpacity+opacity;

if(opacity<25){

opacity=25;

}

if(picIndex>-1){

markSimilars(picIndex);

}

}

void mousePressed() {

boxOpacity = 0;

opacity = 255;

c = color(random(0,255),random(150,255),random(0,255));

if (mouseButton == LEFT) {

picIndex = (mouseY / 240) * 4 + mouseX / 320;

if (picIndex < images.length) {

markSimilars(picIndex);

}

}

}

void markSimilars(int index) {

int rectx, recty;

resetImages();

int[] similars = Similarity.similarVectors(histograms, index);

PFont Serif_48;

Serif_48 = loadFont(“Serif-48.vlw”);

textFont(Serif_48, 48);

for (int i = 0; i < similars.length; i++) {

println(i);

rectx = (similars[i] % 4) * 320;

recty = (similars[i] / 4) * 240;

/*fill(255,255,0);

text(i,rectx+30,recty+90);*/

float idealBoxOpacity = (i+1)*20;

println(idealBoxOpacity);

if(boxOpacity>idealBoxOpacity){

vBoxOpacity = -2;

boxOpacity = vBoxOpacity+boxOpacity;

}

else if(boxOpacity<idealBoxOpacity){

vBoxOpacity = 2;

boxOpacity = vBoxOpacity+boxOpacity;

}

else{

boxOpacity=idealBoxOpacity;

}

fill(0,boxOpacity);

noStroke();

rect(rectx,recty,320,240);

}

}

FilenameFilter filter = new FilenameFilter() {

public boolean accept(File dir, String name) {

if (name.toLowerCase().endsWith(“.jpg”)) return true;

return false;

}

};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: