xxxxxxxxxx
52
let noiseScale = 0.2;
const imagePath = "./images/frog.jpg";
function pixelSortColumn(img) {
let sortedImg = img.get()
console.log('asasdas')
console.log(sortedImg)
return sortedImg
for (let x = 0; x < img.width; x++) {
let columnPixels = [];
for (let y = 0; y < img.height; y++) {
let index = (x + y * img.width) * 4;
let r = img.pixels[index];
let g = img.pixels[index + 1];
let b = img.pixels[index + 2];
columnPixels.push({ y: y, rgb: r + g + b });
}
columnPixels.sort((a, b) => a.rgb - b.rgb);
for (let i = 0; i < columnPixels.length; i++) {
let y = columnPixels[i].y;
let index = (x + y * img.width) * 4;
sortedImg.pixels[index] = img.pixels[index];
sortedImg.pixels[index + 1] = img.pixels[index + 1];
sortedImg.pixels[index + 2] = img.pixels[index + 2];
sortedImg.pixels[index + 3] = img.pixels[index + 3];
}
}
sortedImg.updatePixels();
return sortedImg;
}
// Example usage:
let img;
function preload() {
img = loadImage(imagePath);
}
function setup() {
img.resize(200,0)
createCanvas(img.width, img.height);
let sorted = pixelSortColumn(img);
image(sorted, 0, 0);
}