Zadania:
- Model kolorów RGB
- Model kolorów HSV
- Value/Brightness/Lightness
- Hue
- Histogram
function preload() {
img = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
img_r = createImage(256,256);
img_b = createImage(256,256);
img_g = createImage(256,256);
img_sum =createImage(256,256);
}
function setup() {
createCanvas(512,512);
img.resize(256,256);
img.loadPixels();
img_g.loadPixels();
img_b.loadPixels();
img_r.loadPixels();
img_sum.loadPixels();
for(x=0;x<img.width;x++){
for(y=0;y<img.height;y++) {
pos=4*(y*img.width+x);
// img.pixels[pos] //to jest wartość dla R
// img.pixels[pos+1] //to jest wartość dla G
// img.pixels[pos+2] //to jest wartość dla B
// img.pixels[pos+3] //to jest wartość dla A
img_r.pixels[pos]=img.pixels[pos];
img_r.pixels[pos+1]=0;
img_r.pixels[pos+2]=0;
img_r.pixels[pos+3]=255;
img_g.pixels[pos]=0;
img_g.pixels[pos+1] = img.pixels[pos+1];
img_g.pixels[pos+2]=0;
img_g.pixels[pos+3]=255;
img_b.pixels[pos]=0;
img_b.pixels[pos+1]=0;
img_b.pixels[pos+2]=img.pixels[pos+2];
img_b.pixels[pos+3]=255;
// img_sum.pixels[pos]=0;
// img_sum.pixels[pos+1]=0;
// img_sum.pixels[pos+2]=0;
// img_sum.pixels[pos+3]=255;
}
}
img_r.updatePixels();
img_g.updatePixels();
img_b.updatePixels();
img_sum.updatePixels();
img_sum.blend(img_r,0,0,256,256,0,0,256,256,ADD);
img_sum.blend(img_b,0,0,256,256,0,0,256,256,ADD);
img_sum.blend(img_g,0,0,256,256,0,0,256,256,ADD);
}
function draw() {
noLoop();
image(img_r, 0, 0);
image(img_g, 256, 0);
image(img_b, 0, 256);
image(img_sum, 256, 256);
updatePixels();
}
function preload() {
img = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
img_h = createImage(256,256);
img_s = createImage(256,256);
img_v = createImage(256,256);
}
function setup() {
createCanvas(512,512);
img.resize(256,256);
img.loadPixels();
img_h.loadPixels();
img_s.loadPixels();
img_v.loadPixels();
for(x=0;x<img.width;x++){
for(y=0;y<img.height;y++) {
pos=4*(y*img.width+x);
r=img.pixels[pos]/255;
g=img.pixels[pos+1]/255;
b=img.pixels[pos+2]/255;
cmax = Math.max(r,g,b);
cmin = Math.min(r,g,b);
v=cmax;
// x=(i/4)%256;//indeks kolumny wewnątrz wiersza --
// y=(i/4)/256;//indeks wiersza
img_v.set(x,y,255*v);
}
}
img_h.updatePixels();
img_s.updatePixels();
img_v.updatePixels();
}
function draw() {
noLoop();
image(img_h, 0, 0);
image(img_s, 256, 0);
image(img_v, 0, 256);
image(img, 256, 256);
updatePixels();
}
function preload() {
img = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
img_h = createImage(256,256);
img_s = createImage(256,256);
img_v = createImage(256,256);
}
function setup() {
createCanvas(512,512);
img.resize(256,256);
img.loadPixels();
img_h.loadPixels();
img_s.loadPixels();
img_v.loadPixels();
for(x=0;x<img.width;x++){
for(y=0;y<img.height;y++) {
pos=4*(y*img.width+x);
r=img.pixels[pos]/255;
g=img.pixels[pos+1]/255;
b=img.pixels[pos+2]/255;
cmax = Math.max(r,g,b);
cmin = Math.min(r,g,b);
v=cmax;
// x=(i/4)%256;//indeks kolumny wewnątrz wiersza --
// y=(i/4)/256;//indeks wiersza
img_v.set(x,y,255*v);
c = cmax-cmin;
if (cmax == 0){
s=0;
}
else{
s=c/cmax;
}
img_s.set(x,y,255*s);
}
}
img_h.updatePixels();
img_s.updatePixels();
img_v.updatePixels();
}
function draw() {
noLoop();
image(img_h, 0, 0);
image(img_s, 256, 0);
image(img_v, 0, 256);
image(img, 256, 256);
updatePixels();
}
function preload() {
img = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
img_h = createImage(256,256);
img_s = createImage(256,256);
img_v = createImage(256,256);
}
function setup() {
createCanvas(512,512);
img.resize(256,256);
img.loadPixels();
img_h.loadPixels();
img_s.loadPixels();
img_v.loadPixels();
for(x=0;x<img.width;x++){
for(y=0;y<img.height;y++) {
pos=4*(y*img.width+x);
r=img.pixels[pos]/255;
g=img.pixels[pos+1]/255;
b=img.pixels[pos+2]/255;
cmax = Math.max(r,g,b);
cmin = Math.min(r,g,b);
v=cmax;
// x=(i/4)%256;//indeks kolumny wewnątrz wiersza --
// y=(i/4)/256;//indeks wiersza
img_v.set(x,y,255*v);
c = cmax-cmin;
if (cmax == 0){
s=0;
}
else{
s=c/cmax;
}
img_s.set(x,y,255*s);
if(c==0){
h=0;
}
else if(v==r){
h=((g-b)/c)%6;
}
else if(v==g){
h=((b-r)/c)+2;
}
else /*v==b*/
{
h=((r-g)/c)+4;
}
h/=6;
if(h<0){
h+=1;
}
img_h.set(x,y,255*h);
}
}
img_h.updatePixels();
img_s.updatePixels();
img_v.updatePixels();
}
function draw() {
noLoop();
image(img_h, 0, 0);
image(img_s, 256, 0);
image(img_v, 0, 256);
image(img, 256, 256);
updatePixels();
}
function preload() {
img = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
//img2 = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
}
function setup() {
createCanvas(256,256);
//img.resize(256,256);
//img2.resize(256,256);
img.filter('gray');
// img2.filter('gray');
var tablica = new Array(256);
tablica.fill(0);
img.loadPixels();
for(x=0;x<img.width;x++){
for(y=0;y<img.height;y++) {
pos=4*(y*img.width+x);
t = img.pixels[pos];
tablica[t]++;
}
}
background(256);
stroke(255, 204, 0);
//line(1,256,1,150);
for(i=0;i<tablica.length;i++){
y2=256-(((tablica[i]/Math.max.apply(null, tablica))*256)*10);
x1=i+1;
x2=i+1;
y1=256;
line(x1,y1,x2,y2);
}
}
function draw() {
noLoop();
updatePixels();
}