My concept is to load an image and scan through all its pixels. For every pixel, find another pixel in the whole image that has the biggest color difference. Once the program detects the best pair(biggest difference), it will draw a line between the two pixels’ locations.
My problem is for some reason, the lines and even the image itself won’t show up. I will appreciate if anybody can help me solve this issue. Thanks!
IMAGE:
--------------------------------------------------------------------CODE--------------------------------------------------------------
PImage flower;
color secondColor;
color firstColor;
float r1, g1, b1, r2, g2, b2;
float distanceNow = dist(r1, g1, b1, r2, g2, b2);
int bestX=0;
int bestY=0;
void setup() {
size(470, 900);
flower = loadImage(“flower.jpg”);
background(255);
}
void draw() {
image(flower, 0, 0);
flower.loadPixels()
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
int loc0 = x+y*width;
firstColor = flower.pixels[loc0];
r1 = red(firstColor);
g1 = green(firstColor);
b1 = blue(firstColor);
distanceNow = dist(r1, g1, b1, r2, g2, b2);
for (int a=width-1; a>=0; a--) {
for (int b=height-1; b>=0; b--) {
int loc1 = a+b*width;
secondColor = flower.pixels[loc1];
r2 = red(secondColor);
g2 = green(secondColor);
b2 = blue(secondColor);
float distanceNew = dist(r1, g1, b1, r2, g2, b2);
if (loc0!=loc1) {
if (distanceNew > distanceNow) {
distanceNow = distanceNew;
bestX = a;
bestY = b;
}
}
}
}
updatePixels();
strokeWeight(1);
stroke(0);
line(x, y, bestX, bestY);
}
}
}
--------------------------------------------------------------------CODE--------------------------------------------------------------