<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #rgb - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23rgb</link>
      <pubDate>Sun, 08 Aug 2021 20:26:30 +0000</pubDate>
         <description>Tagged with #rgb - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23rgb/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>get color average from picture parts and save values in an array to send via serial</title>
      <link>https://forum.processing.org/two/discussion/25302/get-color-average-from-picture-parts-and-save-values-in-an-array-to-send-via-serial</link>
      <pubDate>Thu, 30 Nov 2017 13:54:10 +0000</pubDate>
      <dc:creator>waldooo</dc:creator>
      <guid isPermaLink="false">25302@/two/discussions</guid>
      <description><![CDATA[<p>Hi!
I am using part of a code I've found here in the forum ( <a rel="nofollow" href="https://forum.processing.org/two/discussion/15573/get-the-average-rgb-from-pixels">Get the average RGB from pixels</a> from <a rel="nofollow" href="https://forum.processing.org/two/profile/287/bourdonprince">bourdonprince</a> and <a rel="nofollow" href="https://forum.processing.org/two/profile/56/GoToLoop">GoToLoop</a>) that gets the color average values and display squares like big pixels on screen.</p>

<p><strong>Now I want to use this values to set the pixels colors of a RGB LED strip.</strong></p>

<p>The problem is that when I separate and read (at the processing console) de values of the color for each pixel, <strong>I get almost all my pixels with 0 for red...</strong> But the squares drawn in the screen seems OK, only the values I try to save to the matrix for latter use that seems odd.</p>

<p>Below is my code ( <em>with thanks to bourdonprince and GoToLoop</em>):</p>

<pre lang="java">
import processing.video.*;
Capture webcam;

import processing.serial.*;
Serial myPort;

float[][] rx;
float[][] gx;
float[][] bx;

void setup() {
  size(440, 320);

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  rx = new float[16][15];
  gx = new float[16][15];
  bx = new float[16][15];

  webcam = new Capture(this, 320, 240);  
  //String[] devices = Capture.list();
  //println(devices);
  webcam.start();
}

void draw() {

  if (webcam.available() == true) {
    webcam.read();
    image(webcam, 0, 0, width, height);
    saveFrame("/data/image.jpg");
  }

  delay(100);

  PImage img = loadImage("image.jpg");
  int detail = 30; // tamanho do quadrado

  int count_i = 0;
  int count_j = 0;


  for (int j=0; j&lt; height; j+=detail) {
    
    count_i = 0;

    for (int i=0; i &lt; width; i+=detail) {
      PImage newImg = img.get(i, j, detail, detail);
      noStroke();
      color cor = extractColorFromImage(newImg);
      fill(cor);
      rx[count_i][count_i]= red(cor);
      gx[count_i][count_j]= green(cor);
      bx[count_i][count_j]= blue(cor);

      count_i++;
    }
    count_j++;
  }


  for (int i=0; i&lt;15; i++)
  {
    for (int j=0; j&lt;11; j++)
    {
      println((i) + "," + (j) + "," + int( rx[i][j] )+ "," + int (gx[i][j]) + "," + int (bx[i][j]));
      //delay(100);
      myPort.write((i) + "," + (j) + "," + int( rx[i][j] )+ "," + int (gx[i][j]) + "," + int (bx[i][j])  + "\n");
      delay(50);
    }
  }

  delay(2000);
}



//função para extrair a cor média em um recorte
color extractColorFromImage(PImage img) {
  img.loadPixels();
  color r = 0, g = 0, b = 0;

  for (final color c : img.pixels) {
    r += c &gt;&gt; 020 &amp; 0xFF;
    g += c &gt;&gt; 010 &amp; 0xFF;
    b += c        &amp; 0xFF;
  }

  r /= img.pixels.length;
  g /= img.pixels.length;
  b /= img.pixels.length;

  return color(r, g, b);
}
</pre>
]]></description>
   </item>
   <item>
      <title>Multidimensional arrays and java?</title>
      <link>https://forum.processing.org/two/discussion/24613/multidimensional-arrays-and-java</link>
      <pubDate>Wed, 18 Oct 2017 00:27:03 +0000</pubDate>
      <dc:creator>shawnlau</dc:creator>
      <guid isPermaLink="false">24613@/two/discussions</guid>
      <description><![CDATA[<p>I'm working on a paint program that will be able to handle larger images ( 4800 x 6000) pixels.  In order to mix pixels properly, I've found I need to either use a floating point array or an array with the integer r,g,b, values of the pixels shifted 16. Using just integers, there is a little clipping each time that is lost and they start adding up into weird hue shifts.  Though tests, I've found no difference in performance between using the floating point array and the integer shifted array-at least on the java machine. So I use the float because its clearer.</p>

<p>But I have found a major difference in performance between using a multidimensional array and 3 one dimension arrays.</p>

<p>I had been allocating the array as such:</p>

<p><code>float floatArray = new float[4800 * 6000][3];</code></p>

<p>That little line of code took about 5-10 seconds to allocate on my Windows 7, i7 processor with 16gb ram.</p>

<p>But writing it as this takes only milliseconds to allocate:</p>

<pre><code>float floatArrayR = new float[4800 * 6000];
float floatArrayG = new float[4800 * 6000];
float floatArrayB = new float[4800 * 6000];
</code></pre>

<p>I remember reading many years ago that different os's handle multidimensional arrays differently and one should not assume how the members are ordered. I can't imagine how the java virtual machine handles multidimensional arrays to make them so much slower than one dimension arrays. Allocation time from 5-10 seconds to milliseconds? Whats going on there? The multidimensional array also slowed garbage collection so much it was performance issue. Not so with the one dimension array.</p>
]]></description>
   </item>
   <item>
      <title>Averaging a few seconds of a video feed pixel</title>
      <link>https://forum.processing.org/two/discussion/18894/averaging-a-few-seconds-of-a-video-feed-pixel</link>
      <pubDate>Sat, 05 Nov 2016 12:34:37 +0000</pubDate>
      <dc:creator>scottreinhard</dc:creator>
      <guid isPermaLink="false">18894@/two/discussions</guid>
      <description><![CDATA[<p>I would like to display a video pixel's average over a couple of seconds. What would be the best method to.</p>

<p>To make the question simple, let's say I want to get the color of the center pixel of a video feed and fill a rectangle the size of the window to this particular color. To mitigate the flickering of this colored rectangle which will naturally occur from the video, I would like to average, say, the color of the last 60 frames of the video and always have the rectangle displaying that averaged color.</p>

<p>What would be an approach to making this happen?</p>
]]></description>
   </item>
   <item>
      <title>BackgroundRemove + Blobdetection (or a similiar solution?)</title>
      <link>https://forum.processing.org/two/discussion/18983/backgroundremove-blobdetection-or-a-similiar-solution</link>
      <pubDate>Fri, 11 Nov 2016 11:58:07 +0000</pubDate>
      <dc:creator>Aldun</dc:creator>
      <guid isPermaLink="false">18983@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm currently trying to combine two processing sketches (BackgroundRemove and Blobdetection) to do the following with a webcam aimed at a street:</p>

<ol>
<li>Get videocapture and turn the original image fully green</li>
<li>Compare every new frame with the original background image</li>
<li><p>Only show the changed pixels (as a result the canvas is fully green but only moving objects are shown).</p></li>
<li><p>Use blobdetection to draw rectangles around each moving object.</p></li>
</ol>

<p>For this I'm trying to combine the two scripts listed at the end of this post.
The BackgroundRemove comes from <a href="http://learningprocessing.com/examples/chp16/example-16-12-BackgroundRemove" target="_blank" rel="nofollow">http://learningprocessing.com/examples/chp16/example-16-12-BackgroundRemove</a>
The Blobdetection comes from <a href="http://www.v3ga.net/processing/BlobDetection/index-page-home.html" target="_blank" rel="nofollow">http://www.v3ga.net/processing/BlobDetection/index-page-home.html</a></p>

<p>Both scripts seperately work fine, but I've been working for days to combine them and I can't seem to get it working. I think the solution would be to replace the video input in the Blob detection with the canvas input, but I can't figure out how to do that (or how to fix this otherwise).</p>

<p>Would anyone be able to help me here? Thanks!</p>

<blockquote class="Quote">
  <p>sorry, the Code tags don't seem to work correctly.
  For a better view, here are the code Gists: 
  <a href="https://gist.github.com/Thomvdm/fd4c412b6bb66a264728b1816c9b5a10" target="_blank" rel="nofollow">https://gist.github.com/Thomvdm/fd4c412b6bb66a264728b1816c9b5a10</a>
  <a href="https://gist.github.com/Thomvdm/21d6e9d3df86e288cb8e36fd41bcaf29" target="_blank" rel="nofollow">https://gist.github.com/Thomvdm/21d6e9d3df86e288cb8e36fd41bcaf29</a></p>
</blockquote>

<p>|
|
|
|
|
|
|</p>

<pre><code>// Example 16-12: Simple background removal

// Click the mouse to memorize a current background image
import processing.video.*;

// Variable for capture device
Capture video;

// Saved background
PImage backgroundImage;

// How different must a pixel be to be a foreground pixel
float threshold = 30;

void setup() {
  size(640, 480);

  video = new Capture(this, width, height);


  video.start();
  // Create an empty image the same size as the video
  backgroundImage = createImage(video.width, video.height, RGB);
}

void captureEvent(Capture video) {
  // Read image from the camera
  video.read();
}

void draw() {
  // We are looking at the video's pixels, the memorized backgroundImage's pixels, as well as accessing the display pixels. 
  // So we must loadPixels() for all!
  loadPixels();
  video.loadPixels(); 
  backgroundImage.loadPixels();

  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x ++ ) {
    for (int y = 0; y &lt; video.height; y ++ ) {
      int loc = x + y*video.width; // Step 1, what is the 1D pixel location
      color fgColor = video.pixels[loc]; // Step 2, what is the foreground color

      // Step 3, what is the background color
      color bgColor = backgroundImage.pixels[loc];

      // Step 4, compare the foreground and background color
      float r1 = red(fgColor);
      float g1 = green(fgColor);
      float b1 = blue(fgColor);
      float r2 = red(bgColor);
      float g2 = green(bgColor);
      float b2 = blue(bgColor);
      float diff = dist(r1, g1, b1, r2, g2, b2);

      // Step 5, Is the foreground color different from the background color
      if (diff &gt; threshold) {
        // If so, display the foreground color
        pixels[loc] = fgColor;
      } else {
        // If not, display green
        pixels[loc] = color(0, 255, 0); // We could choose to replace the background pixels with something other than the color green!
      }
    }
  }
  updatePixels();
}

void mousePressed() {
  // Copying the current frame of video into the backgroundImage object
  // Note copy takes 5 arguments:
  // The source image
  // x, y, width, and height of region to be copied from the source
  // x, y, width, and height of copy destination
  backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
  backgroundImage.updatePixels();
}














// - Super Fast Blur v1.1 by Mario Klingemann &lt;<a href="http://incubator.quasimondo.com&gt" target="_blank" rel="nofollow">http://incubator.quasimondo.com&gt</a>;
// - BlobDetection library

import processing.video.*;
import blobDetection.*;

Capture cam;
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;

// ==================================================
// setup()
// ==================================================
void setup()
{
    // Size of applet
    size(640, 480);
    // Capture
    cam = new Capture(this, 640, 480, 30);
        // Comment the following line if you use Processing 1.5
        cam.start();

    // BlobDetection
    // img which will be sent to detection (a smaller copy of the cam frame);
    img = new PImage(80,60); 
    theBlobDetection = new BlobDetection(img.width, img.height);
    theBlobDetection.setPosDiscrimination(true);
    theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity &gt; 0.2f;
}

// ==================================================
// captureEvent()
// ==================================================
void captureEvent(Capture cam)
{
    cam.read();
    newFrame = true;
}

// ==================================================
// draw()
// ==================================================
void draw()
{
    if (newFrame)
    {
        newFrame=false;
        image(cam,0,0,width,height);
        img.copy(cam, 0, 0, cam.width, cam.height, 
                0, 0, img.width, img.height);
        fastblur(img, 2);
        theBlobDetection.computeBlobs(img.pixels);
        drawBlobsAndEdges(true,true);
    }
}

// ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{
    noFill();
    Blob b;
    EdgeVertex eA,eB;
    for (int n=0 ; n&lt;theBlobDetection.getBlobNb() ; n++)
    {
        b=theBlobDetection.getBlob(n);
        if (b!=null)
        {
    print("Blob #: ");
    println(n);
    print("X Coord of center: ");
    println(b.x);
print("Y Coord of center: ");
println(b.y);
            // Edges
            if (drawEdges)
            {
                strokeWeight(3);
                stroke(0,255,0);
                for (int m=0;m&lt;b.getEdgeNb();m++)
                {
                    eA = b.getEdgeVertexA(m);
                    eB = b.getEdgeVertexB(m);
                    if (eA !=null &amp;&amp; eB !=null)
                        line(
                            eA.x*width, eA.y*height, 
                            eB.x*width, eB.y*height
                            );
                }
            }

            // Blobs
            if (drawBlobs)
            {
                strokeWeight(1);
                stroke(255,0,0);
                rect(
                    b.xMin*width,b.yMin*height,
                    b.w*width,b.h*height
                    );

            }

        }

      }
}

// ==================================================
// Super Fast Blur v1.1
// by Mario Klingemann 
// &lt;<a href="http://incubator.quasimondo.com&gt" target="_blank" rel="nofollow">http://incubator.quasimondo.com&gt</a>;
// ==================================================
void fastblur(PImage img,int radius)
{
 if (radius&lt;1){
    return;
  }
  int w=img.width;
  int h=img.height;
  int wm=w-1;
  int hm=h-1;
  int wh=w*h;
  int div=radius+radius+1;
  int r[]=new int[wh];
  int g[]=new int[wh];
  int b[]=new int[wh];
  int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw;
  int vmin[] = new int[max(w,h)];
  int vmax[] = new int[max(w,h)];
  int[] pix=img.pixels;
  int dv[]=new int[256*div];
  for (i=0;i&lt;256*div;i++){
    dv[i]=(i/div);
  }

  yw=yi=0;

  for (y=0;y&lt;h;y++){
    rsum=gsum=bsum=0;
    for(i=-radius;i&lt;=radius;i++){
      p=pix[yi+min(wm,max(i,0))];
      rsum+=(p &amp; 0xff0000)&gt;&gt;16;
      gsum+=(p &amp; 0x00ff00)&gt;&gt;8;
      bsum+= p &amp; 0x0000ff;
    }
    for (x=0;x&lt;w;x++){

      r[yi]=dv[rsum];
      g[yi]=dv[gsum];
      b[yi]=dv[bsum];

      if(y==0){
        vmin[x]=min(x+radius+1,wm);
        vmax[x]=max(x-radius,0);
      }
      p1=pix[yw+vmin[x]];
      p2=pix[yw+vmax[x]];

      rsum+=((p1 &amp; 0xff0000)-(p2 &amp; 0xff0000))&gt;&gt;16;
      gsum+=((p1 &amp; 0x00ff00)-(p2 &amp; 0x00ff00))&gt;&gt;8;
      bsum+= (p1 &amp; 0x0000ff)-(p2 &amp; 0x0000ff);
      yi++;
    }
    yw+=w;
  }

  for (x=0;x&lt;w;x++){
    rsum=gsum=bsum=0;
    yp=-radius*w;
    for(i=-radius;i&lt;=radius;i++){
      yi=max(0,yp)+x;
      rsum+=r[yi];
      gsum+=g[yi];
      bsum+=b[yi];
      yp+=w;
    }
    yi=x;
    for (y=0;y&lt;h;y++){
      pix[yi]=0xff000000 | (dv[rsum]&lt;&lt;16) | (dv[gsum]&lt;&lt;8) | dv[bsum];
      if(x==0){
        vmin[y]=min(y+radius+1,hm)*w;
        vmax[y]=max(y-radius,0)*w;
      }
      p1=x+vmin[y];
      p2=x+vmax[y];

      rsum+=r[p1]-r[p2];
      gsum+=g[p1]-g[p2];
      bsum+=b[p1]-b[p2];

      yi+=w;
    }
  }

}`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Mirroring Capture help</title>
      <link>https://forum.processing.org/two/discussion/18525/mirroring-capture-help</link>
      <pubDate>Thu, 13 Oct 2016 04:52:59 +0000</pubDate>
      <dc:creator>kksd</dc:creator>
      <guid isPermaLink="false">18525@/two/discussions</guid>
      <description><![CDATA[<p>How do you flip/mirror a video?
Below is my code, where I am trying to get the video to play a mirrored image on processing using
"int loc = (cam.width - i - 1) + j*cam.width;"
Where I translate the x-axis to flip, subtracting the x-location of the particular pixel (where brightness is above 253) from the width of the screen, but somehow it is not working.
What is the issue here?</p>

<p>import processing.video.*;
int cols, rows;
Capture cam;</p>

<p>void setup() {</p>

<p>//displays it full screen
  size (displayWidth, displayHeight);</p>

<p>cols = width;<br />
  rows = height;
  //30 fps is default so bellow won't change anything
  cam = new Capture(this, width, height, 30);</p>

<p>// Start capturing the images from the camera
  cam.start();</p>

<p>frameRate(30);
  background(0);
}</p>

<p>void draw() { 
  if(cam.available()) {
    //reads fresh-est  pixels from camera
    cam.read();
    cam.loadPixels();
    loadPixels();
    // Loop through every pixel. ++i is equivalent to i = i + 1.
    //for (int i=0; i&lt;cam.pixels.length; i++) {</p>

<pre><code>// Begin loop for columns(using width)
for (int i = 0; i &lt; cols;i++) {
  // Begin loop for rows(using length)
  for (int j = 0; j &lt; rows;j++) {

    // Where are we, pixel-wise? (cam.width - i - 1) means x-coordinate of the pixel mirrored
    int loc = (cam.width - i - 1) + j*cam.width;  // Reversing x to mirror the image

    if (brightness(cam.pixels[loc]) &gt; 253) {
      pixels[loc] = color(255);       
    }

 float red = red(pixels[loc]);
 float green = green(pixels[loc]);
 float blue = blue(pixels[loc]);

 blue = blue - 5;
 if(blue &lt; 0) blue = 0;

 red = red - 5;
 if(red &lt; 0) red = 0;

 green = green - 5;
 if(green &lt; 0) green = 0;

 pixels[loc] = color(red, green, blue);

} 
</code></pre>

<p>}</p>

<p>updatePixels();</p>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>Problem with Retrieving red(), green(), or blue() on an Array of PImages</title>
      <link>https://forum.processing.org/two/discussion/17894/problem-with-retrieving-red-green-or-blue-on-an-array-of-pimages</link>
      <pubDate>Thu, 18 Aug 2016 17:37:35 +0000</pubDate>
      <dc:creator>stevev4915</dc:creator>
      <guid isPermaLink="false">17894@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to create an image texture analyzer by progressively blurring an image and finding the difference between the  pixels at different stages of blurring. I had this working when I was using individual PImages but when I tried using an array of PImages, my code broke. The error I am receiving is, "the function "red()" expects parameters like: red(int)". Here is my code.</p>

<pre><code>PImage[] pic, difference;
int levels = 3;

void setup(){

  size(displayWidth, displayHeight);
  background(0);

  //setup image arrays

  pic = new PImage[levels + 1];
  difference = new PImage[levels];

  //load image to be analyzed
  pic[0] = loadImage("swamptrees.jpg");
  pic[0].loadPixels();

  //setup individual color variables
  float r, g, b;

  //blur each image and find the diffence from previous level of blur
  for (int i = 0 ; i &lt; levels ; i ++){

    //create and blur this level
    pic[i + 1] = createImage(pic[0].width, pic[0].height, RGB);
    pic[i + 1] = pic[0].get();
    pic[i + 1].filter(BLUR, pow(2, i));
    pic[i + 1].loadPixels();

    //create and calculate the difference
    difference[i] = createImage(pic[0].width, pic[0].height, RGB);
    difference[i].loadPixels();

    for (int j = 0 ; j &lt; pic[0].pixels.length ; j++){

      r = abs(red(pic[i].pixels[j] - red(pic[i + 1].pixels[j])));
      g = abs(green(pic[i].pixels[j] - green(pic[i + 1].pixels[j])));
      b = abs(blue(pic[i].pixels[j] - blue(pic[i + 1].pixels[j])));

      difference[i].pixels[j] = color(r, g, b);

    }

  }

  pic[0].updatePixels();

  for (int i = 0 ; i &lt; levels ; i++){

    pic[i + 1].updatePixels();
    difference[i].updatePixels();

  }

}

void draw(){

  image(pic[0], 0, 0, width/4, height/4);

  for (int i = 0 ; i &lt; levels ; i ++){

    image(pic[i + 1], 0, (height / 4) * (i + 1), width / 4, (height / 4) * (i + 2));
    image(difference[i + 1], width / 4, (height / 4) * (i + 1), width / 2, (height / 4) * (i + 2));

  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Pixels change colors by the mouse pointer moves over</title>
      <link>https://forum.processing.org/two/discussion/16466/pixels-change-colors-by-the-mouse-pointer-moves-over</link>
      <pubDate>Fri, 06 May 2016 16:59:00 +0000</pubDate>
      <dc:creator>Sara99</dc:creator>
      <guid isPermaLink="false">16466@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody, I’m Sara and I’m pretty new in graphic with Processing.
Recently I’ve been asked to make a sketch for a communication campaign. 
May someone of you gentleman could help me out? I’m almost running out of time, my deadline is approaching and all my drafts still not good enough, so I finally decided to ask some help to the pros.</p>

<p>I’m projecting a sketch in which, the mouse pointer can change the colors of an image by moving over.</p>
]]></description>
   </item>
   <item>
      <title>Get the average RGB from pixels</title>
      <link>https://forum.processing.org/two/discussion/15573/get-the-average-rgb-from-pixels</link>
      <pubDate>Sat, 19 Mar 2016 13:21:08 +0000</pubDate>
      <dc:creator>bourdonprince</dc:creator>
      <guid isPermaLink="false">15573@/two/discussions</guid>
      <description><![CDATA[<p>Hi to all.</p>

<p>I am using the following code to draw one pixel colour for every 10x10 pixel area.</p>

<pre><code>size(700, 450);
PImage img = loadImage("image.jpg");
//noStroke();
int detail = 10;

for (int i=0; i&lt;width; i+=detail) {
  for (int j=0; j&lt;height; j+=detail) {
    color c = img.get(i, j);
    fill(c);
    rect(i, j, detail, detail);
  }
}
</code></pre>

<p>My question is, how can I instead of reading one pixel's value and draw it in the area of 10x10, to get the average of all pixels from the 10x10 area of the original image, and draw the value on the same 10x10 rect?</p>

<p>Thanks - I also attach a sketch, maybe is helps!</p>

<p><img src="" alt="" /><img src="https://forum.processing.org/two/uploads/imageupload/178/ARBI51BNN2Z8.jpg" alt="Untitled-2" title="Untitled-2" /></p>
]]></description>
   </item>
   <item>
      <title>Writing an Algorithm to update values?</title>
      <link>https://forum.processing.org/two/discussion/15536/writing-an-algorithm-to-update-values</link>
      <pubDate>Thu, 17 Mar 2016 12:02:16 +0000</pubDate>
      <dc:creator>mef233</dc:creator>
      <guid isPermaLink="false">15536@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone,
I am writing a code that has turned the pixels of an image into noise.  While I am excited that I managed to get the code to scramble an image, I was wondering if anyone had an idea of how to slow the effect down so that when the code is run, the effect is more apparent; rather than the sketch opening, the picture appearing for a moment, and then is scrambled.  An algorithm that would slowly update the RGB values- because I am really stumped.
Any other suggestions aside from frame rate? Something that could happen in the draw loop?  Code follows! Thanks!</p>

<hr />

<blockquote class="Quote">
  
</blockquote>

<pre><code>PImage img;       // The source image
color c;
int r;
int g;
int b;
int loc;

void setup() {
  size(564, 424);
  img = loadImage("ring.jpg"); // Load the image
image(img,0,0);
  loadPixels();
}

void draw() {

  updatePixels();


  // Begin loop for columns
  for (int i = 0; i &lt; img.width; i++ ) {
    // Begin loop for rows
    for (int j = 0; j &lt; img.height; j++ ) {


    //focus on an algorithm to slowly update the RGB values
    if(r&lt;255){r=r+10;}else {r=0;}
     if(b&lt;255){b=b+10;}else {b=0;}
     if(g&lt;255){g=g+10;}else {g=0;}

    // print("R:");println(r);
     //print("G:");println(r);
     //print("B:");println(r);

      loc = (int)random(236139);     

     //loc=i+j*img.width;      

    /*  if(loc&lt;239135)
      {
      loc++;       }
      else{loc=0;}*/

      c = color(r,g,b);

      pixels[loc]=c;       
      //println(loc);

      }//j
  }//i


}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Errors when cycling through pixels[]</title>
      <link>https://forum.processing.org/two/discussion/15050/errors-when-cycling-through-pixels</link>
      <pubDate>Mon, 22 Feb 2016 04:41:16 +0000</pubDate>
      <dc:creator>tripnikk</dc:creator>
      <guid isPermaLink="false">15050@/two/discussions</guid>
      <description><![CDATA[<p>I've been delving into image processing over the last few days and thought I had an idea of what was going on, but apparently I'm doing something very wrong. Whenever I run my code, Processing locks up and I have to force quit. It's frustrating.</p>

<p>I've stripped down some code I'm working on to figure out what's breaking, but even in this VERY bare bones version, everything breaks. At this point I'm simply trying to cycle through each pixel and report red green and blue values. Any help would be greatly appreciated as I have no idea what I'm doing incorrectly.</p>

<p><strong>code below</strong></p>

<pre><code>PImage source;
int loc;
float r;
float g;
float b;
float lumin;
color c;

void setup(){
 source = loadImage("sheet_face.jpg","jpg");
 size(564,848,P2D); 
 float threshold = .7;

 source.loadPixels();

 image(source,0,0);

 for(int y = 0; y &lt; source.height; y++){
  for(int x = 0; x &lt; source.width; x++){
   loc = y*width+x;
   c = source.pixels[loc];
   r = red(c);
   g = green(c);
   b = blue(c);
   println("red value is "+r);
   println("green value is "+g);
   println("blue value is "+b);
   lumin = (r+g+b)/765;
   println("lumin value is "+lumin);
  }
 }
 source.updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arrays and Rows/Colums</title>
      <link>https://forum.processing.org/two/discussion/14614/arrays-and-rows-colums</link>
      <pubDate>Mon, 25 Jan 2016 17:14:01 +0000</pubDate>
      <dc:creator>Jonasan</dc:creator>
      <guid isPermaLink="false">14614@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>For my project (<a href="https://forum.processing.org/two/discussion/comment/60203" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/comment/60203</a>) I have 4 x 4 objects. I use an array to define the 16 objects, but somehow it seems easier if I could use indexes that refer to the row and colum each object is in.</p>

<p>Someting like this:
object11, object12, object13, object14
object21, object22, object23, ...</p>

<p>Is this easy doable? If yes, how?</p>

<p>Thank you ;-)</p>
]]></description>
   </item>
   <item>
      <title>Trying to split video frames into RGB component images</title>
      <link>https://forum.processing.org/two/discussion/14598/trying-to-split-video-frames-into-rgb-component-images</link>
      <pubDate>Sun, 24 Jan 2016 06:28:29 +0000</pubDate>
      <dc:creator>LDB477</dc:creator>
      <guid isPermaLink="false">14598@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to take a video frame and break out the RGB component information into three separate images.  The problem I seem to be having is that when I load more than one set of pixel information, some strange things start to happen.  You can see in the code below that when I simply reference the information in the original capture it will actually seem to change that information.  I'm not quite getting the loadPixels and updatePixels functions it seems.  Here's a simplified version of my sketch using one of the video examples:</p>

<pre><code>import processing.video.*;

Capture cam;

PImage camR;
PImage camG;
PImage camB;

void setup() {
  size(640, 480);
  colorMode(RGB,255);
  frameRate(1);
  String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 640, 480);
  } if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i &lt; cameras.length; i++) {
      println(cameras[i]);
    }

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam = new Capture(this, cameras[0]);
    // Or, the settings can be defined based on the text in the list
    //cam = new Capture(this, 640, 480, "Built-in iSight", 30);

    // Start capturing the images from the camera
    cam.start();
  }
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  camR = cam;
  camG = cam;
  camB = cam;
  cam.loadPixels();
  camR.loadPixels();
  camG.loadPixels();
  camB.loadPixels();

  for (int i = 0; i &lt; cam.width*cam.height; i++){

    camR.pixels[i] = color(red(cam.pixels[i]));
    camG.pixels[i] = color(green(cam.pixels[i]));
    camB.pixels[i] = color(blue(cam.pixels[i]));
  }
  cam.updatePixels();
  camR.updatePixels();
  camG.updatePixels();
  camB.updatePixels();
  image(cam,0,0,200,150);
  image(camR,200,0,200,150);
  image(camG,200,150,200,150);
  image(camB,200,300,200,150);

}
</code></pre>

<p>I'm expecting to see the full RGB image when I run image(cam...), but I end up just getting the greyscale RED channel.  The "camG" and "camB" are also displaying the red channel.</p>
]]></description>
   </item>
   <item>
      <title>Change one colour from a PNG to another one</title>
      <link>https://forum.processing.org/two/discussion/14352/change-one-colour-from-a-png-to-another-one</link>
      <pubDate>Fri, 08 Jan 2016 23:03:46 +0000</pubDate>
      <dc:creator>maxarch</dc:creator>
      <guid isPermaLink="false">14352@/two/discussions</guid>
      <description><![CDATA[<p>hello!
I have PNG with transparency, green, and white
I will like to be able  to change the green to another colour and the white for another.</p>

<p>I imagine it will go something like this</p>

<pre><code>PImage myImage = loadImage("apples.jpg");
image(myImage, 0, 0);

loadPixels();
get () green pixel
change green pixel to  x pixel
get () white pixel
change white pixel to  y pixel
updatePixels();
</code></pre>

<p>I am a bit confuse on how to proceed between loadPixels(); and updatePixels();  if it the right way,
any help will be appreciated.</p>
]]></description>
   </item>
   <item>
      <title>accessing single value in a color variable</title>
      <link>https://forum.processing.org/two/discussion/14416/accessing-single-value-in-a-color-variable</link>
      <pubDate>Tue, 12 Jan 2016 17:38:22 +0000</pubDate>
      <dc:creator>plux</dc:creator>
      <guid isPermaLink="false">14416@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I would like to know if it's possible to access separately the values r,g and b of a color() variable.
For instance, let's say I have this</p>

<pre><code>    color c1 = color(255,255,0);
</code></pre>

<p>and I want to be able to modify the R value of this variable without having to rewrite it (then NOT something like c1 = color(100,255,0)).</p>

<p>Any idea?</p>

<p>Thank you
p.</p>
]]></description>
   </item>
   <item>
      <title>Accessing the value of color</title>
      <link>https://forum.processing.org/two/discussion/14213/accessing-the-value-of-color</link>
      <pubDate>Fri, 01 Jan 2016 04:34:21 +0000</pubDate>
      <dc:creator>CantSayIHave</dc:creator>
      <guid isPermaLink="false">14213@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>I need to access the individual RGB values of <strong>color</strong>. Anybody know what they're called?</p>

<p>Thanks.</p>
]]></description>
   </item>
   <item>
      <title>RGB Values Not Consistent Before and After Saving Image</title>
      <link>https://forum.processing.org/two/discussion/12118/rgb-values-not-consistent-before-and-after-saving-image</link>
      <pubDate>Mon, 17 Aug 2015 04:00:40 +0000</pubDate>
      <dc:creator>Sono</dc:creator>
      <guid isPermaLink="false">12118@/two/discussions</guid>
      <description><![CDATA[<p>I've been trying to develop a steganography program that can send and receive messages through the least significant bits of an image, however, Processing seems to sometimes change an RGB value by one or two units for absolutely no reason.</p>

<p>I threw together the following program to demonstrate what I mean.</p>

<pre><code>PImage originalImage, newImage;
String oldName = "input.jpeg", newName = "newImage.jpeg";

void setup() {
  originalImage = loadImage(oldName);

  printPixels(originalImage, oldName);
  makeNewImage(newName);
  printPixels(loadImage(newName), newName);
}

private void printPixels(PImage _image, String _name) {
  println(" === Pixels: " + _name + " === ");

  // Print only 15 pixels, just to keep things simple.
  for (int i = 0; i &lt; 15; i++) {
    println(red(_image.pixels[i]) + " : " + green(_image.pixels[i]) + " : " + blue(_image.pixels[i]));
  }
  println();
}

private void makeNewImage(String _name) {
  // Create new image
  newImage = createImage(originalImage.width, originalImage.height, RGB); 
  // Copy the original image over
  newImage = originalImage.get();
  // Save new image
  newImage.save(_name);
}
</code></pre>

<p>All this program does is receive an image "input.jpeg", and save an identical copy of it called "newImage.jpeg". Easy enough, right? 
Well, here is what it outputs when it reads the pixel RGB values:</p>

<pre><code> === Pixels: input.jpeg === 
226.0 : 234.0 : 237.0
226.0 : 234.0 : 237.0
226.0 : 234.0 : 237.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
223.0 : 231.0 : 234.0
222.0 : 230.0 : 233.0
220.0 : 228.0 : 231.0
220.0 : 228.0 : 231.0
221.0 : 229.0 : 232.0
222.0 : 230.0 : 233.0

 === Pixels: newImage.jpeg === 
226.0 : 234.0 : 237.0
226.0 : 234.0 : 237.0
226.0 : 234.0 : 237.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
225.0 : 233.0 : 236.0
224.0 : 232.0 : 235.0
223.0 : 231.0 : 234.0
221.0 : 229.0 : 232.0
220.0 : 228.0 : 231.0
219.0 : 227.0 : 230.0
220.0 : 228.0 : 231.0
222.0 : 230.0 : 233.0
</code></pre>

<p>Look at the second last pixel data. Can anyone explain why the RGB values sometimes differ? Is there a better way to import and save images? Should I use a different picture format?</p>

<p>Thanks in advance,
- Sono</p>
]]></description>
   </item>
   <item>
      <title>Help with a multidimensional array</title>
      <link>https://forum.processing.org/two/discussion/10362/help-with-a-multidimensional-array</link>
      <pubDate>Thu, 16 Apr 2015 21:39:33 +0000</pubDate>
      <dc:creator>lolnyancats</dc:creator>
      <guid isPermaLink="false">10362@/two/discussions</guid>
      <description><![CDATA[<pre><code>int drk;
int lgt;
int normal;
int changer;
int changeg;
int changeb;
float r=random(0,255);
float g=random(0,255);
float b=random(0,255);
float[] [] [] arr = new float[r][g][b];
</code></pre>
]]></description>
   </item>
   <item>
      <title>What is a color in Processing?</title>
      <link>https://forum.processing.org/two/discussion/8086/what-is-a-color-in-processing</link>
      <pubDate>Tue, 11 Nov 2014 11:02:50 +0000</pubDate>
      <dc:creator>PhiLho</dc:creator>
      <guid isPermaLink="false">8086@/two/discussions</guid>
      <description><![CDATA[<h1>What is a color in Processing?</h1>

<h3>Why colors are negatives? What are these strange values?</h3>

<p>These are common questions, often seen in the forum.</p>

<p>Colors, in Processing, are stored actually in simple Java <code>int</code>s, 32-bit values.
The <code>color</code> pseudo-type is actually replaced by Processing with <code>int</code> when generating Java code before compilation.</p>

<p>This type has a width of 32 bits, which is perfect as we can put 4 channels of 8 bits each inside.
8 bits allow a range of of values from 0 to 255 (included). The 4 channels are alpha (opacity), red, green, blue, the whole being often abbreviated as ARGB.</p>

<p>Low value of color channel means "low intensity", darkness. High value means "high intensity", lightness.
So if all channels are 0, we have black; if they are all at 255, we have white.<br />
Alpha channel is different: 0 means low opacity, fully transparent, while 255 means high opacity, normal opaque color.</p>

<p>In Java, numbers are always signed. In computing, negative numbers are marked by setting the highest bit to 1. So, opaque colors, the most common kind, the default if no opacity is given, is 0xFF = 255, the high bit is set to 1, the color value is negative.<br />
Hence the answer to the first question...</p>

<p>The strange values are the result of combining all the values of the channels.<br />
Let's take a simple yellowish color. Alpha is 255 (opaque), red is 250, green is 230 and blue is, say, 20.
These values are <code>0xFF</code>, <code>0xFA</code>, <code>0xE6</code> and <code>0x14</code>.<br />
Combined to make an <code>int</code>, it gives <code>0xFFFAE614</code>, ie. <code>-334316</code>. Hence a strange number, not very easy to decipher.</p>

<p>Note that Processing uses a special notation (not in the Java language) for color literals: the previous color can be written <code>#FAE614</code> (no alpha in this notation).
It is equivalent to <code>0xFFFAE614</code> or to a call to the <code>color()</code> function: <code>color(240, 130, 20);</code></p>

<p>If you want to print out color values, eg. for debugging, you have to use the <code>hex()</code> function:</p>

<pre lang="processing">
color c = color(240, 130, 20);
background(c);
println(c);
println(hex(c));
</pre>

<h3>How do I get the color components?</h3>

<p>The easiest way is to use <a rel="nofollow" href="http://processing.org/reference/red_.html">red()</a>, <a rel="nofollow" href="http://processing.org/reference/green_.html">green()</a>, <a rel="nofollow" href="http://processing.org/reference/blue_.html">blue()</a> and <a rel="nofollow" href="http://processing.org/reference/alpha_.html">alpha()</a> functions. They return a floating point number. Also of interest are <a rel="nofollow" href="http://processing.org/reference/hue_.html">hue()</a>, <a rel="nofollow" href="http://processing.org/reference/saturation_.html">saturation()</a> and <a rel="nofollow" href="http://processing.org/reference/brightness_.html">brightness()</a> for HSB mode.<br />
But these functions are rather slow, because Processing takes the current <a rel="nofollow" href="http://processing.org/reference/colorMode_.html">colorMode()</a> into account.</p>

<p>It is faster to use <a rel="nofollow" href="http://en.wikipedia.org/wiki/Bitwise_operation">bitwise operations</a> to get the components as integers between 0 and 255 (inclusive):</p>

<pre lang="processing">
color c = color(240, 130, 20);
int alpha = (c &gt;&gt; 24) &amp; 0xFF;
int red   = (c &gt;&gt; 16) &amp; 0xFF;
int green = (c &gt;&gt; 8)  &amp; 0xFF;
int blue  =  c        &amp; 0xFF;
println(alpha + " " + red + " " + green + " " + blue);
</pre>

<p>The idea is to shift the relevant bits to the right until they are at the lower position, then to mask them with 'and' to isolate them.</p>

<p>Likewise, you can build a color this way, although it is easier to use <a rel="nofollow" href="http://processing.org/reference/color_.html">color()</a> for that (which is, again, slower because of colorMode).</p>

<pre><code>color c2 = (alpha &lt;&lt; 24) | (red &lt;&lt; 16) | (green &lt;&lt; 8) | blue;
println(hex(c2));
</code></pre>
]]></description>
   </item>
   <item>
      <title>Amount of color in picture depending on mouse location?</title>
      <link>https://forum.processing.org/two/discussion/5933/amount-of-color-in-picture-depending-on-mouse-location</link>
      <pubDate>Sat, 21 Jun 2014 10:01:38 +0000</pubDate>
      <dc:creator>iaften</dc:creator>
      <guid isPermaLink="false">5933@/two/discussions</guid>
      <description><![CDATA[<p>Hello. I've been working on a code that makes a picture blue.
And it works perfectly. The problem is that i know need to have the level of blue depending on the location of the mouse. Meaning if the mouse is on the bottom of the picture, it should be almost none blue. And if its on the top, it should be almost completely blue, but the picture still needs to be visible.</p>

<p>My code looks like this so far:</p>

<pre><code>  float light = 1;

  for(int y = 0;y &lt; img.height; y = y + 1){
    for(int x = 0;x &lt; img.width; x = x + 1){
      color getColor = img.get(x, y);{

      float newRed = red(getColor)*light*0;
      float newGreen = green(getColor)*light*0;
      float newBlue = blue(getColor)*light*2;

      color newColor = color(newRed, newGreen, newBlue);


      set(x, y, newColor);
    }
  }
  }
}
</code></pre>

<p>Thanks.</p>
]]></description>
   </item>
   <item>
      <title>hello, this code is for the passage of a blur image, need help for understand this code</title>
      <link>https://forum.processing.org/two/discussion/5318/hello-this-code-is-for-the-passage-of-a-blur-image-need-help-for-understand-this-code</link>
      <pubDate>Thu, 22 May 2014 03:41:45 +0000</pubDate>
      <dc:creator>niita</dc:creator>
      <guid isPermaLink="false">5318@/two/discussions</guid>
      <description><![CDATA[<pre><code>PImage imgmdr = createImage(img.width, img.height, RGB);
  float v = 1.0 / 9.0;//definit une matrice de 3*3qui est notre kernel v= comme suite (1+2+..+n)n fois/9
  float[][] kernel = {
    { 
      v, v, v 
    }
    , 
    { 
      v, v, v
    }
    , 
    { 
      v, v, v
    }
  };

  // Loop through every pixel in the image
  for (int y = 1; y &lt; img.height-1; y++) {   // BORDS SUPERIEUR ET INF
    for (int x = 1; x &lt; img.width-1; x++) {  // BORDS GAUCHE ET DROITE
      float sumr = 15; // Kernel SOMME de ces pixels
      float sumg = 8;
      float sumb = 2;
      for (int ky = -1; ky &lt;= 1; ky++) {
        for (int kx = -1; kx &lt;= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // l'image est en niveaux de gris, rouge/vert/bleu identiques
          float valr = red(img.pixels[pos]);
          float valg = green(img.pixels[pos]);
          float valb = blue(img.pixels[pos]);

          // Multiplier pixels adjacents sur la base des valeurs de noyau
          sumr += kernel[ky+1][kx+1] * valr;
          sumg += kernel[ky+1][kx+1] * valg;
          sumb += kernel[ky+1][kx+1] * valb;
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      imgmdr.pixels[y*img.width + x] = color(sumr, sumg, sumb);
    }
  }
  // Image changée face à edgeImg.pixels[]
  imgmdr.updatePixels();

  //image(imgmdr, 0, 0); // Draw the new image

  return imgmdr;
}
</code></pre>

<p>I would like that someone explain me this code cuz i don't understand what's correspond of sumr, why a ' k ' .... Thx to reply me</p>
]]></description>
   </item>
   <item>
      <title>Pixels array, HSB,  PImage.save(), and Unexpected Behavior</title>
      <link>https://forum.processing.org/two/discussion/5118/pixels-array-hsb-pimage-save-and-unexpected-behavior</link>
      <pubDate>Tue, 13 May 2014 14:17:41 +0000</pubDate>
      <dc:creator>Jim_Plaxco</dc:creator>
      <guid isPermaLink="false">5118@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, 
I'm working on a generative art project. For this project it is in the best interests of flexibility to work in HSB mode. Given that this involves working with large image files, I hit upon the idea of stuffing HSB info into the RGB field, saving it, and then processing that altered version. Here is my process.</p>

<p>1) Read image, loadpixels.
2) convert rgb data to hsv data in pixels array
3) update pixels
4) validate hsv data ranges in pixels array
5) save file</p>

<p>Once I've started my program I read the file, convert to HSV/HSB, and show the resulting bizarre image on screen via image(). Just to be sure I was doing it right, I wrote a routine to convert the HSV/HSB data in the pixels array back to RGB. I can go back and forth flawlessly.</p>

<p>Before saving the image to disk using the PImage.save(), I run a validate routine to check on the ranges of all the HSV values in the pixels array. The output from that is as follows:</p>

<pre><code>HSV validation: hue range=** 0 to 359** Saturation range= **0 to 94**  Brightness range= **7 to 100**
</code></pre>

<p>This is what I expect to see so I save the file and end the session.</p>

<p>I restart the program and load that newly saved image. Displaying the image it does display correctly, that is as a weird image - which is no surprise as the image data is being interpreted as 0-255 RGB values.</p>

<p>However, when I run my validate routine against the values in the pixels array, it returns the following.</p>

<pre><code>   HSV validation: hue range= **0 to 746** Saturation range= **0 to 127**  Brightness range= **0 to 127**
</code></pre>

<p>The values in this new pixels array have changed substantially yet I have done nothing to the data between the time I saved it and opened it. Further when I attempt to convert the HSB values back to RGB the result is garbage and all kinds of "range out of bounds" error messages that I incorporated into my conversion utilities.</p>

<p>I am guessing that there is some sort of behind the scenes processing that is going on with respect to what Processing is doing when it is reading and writing the pixels array.  OR... a thought that has crossed my mind is that the PImage.save does not save the contents of the pixels array but instead relies on saving an RGB version of what appears on screen.</p>

<p>So, perhaps my question should be this: how can I insure that the contents of the pixels array is what is being saved?</p>

<p>PS - the reason I suspect that Processing is at fault is because I have to lie in order to do HSB. RGB values are all in the 0-255 range associated with 8 bits per channel of storage. In order to save the HSB data, whose range is 360,100,100, I use only 7 bits for S and B, and 10 bits for H.</p>

<p>Any light that anyone can shed on this would be immensely appreciated. Thanks.</p>
]]></description>
   </item>
   </channel>
</rss>