Created
April 16, 2025 21:59
-
-
Save ericrobskyhuntley/16557f02e0a6f58803c93d76c067c015 to your computer and use it in GitHub Desktop.
Cute Processing script that graphs image intensity (R+G+B) along horizontal axis at designated vertical intervals creating a similar effect to https://github.com/mit-spatial-action/unknown_pleasuR.
This file contains hidden or 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
String imgPath = "upthenose_color.jpg"; | |
String imgOut = appendSuffix(imgPath, "out"); | |
float imgScale = 0.5; // Scale for the image | |
int lineStep = 4; // Step for the y-axis | |
color backgroundColor = color(153, 0, 0); // Background color (R, G, B) | |
PImage img; | |
void settings() { | |
img = loadImage(imgPath); | |
img.resize(round(img.width * imgScale), round(img.height * imgScale)); | |
size(img.width, img.height); | |
} | |
void setup() { | |
background(backgroundColor); | |
noLoop(); | |
blendMode(SCREEN); | |
} | |
void draw() { | |
loadPixels(); | |
img.loadPixels(); | |
float xm1 = 0; | |
float ym1_avg = 0; | |
for (int y = 0; y < img.height; y += lineStep) { | |
for (int x = 0; x < img.width; x++) { | |
int loc = x + y * img.width; | |
// Check if loc is within bounds | |
if (loc < img.pixels.length) { | |
float r = red(img.pixels[loc]); | |
float g = green(img.pixels[loc]); | |
float b = blue(img.pixels[loc]); | |
float avg = (r + g + b) / 3; // Average should be divided by 3 | |
float scale = 1; // Ideal for graph | |
stroke(avg); | |
line(xm1, ym1_avg, x, y - (avg * scale)); | |
if (x != (width - 1)) { | |
xm1 = x; | |
ym1_avg = y - (avg * scale); | |
} else { | |
xm1 = 0; | |
} | |
} | |
} | |
} | |
save(imgOut); | |
} | |
String appendSuffix(String filepath, String suffix) { | |
int lastSlash = filepath.lastIndexOf('/'); | |
int lastDot = filepath.lastIndexOf('.'); | |
String directory = (lastSlash == -1) ? "" : filepath.substring(0, lastSlash + 1); | |
String filename = (lastDot == -1) ? filepath : filepath.substring(lastSlash + 1, lastDot); | |
String extension = (lastDot == -1) ? "" : filepath.substring(lastDot); | |
// Append the suffix to the filename | |
String newFilename = filename + "_" + suffix + extension; | |
// Join the directory and the new filename to get the new file path | |
return directory + newFilename; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment