Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will no longer be attributed to this sketch.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
CustomPixel+AI
Levin
xxxxxxxxxx
// "Custom Picture Element", with AI augmentation.
// This project ingests 3 images: rgb, segment, depth.
// All three images are required to have the same dimensions.
// 1. rgb.png: An rgb photograph of an elephant
// From: https://www.britannica.com/animal/elephant-mammal
// 2. depth.png: a depth image, from HKU's "Depth Anything V2".
// 3. segment.png: a semantic segmentation mask image, created
// with the "Segment Anything 2 Model" (SAM) by Meta AI.
// For full details, see:
// https://github.com/golanlevin/60-212/blob/main/lectures/comfy/image_analysis/readme.md
let imgRgb, imgDepth, imgSegment;
let gridSize = 24;
// Preload the three images
function preload(){
imgRgb = loadImage("rgb.png");
imgDepth = loadImage("depth.png");
imgSegment = loadImage("segment.png");
}
function setup() {
// This is also the same as the images' sizes.
createCanvas(964, 640);
}
function draw() {
background(0,0,40);
const nRows = int(imgRgb.height / gridSize);
const nCols = int(imgRgb.width / gridSize);
for (let row=0; row<nRows; row++){
for (let col=0; col<nCols; col++){
let px = (col + 0.5) * gridSize;
let py = (row + 0.5) * gridSize;
drawCustomPictureElement (px,py);
}
}
}
// Use all 5 channels of image data: RGB + Depth + Segmentation
// to do something interesting. In the design shown here, e.g,:
// * Elements inside our segmentation mask are colored differently.
// * Elements that are 'further away' (from depth) appear smaller.
function drawCustomPictureElement (px,py){
let colorOfRgbPixel = imgRgb.get(px, py);
let colorOfDepthPixel = imgDepth.get(px, py);
let colorOfSegmentPixel = imgSegment.get(px, py);
let bIsElephant = (colorOfSegmentPixel[0] > 0);
fill (bIsElephant ? 'HotPink' : colorOfRgbPixel);
let r = red(colorOfDepthPixel); // depth is a grayscale image
let squareSize = map(r,0,255, 0.2,1.0) * gridSize;
noStroke();
rectMode(CENTER);
square(px,py, squareSize);
}
See More Shortcuts
Please verify your email to comment
Verify Email