mateooo
Junior Member
Offline
Posts: 58
converting array of colors into an image
Feb 28th , 2009, 11:38am
hello, ive made a program that analizes an imagen and separate s it into 3 new images depending on the luminosity of the pixels. i made something like this: first it iterates over all of the pixels of the image and based on the luminosity of each pixel it store the values of each pixel on 3 diferent array, so i got 3 new arrays , each one storing the color of a segment of luminosity of my image. For drawing each one of the 3 new images i need to iterate all over the array in each frame in order to draw the image , but this consumes a lot of my cpu, and its very slow if i want to make animations, so my question is : is there is a way of converting each of the arrays containin the values of each imagen into a pic? or graphic? so i do not need to iterate all over the pixels in order to draw it? any idea? here is the code: PImage img; color [] imageColors ; float [] colorRojo; float [] colorVerde; float [] colorAzul; float [] colorRojo_separadouno; float [] colorVerde_separadouno; float []colorAzul_separadouno; float []cambiauno; float cambia ; float []cambiados; float [] colorRojo_separadodos; float [] colorVerde_separadodos; float []colorAzul_separadodos; float []cambiatres; float [] colorRojo_separadotres; float [] colorVerde_separadotres; float []colorAzul_separadotres; float luminosidad_total; color luminosidad; float sube = 1; //colorMode(HSB, 255); void setup () { noStroke() ; size (400, 400) ; //colorMode(HSB, 255); img = loadImage("glitch.jpg"); colorRojo = new float[img.width * img.height]; colorVerde = new float[img.width * img.height]; colorAzul = new float[img.width * img.height]; colorRojo_separadouno = new float[img.width * img.height]; colorVerde_separadouno = new float[img.width * img.height]; colorAzul_separadouno = new float[img.width * img.height]; cambiauno = new float[img.width * img.height]; colorRojo_separadodos = new float[img.width * img.height]; colorVerde_separadodos = new float[img.width * img.height]; colorAzul_separadodos = new float[img.width * img.height]; cambiados = new float[img.width * img.height]; colorRojo_separadotres = new float[img.width * img.height]; colorVerde_separadotres = new float[img.width * img.height]; colorAzul_separadotres = new float[img.width * img.height]; cambiatres = new float[img.width * img.height]; //aca abajo genero un array con un numero de casillas igual que el numero de pixeles de mi imagen imageColors = new color[img.width * img.height]; for (int y = 0; y<img.height;y++){ for (int x = 0; x<img.width;x++) { imageColors[y*img.height + x]= img.get(x,y); colorRojo[y*img.height + x] = (imageColors[y*img.height + x]>>16)&255; colorVerde[y*img.height + x] = (imageColors[y*img.height + x]>>8)&255; colorAzul[y*img.height + x] = imageColors[y*img.height + x]&255; luminosidad = img.get(x,y); // red(luminosidad)+ green(luminosidad) + blue(luminosidad) luminosidad_total =( (red(luminosidad)) + (green(luminosidad)) + (blue(luminosidad))/3); // println( luminosidad); if(luminosidad_total>374){ cambiauno[y*img.height + x] = 250; colorRojo_separadouno[y*img.height + x] = (imageColors[y*img.height + x]>>16)&255; colorVerde_separadouno[y*img.height + x] = (imageColors[y*img.height + x]>>8)&255; colorAzul_separadouno[y*img.height + x] = imageColors[y*img.height + x]&255; } else { // cambia = 0; cambiauno[y*img.height + x] = 0; //esto de aca le pone los huecos de un color, pero como podria hacer para que sean transparaentes? colorRojo_separadouno[y*img.height + x] = 122 ; colorVerde_separadouno[y*img.height + x] = 188; colorAzul_separadouno[y*img.height + x] = 177; } if(luminosidad_total<374){ cambiados[y*img.height + x] = 250; colorRojo_separadodos[y*img.height + x] = (imageColors[y*img.height + x]>>16)&255; colorVerde_separadodos[y*img.height + x] = (imageColors[y*img.height + x]>>8)&255; colorAzul_separadodos[y*img.height + x] = imageColors[y*img.height + x]&255; } else { cambiados[y*img.height + x] = 0; } if(luminosidad_total<124){ cambiatres[y*img.height + x] = 250; colorRojo_separadotres[y*img.height + x] = (imageColors[y*img.height + x]>>16)&255; colorVerde_separadotres[y*img.height + x] = (imageColors[y*img.height + x]>>8)&255; colorAzul_separadotres[y*img.height + x] = imageColors[y*img.height + x]&255; } else { cambiatres[y*img.height + x] = 0; } } }} void draw() { background(233) ; sube = sube + 1; for (int y = 0; y<img.height;y++){ for (int x = 0; x<img.width;x++) { fill( colorRojo_separadouno[y*img.height + x], colorVerde_separadouno[y*img.height + x], colorAzul_separadouno[y*img.height + x] , cambiauno[y*img.height + x] ); ellipse(x + sube + 88, y , 7, 3); fill( colorRojo_separadodos[y*img.height + x], colorVerde_separadodos[y*img.height + x], colorAzul_separadodos[y*img.height + x],cambiados[y*img.height + x]); ellipse(x + 2+ sube + 88, y + 100,1,1); fill( colorRojo_separadotres[y*img.height + x], colorVerde_separadotres[y*img.height + x], colorAzul_separadotres[y*img.height + x],cambiatres[y*img.height + x]); ellipse(x + 2+ sube + 88, y + 200,1,1); }} }