We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
mirroring bug (Read 642 times)
mirroring bug
Aug 30th, 2008, 11:18pm
 
i'm trying to flip a PIMage into a mirror of itself with this function. i think i've been looking at it too long. it keeps returning the same image i send it.... can't work out why. any fresh eyed ideas?

thanks henry

public class Flipper
{
 int cols, rows, x, y, location, pixelColour;
 public Flipper()

 {
   cols = width;
   rows = height;
 }

 PImage rotateImage(PImage img)
 {
   img.loadPixels();
   int numPixels = img.height*img.width;

   // Begin loop for columns
   for (int i = 1; i < cols; i++)
   {
     // Begin loop for rows
     for (int j = 1; j < rows; j++)
     {
       x = i;
       y = j;

       location = (img.width - x - 1) + y*img.width;// i got this algorithm from a source i know works in the examples folder.

       color pixelColour = img.pixels[i];

     }
     img.set(location, y, pixelColour);
   }

   img.updatePixels();
   return img;

 }
}


Re: mirroring bug
Reply #1 - Sep 2nd, 2008, 6:27am
 
Hi!

I think you just put the location in the wrong place! Your variable location is the point in the pixels array. It's not an x-Position! Also I think you need a copy of the image you want to copy. Otherwise there will be a mirrow effect in the middle. I just wrote a really small function based on your class. It works. Might it helps you! Might you can say me to do somethink better-)

void flipImage(){
 int cols, rows, location;
 PImage videoTemp;
 cols = video.width;
 rows = video.height;
 
 videoTemp = createImage(video.width, video.height, RGB);
// gets a copy of the video Image
 videoTemp.copy(video, 0, 0, cols, rows, 0, 0, cols, rows);
 videoTemp.loadPixels();

 for (int x = 1; x < cols; x++) {
   for (int y = 1; y < rows; y++) {
     // location of your pixel in the pixel array
     location = (video.width - x - 1) + y*video.width;
     color pixelColour = videoTemp.pixels[location];
    //change the pixel
     video.set(x, y, pixelColour);
   }
 }

 video.updatePixels();
}
Re: mirroring bug THANKS!
Reply #2 - Sep 3rd, 2008, 8:40pm
 
thankyou! i sorted it out having seen your example thusly:

public class Flipper
{
 int cols, rows, x, y, location, pixelColour;
 PImage mirror;
 public Flipper()

 {

 }

 PImage rotateImage(PImage img)
 {

   img.loadPixels();
   cols = img.width;
   rows = img.height;
   
   println(cols + " " + rows);
   mirror = new PImage(cols, rows);
   // Begin loop for columns
   for(int i = 0; i < rows; i++)
   {
     // Begin loop for rows
     for(int j = 0; j < cols; j++)
     {

       // makes a new index for the pixels
       location = (cols - j - 1) + i*cols;

       // retrives the original colour value from the array
       color pixelColour = img.pixels[location];

       //set the pixels in the image to their new values
       mirror.set(j, i, pixelColour);
     }

   }
   mirror.updatePixels();
   return mirror;
 }
}

Page Index Toggle Pages: 1