Size problem

Home Forums Processing Size problem

This topic contains 15 replies, has 2 voices, and was last updated by  Phil 11 months, 1 week ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #443

    Stradis
    Participant

    Hi

    I explained my problem here : http://datamoshing.com/2016/06/16/how-to-glitch-images-using-pixel-sorting/#comment-16

    I copy/paste it here :

    “I struggled during all my afternoon to find some good pixel processing software. I found your tutorial an hour ago and it seems great. I have just one problem. I do all the necessary, and when i process my images, it gets awfully cropped.

    I put a jpg image, about 900 ko, 2000p of width and 1541 of height, and i get a 2,5 Mo png file 1916-1053

    I don’t understand at all. I just change the filename and the file type in the script, nothing else.”

    Phil then responded : “These scripts set the Processing window to the size of the image. It could be that your operating system, or version of Java is affecting this somehow. You can try changing the lines,

    size(1, 1);

    […]

    surface.setSize(img.width, img.height);

    To the actual size of the image,

    size(2000, 1541);

    surface.setSize(2000, 1541);”

    But sadly it didn’t work, so here I am for further discussions !

    (btw, i have absolutely no knowledge on programing. I hope it won’t be too much of a problem)
    (btw², I’m not a native english speaker, so excuse me about eventuals grammar/orthographic/etc mistakes)

    #444

    Phil
    Keymaster

    Could you post the image you’re using? Or try with a different image and let me know the results? Also, your operating system and the version of Processing you are using.

    #445

    Stradis
    Participant

    The image I use to test Processing

    I tested it with another image, same result. Cropping (1916×1053 instead of 2000×1335. It’s the same cropped result than the first image : exactly the same amount of pixel) + a .png conversion.

    I’m using Windows 10 and Processing 3.2.1.
    Here is my script (in case there’s a problem in it) :

    
    /*
    
     ASDF Pixel Sort
     Kim Asendorf | 2010 | kimasendorf.com
     
     sorting modes
     
     0 = black
     1 = brightness
     2 = white
     
     */
    
    int mode = 1;
    
    // image path is relative to sketch directory
    PImage img;
    String imgFileName = "glitchtest";
    String fileType = "jpg";
    
    int loops = 1;
    
    // threshold values to determine sorting start and end pixels
    int blackValue = -16000000;
    int brightnessValue = 60;
    int whiteValue = -13000000;
    
    int row = 0;
    int column = 0;
    
    boolean saved = false;
    
    void setup() {
      img = loadImage(imgFileName+"."+fileType);
      
      // use only numbers (not variables) for the size() command, Processing 3
      size(1, 1);
      
      // allow resize and update surface to image dimensions
      surface.setResizable(true);
      surface.setSize(img.width, img.height);
      
      // load image onto surface
      image(img, 0, 0);
    }
    
    void draw() {
      
      // loop through columns
      while(column < width-1) {
        println("Sorting Column " + column);
        img.loadPixels(); 
        sortColumn();
        column++;
        img.updatePixels();
      }
      
      // loop through rows
      while(row < height-1) {
        println("Sorting Row " + column);
        img.loadPixels(); 
        sortRow();
        row++;
        img.updatePixels();
      }
      
      // load updated image onto surface
      image(img, 0, 0);
      
      if(!saved && frameCount >= loops) {
        
        // save surface
        saveFrame(imgFileName+"_"+mode+".png");
        saved = true;
        println("Saved "+frameCount+" Frame(s)");
        
        // exiting here can interrupt file save, wait for user to trigger exit
        println("Click or press any key to exit...");
      }
    }
    
    void keyPressed() {
      if(saved)
      {
        System.exit(0);
      }
    }
    
    void mouseClicked() {
      if(saved)
      {
        System.exit(0);
      }
    }
    
    void sortRow() {
      // current row
      int y = row;
      
      // where to start sorting
      int x = 0;
      
      // where to stop sorting
      int xend = 0;
      
      while(xend < width-1) {
        switch(mode) {
          case 0:
            x = getFirstNotBlackX(x, y);
            xend = getNextBlackX(x, y);
            break;
          case 1:
            x = getFirstBrightX(x, y);
            xend = getNextDarkX(x, y);
            break;
          case 2:
            x = getFirstNotWhiteX(x, y);
            xend = getNextWhiteX(x, y);
            break;
          default:
            break;
        }
        
        if(x < 0) break;
        
        int sortLength = xend-x;
        
        color[] unsorted = new color[sortLength];
        color[] sorted = new color[sortLength];
        
        for(int i=0; i<sortLength; i++) {
          unsorted[i] = img.pixels[x + i + y * img.width];
        }
        
        sorted = sort(unsorted);
        
        for(int i=0; i<sortLength; i++) {
          img.pixels[x + i + y * img.width] = sorted[i];      
        }
        
        x = xend+1;
      }
    }
    
    void sortColumn() {
      // current column
      int x = column;
      
      // where to start sorting
      int y = 0;
      
      // where to stop sorting
      int yend = 0;
      
      while(yend < height-1) {
        switch(mode) {
          case 0:
            y = getFirstNotBlackY(x, y);
            yend = getNextBlackY(x, y);
            break;
          case 1:
            y = getFirstBrightY(x, y);
            yend = getNextDarkY(x, y);
            break;
          case 2:
            y = getFirstNotWhiteY(x, y);
            yend = getNextWhiteY(x, y);
            break;
          default:
            break;
        }
        
        if(y < 0) break;
        
        int sortLength = yend-y;
        
        color[] unsorted = new color[sortLength];
        color[] sorted = new color[sortLength];
        
        for(int i=0; i<sortLength; i++) {
          unsorted[i] = img.pixels[x + (y+i) * img.width];
        }
        
        sorted = sort(unsorted);
        
        for(int i=0; i<sortLength; i++) {
          img.pixels[x + (y+i) * img.width] = sorted[i];
        }
        
        y = yend+1;
      }
    }
    
    // black x
    int getFirstNotBlackX(int x, int y) {
      
      while(img.pixels[x + y * img.width] < blackValue) {
        x++;
        if(x >= width) 
          return -1;
      }
      
      return x;
    }
    
    int getNextBlackX(int x, int y) {
      x++;
      
      while(img.pixels[x + y * img.width] > blackValue) {
        x++;
        if(x >= width) 
          return width-1;
      }
      
      return x-1;
    }
    
    // brightness x
    int getFirstBrightX(int x, int y) {
      
      while(brightness(img.pixels[x + y * img.width]) < brightnessValue) {
        x++;
        if(x >= width)
          return -1;
      }
      
      return x;
    }
    
    int getNextDarkX(int _x, int _y) {
      int x = _x+1;
      int y = _y;
      
      while(brightness(img.pixels[x + y * img.width]) > brightnessValue) {
        x++;
        if(x >= width) return width-1;
      }
      return x-1;
    }
    
    // white x
    int getFirstNotWhiteX(int x, int y) {
    
      while(img.pixels[x + y * img.width] > whiteValue) {
        x++;
        if(x >= width) 
          return -1;
      }
      return x;
    }
    
    int getNextWhiteX(int x, int y) {
      x++;
    
      while(img.pixels[x + y * img.width] < whiteValue) {
        x++;
        if(x >= width) 
          return width-1;
      }
      return x-1;
    }
    
    // black y
    int getFirstNotBlackY(int x, int y) {
    
      if(y < height) {
        while(img.pixels[x + y * img.width] < blackValue) {
          y++;
          if(y >= height)
            return -1;
        }
      }
      
      return y;
    }
    
    int getNextBlackY(int x, int y) {
      y++;
    
      if(y < height) {
        while(img.pixels[x + y * img.width] > blackValue) {
          y++;
          if(y >= height)
            return height-1;
        }
      }
      
      return y-1;
    }
    
    // brightness y
    int getFirstBrightY(int x, int y) {
    
      if(y < height) {
        while(brightness(img.pixels[x + y * img.width]) < brightnessValue) {
          y++;
          if(y >= height)
            return -1;
        }
      }
      
      return y;
    }
    
    int getNextDarkY(int x, int y) {
      y++;
    
      if(y < height) {
        while(brightness(img.pixels[x + y * img.width]) > brightnessValue) {
          y++;
          if(y >= height)
            return height-1;
        }
      }
      return y-1;
    }
    
    // white y
    int getFirstNotWhiteY(int x, int y) {
    
      if(y < height) {
        while(img.pixels[x + y * img.width] > whiteValue) {
          y++;
          if(y >= height)
            return -1;
        }
      }
      
      return y;
    }
    
    int getNextWhiteY(int x, int y) {
      y++;
      
      if(y < height) {
        while(img.pixels[x + y * img.width] < whiteValue) {
          y++;
          if(y >= height) 
            return height-1;
        }
      }
      
      return y-1;
    }
    

    I hope it will help !

    #446

    Phil
    Keymaster

    I have a feeling that this is a Windows 10 issue. The script uses the Processing window to render the image, if that window’s size is being restricted by the operating system that would account for the cropping. I’ll do some testing. If you can, try increasing the resolution on your desktop to larger than the dimension of the image.

    #447

    Stradis
    Participant

    Damn … I don’t have any other computer not using windows 10.

    Increasing the resolution of my desktop ? How do I do that ? Are you talking about this ? :

    I can’t go higher than 1920×1080 …

    #448

    Stradis
    Participant

    Quick update.

    As i could’nt try with a higher screen resolution, I tried with a smaller image (still the same photo) of 1500×1155, and it gives a photo (still png) of : 1500×1053. It’s better, but there’s still a little cropping. Don’t know if it can help you …

    EDIT : tried with an even smaller one : 1000×700, and it gives me a uncropped one. Seems you’re right, when it falls under 1920×1080 it works. But i can’t work with poor resolution with photos ..

    • This reply was modified 1 year, 3 months ago by  Stradis.
    #450

    Stradis
    Participant

    sorry for the spam. It’s 1000×770, not 700

    #451

    Stradis
    Participant

    Do you think you will be able to solve the problem (is it possible I mean to make it work on windows 10 ?) ? Or should I give up ?

    #452

    Phil
    Keymaster

    The script would have to be adjusted to not rely on the Processing window, I’m not sure that there’s another way. I’ll look into it, but I may not have the time to update the script for a while.

    If you have an iOS device you can use Glitch, which has similar pixel sorting effects, using full resolution images can be turned on in the settings,

    https://itunes.apple.com/us/app/glitch/id968430091

    #453

    Stradis
    Participant

    Well I’m not really interested with this app, it cannot do what I would like to.

    Do you know another method to do some pixel sort ? Like on this image for example :

    #458

    Phil
    Keymaster

    That app does indeed do pixel sorting. Here are a couple of examples with a similar image.

    Original
    Original

    Pixel Sort, Mode 1
    Pixel Sort, Mode 1

    Pixel Sort, Mode 1
    Pixel Sort, Mode 1

    #459

    Stradis
    Participant

    And is it totally controlable ?

    #460

    Phil
    Keymaster

    To answer your question, I’m not aware of any other software that does automatic pixel sorting.

    #461

    Stradis
    Participant

    I’m sorry but i didn’t understant this answer (i’m not native, i think it’s how the sentence is turned, sorry). It does automatic or controllable pixel sorting ?

    #462

    Phil
    Keymaster

    Glitch does both. Selecting either Sort or Hue Sort will apply random pixel sort algorithms, while expanding the effect controls allow the user to manipulate a number of parameters of the pixel sort. Also, rotating the image before applying an effect and the back after will achieve different results as well.

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.